-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
release.js
91 lines (82 loc) · 2.6 KB
/
release.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
import { exec } from "node:child_process";
import { fileURLToPath } from "node:url";
import path from "node:path";
async function run() {
const importDefault = async (module) => (await import(module)).default;
const chalk = await importDefault("chalk");
const minimist = await importDefault("minimist");
const semver = await importDefault("semver");
const { string: outdentString } = await importDefault("outdent");
const { runGit, readJson } = await import("./utils.js");
const params = minimist(process.argv.slice(2), {
string: ["version", "repo"],
boolean: ["dry", "manual", "skip-dependencies-install"],
alias: { v: "version" },
default: {
manual: false,
dry: false,
"skip-dependencies-install": false,
repo: "git@github.com:prettier/prettier.git",
},
});
const { stdout: previousVersion } = await runGit([
"describe",
"--tags",
"--abbrev=0",
]);
if (semver.parse(previousVersion) === null) {
throw new Error(`Unexpected previousVersion: ${previousVersion}`);
} else {
params.previousVersion = previousVersion;
params.previousVersionOnDefaultBranch = (
await readJson("package.json")
).version;
}
const steps = await Promise.all(
[
"./steps/validate-new-version.js",
"./steps/check-git-status.js",
!params["skip-dependencies-install"] && "./steps/install-dependencies.js",
params.manual && "./steps/run-tests.js",
"./steps/update-version.js",
params.manual && "./steps/generate-bundles.js",
"./steps/update-changelog.js",
"./steps/push-to-git.js",
params.manual
? "./steps/publish-to-npm.js"
: "./steps/wait-for-bot-release.js",
"./steps/show-instructions-after-npm-publish.js",
"./steps/update-dependents-count.js",
"./steps/bump-prettier.js",
"./steps/post-publish-steps.js",
]
.filter(Boolean)
.map((step) => importDefault(step))
);
try {
for (const step of steps) {
await step(params);
}
} catch (error) {
const message = outdentString(error.message.trim());
const stack = error.stack.replace(message, "");
console.error(`${chalk.red("error")} ${message}\n${stack}`);
process.exit(1);
}
}
exec(
[
"git fetch --tags", // Fetch git tags to get the previous version number (i.e. the latest tag)
"yarn install", // Install script's dependencies before any require
].join(" && "),
{ cwd: path.dirname(fileURLToPath(import.meta.url)) },
(error) => {
if (error) {
console.error(error);
process.exit(1);
} else {
run();
}
}
);