-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathadd-publishConfig.js
34 lines (29 loc) · 959 Bytes
/
add-publishConfig.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
#!/usr/bin/env node
const fsModule = require("fs");
const path = "./package.json";
const fileOptions = { encoding: "utf-8" };
const content = fsModule.readFileSync(path, fileOptions);
const packageDef = JSON.parse(content);
if (!packageDef.publishConfig) {
packageDef.publishConfig = {};
}
const branch = process.argv[2];
if (!branch) {
console.log("Please pass the branch name as an argument!");
process.exit(1);
}
switch (branch) {
case "release":
packageDef.publishConfig.tag = "rc";
break;
case "release-patch":
packageDef.publishConfig.tag = "patch";
break;
case "master":
packageDef.publishConfig.tag = "next";
break;
default:
throw new Error(`Unable to publish as the branch ${branch} does not have corresponding tag. Supported branches are master (next tag), release (rc tag) and release-patch (patch tag)`);
}
const newContent = JSON.stringify(packageDef, null, " ");
fsModule.writeFileSync(path, newContent, fileOptions);