-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
publish.js
72 lines (54 loc) · 1.83 KB
/
publish.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
const fs = require("fs-extra");
const path = require("path");
const args = require("minimist")(process.argv.slice(2));
const assert = require("assert");
const execa = require("execa");
const { prompt } = require("enquirer");
const { targets: allTargets } = require("./utils");
const { build, resolvePkgDir } = require("./build");
const targets = args._;
const buildTargets = targets.length > 0 ? targets : allTargets;
async function publish(package, targetVersion) {
assert([2, 3].includes(targetVersion));
const mainPkg = require(path.resolve("package.json"));
const pkgDir = resolvePkgDir(package);
await build(package, targetVersion);
const pkg = JSON.parse(fs.readFileSync(`${pkgDir}/package.json`)); // require(`${pkgDir}/package.json`);
const currentMinor = +mainPkg.version.split(".").slice(-1);
const majorVersion = mainPkg.version.split("-")[0];
const tag = targetVersion === 3 ? "next" : false;
const tempVersion = targetVersion === 3 ? "alpha" : "dev";
const version = `${majorVersion}-${tempVersion}.${currentMinor}`;
pkg.version = version;
await fs.writeFile(`${pkgDir}/package.json`, JSON.stringify(pkg, null, 2));
try {
const args = ["publish", "--access public"];
args.push(`--new-version`, version);
if (tag) {
args.push("--tag", tag);
}
console.log("publishing for ", package, version, tag || "", args);
const otp = await prompt({
type: "input",
name: "otp",
message: "Enter OTP"
});
args.push(`--otp`, otp.otp);
await execa("yarn", args, {
stdio: "inherit",
cwd: pkgDir
});
} catch (e) {
console.error(e);
return process.exit(1);
}
}
async function run() {
const versions = [2, 3];
for (const version of versions) {
for (const target of buildTargets) {
await publish(target, version);
}
}
}
run();