forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.js
75 lines (64 loc) · 1.78 KB
/
version.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { execSync } = require("child_process");
const semver = require("semver");
const {
ensureCleanWorkingDirectory,
getPackageVersion,
prompt,
incrementRemixVersion,
} = require("./utils");
run(process.argv.slice(2)).then(
() => {
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
}
);
/**
* @param {string[]} args
*/
async function run(args) {
let givenVersion = args[0];
let prereleaseId = args[1];
ensureCleanWorkingDirectory();
// Get the next version number
let currentVersion = await getPackageVersion("remix");
let nextVersion = semver.valid(givenVersion);
if (nextVersion == null) {
nextVersion = getNextVersion(currentVersion, givenVersion, prereleaseId);
}
// Confirm the next version number
if (prereleaseId !== "--skip-prompt") {
let answer = await prompt(
`Are you sure you want to bump version ${currentVersion} to ${nextVersion}? [Yn] `
);
if (answer === false) return 0;
}
await incrementRemixVersion(nextVersion);
}
/**
* @param {string|undefined} currentVersion
* @param {string} givenVersion
* @param {string} [prereleaseId]
* @returns
*/
function getNextVersion(currentVersion, givenVersion, prereleaseId = "pre") {
if (givenVersion == null) {
console.error("Missing next version. Usage: node version.js [nextVersion]");
process.exit(1);
}
let nextVersion;
if (givenVersion === "experimental") {
let hash = execSync(`git rev-parse --short HEAD`).toString().trim();
nextVersion = `0.0.0-experimental-${hash}`;
} else {
// @ts-ignore
nextVersion = semver.inc(currentVersion, givenVersion, prereleaseId);
}
if (nextVersion == null) {
console.error(`Invalid version specifier: ${givenVersion}`);
process.exit(1);
}
return nextVersion;
}