-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathpatch-npm-version.ts
executable file
·35 lines (30 loc) · 1.22 KB
/
patch-npm-version.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ts-node
// If the version in package.json is less than or equal to
// the published version on npm, set the version to a patch
// on top of the npm version so we can publish.
import * as shell from "shelljs";
import * as semver from "semver";
function exec(command: string) {
const result = shell.exec(command, { silent: true });
return (result.stdout as string).trim();
}
const PUBLISHED = (() => {
// Get the highest published version of any tag
const all = JSON.parse(exec(`npm show quicktype versions --json`));
return all[all.length - 1];
})();
const CURRENT = exec(`npm version`).match(/quicktype: '(.+)'/)![1];
switch (semver.compare(CURRENT, PUBLISHED)) {
case -1:
console.error(`* package.json version is ${CURRENT} but ${PUBLISHED} is published. Patching...`);
exec(`npm version ${PUBLISHED} --force --no-git-tag-version`);
shell.exec(`npm version patch --no-git-tag-version`);
break;
case 0:
console.error(`* package.json version is ${CURRENT} but ${PUBLISHED} is published. Patching...`);
shell.exec(`npm version patch --no-git-tag-version`);
break;
default:
// Greater than published, nothing to do
break;
}