-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathversion-script.js
More file actions
35 lines (32 loc) · 966 Bytes
/
version-script.js
File metadata and controls
35 lines (32 loc) · 966 Bytes
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
/**
* Update the package.json version property for the given package
*
* Usage:
*
* ```
* node ./.github/version-script.js <package-name>
* ```
*
* `<package-name>` defaults to `wrangler` if not provided.
*/
const { readFileSync, writeFileSync } = require("fs");
const { execSync } = require("child_process");
try {
const packageName = getArgs()[0] ?? "wrangler";
const packageJsonPath = `./packages/${packageName}/package.json`;
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
const stdout = execSync("git rev-parse --short HEAD", { encoding: "utf8" });
pkg.version = "0.0.0-" + stdout.trim();
writeFileSync(packageJsonPath, JSON.stringify(pkg, null, "\t") + "\n");
} catch (error) {
console.error(error);
process.exit(1);
}
/**
* Get the command line args, stripping `node` and script filename, etc.
*/
function getArgs() {
const args = Array.from(process.argv);
while (args.shift() !== module.filename) {}
return args;
}