-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathversion.js
66 lines (56 loc) · 1.69 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
const fs = require("node:fs");
const { execSync } = require("child_process");
const chalk = require("chalk");
const semver = require("semver");
const {
ensureCleanWorkingDirectory,
invariant,
updatePackageConfig,
} = require("./utils");
async function run() {
try {
let args = process.argv.slice(2);
let skipGit = args.includes("--skip-git");
let givenVersion = args[0];
invariant(
givenVersion != null,
`Missing next version. Usage: node version.js [nextVersion]`
);
// 0. Make sure the working directory is clean
if (!skipGit) {
ensureCleanWorkingDirectory();
}
// 1. Get the next version number
let version = semver.valid(givenVersion);
invariant(version != null, `Invalid version specifier: ${givenVersion}`);
// 2. Bump package versions
let packageDirNamesToBump = fs
.readdirSync("packages")
.filter((name) => fs.statSync(`packages/${name}`).isDirectory());
for (let packageDirName of packageDirNamesToBump) {
let packageName;
await updatePackageConfig(packageDirName, (pkg) => {
packageName = pkg.name;
pkg.version = version;
});
console.log(
chalk.green(` Updated ${packageName} to version ${version}`)
);
}
// 3. Commit and tag
if (!skipGit) {
execSync(`git commit --all --message="Version ${version}"`);
execSync(`git tag -a -m "Version ${version}" v${version}`);
console.log(chalk.green(` Committed and tagged version ${version}`));
}
} catch (error) {
console.log();
console.error(chalk.red(` ${error.message}`));
console.log();
return 1;
}
return 0;
}
run().then((code) => {
process.exit(code);
});