Files
test-repo/scripts/release/release.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-06-05 16:37:52 -03:00
#!/usr/bin/env node
2021-07-26 09:24:44 +08:00
import { exec } from "node:child_process";
import { fileURLToPath } from "node:url";
import path from "node:path";
2018-08-08 23:49:22 +08:00
2018-06-05 16:37:52 -03:00
async function run() {
2021-07-26 09:24:44 +08:00
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");
2018-06-05 16:37:52 -03:00
const params = minimist(process.argv.slice(2), {
2022-06-16 13:17:54 +08:00
string: ["version", "repo"],
boolean: ["dry", "manual", "skip-dependencies-install"],
2018-06-05 16:37:52 -03:00
alias: { v: "version" },
2022-06-16 13:17:54 +08:00
default: {
manual: false,
dry: false,
"skip-dependencies-install": false,
repo: "git@github.com:prettier/prettier.git",
},
2018-06-05 16:37:52 -03:00
});
2018-08-08 23:49:22 +08:00
2021-04-21 22:15:12 +08:00
const { stdout: previousVersion } = await runGit([
"describe",
"--tags",
"--abbrev=0",
]);
2018-08-08 23:49:22 +08:00
if (semver.parse(previousVersion) === null) {
throw new Error(`Unexpected previousVersion: ${previousVersion}`);
} else {
params.previousVersion = previousVersion;
2021-01-24 01:14:13 +08:00
params.previousVersionOnDefaultBranch = (
await readJson("package.json")
).version;
2018-08-08 23:49:22 +08:00
}
2018-06-05 16:37:52 -03:00
2021-07-26 09:24:44 +08:00
const steps = await Promise.all(
[
2022-06-14 14:40:25 +08:00
"./steps/validate-new-version.js",
"./steps/check-git-status.js",
2022-06-16 13:21:11 +08:00
!params["skip-dependencies-install"] && "./steps/install-dependencies.js",
2022-06-14 14:40:25 +08:00
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",
2022-05-30 13:44:54 +08:00
params.manual
? "./steps/publish-to-npm.js"
: "./steps/wait-for-bot-release.js",
"./steps/show-instructions-after-npm-publish.js",
2021-07-26 09:24:44 +08:00
"./steps/update-dependents-count.js",
2022-03-16 19:38:31 +09:00
"./steps/bump-prettier.js",
2021-07-26 09:24:44 +08:00
"./steps/post-publish-steps.js",
2022-05-30 13:44:54 +08:00
]
.filter(Boolean)
.map((step) => importDefault(step))
2021-07-26 09:24:44 +08:00
);
2018-06-05 16:37:52 -03:00
try {
for (const step of steps) {
await step(params);
}
} catch (error) {
2020-05-11 09:05:06 +08:00
const message = outdentString(error.message.trim());
2018-06-05 16:37:52 -03:00
const stack = error.stack.replace(message, "");
console.error(`${chalk.red("error")} ${message}\n${stack}`);
process.exit(1);
}
}
2018-08-08 23:49:22 +08:00
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(" && "),
2021-07-26 09:24:44 +08:00
{ cwd: path.dirname(fileURLToPath(import.meta.url)) },
2018-08-08 23:49:22 +08:00
(error) => {
if (error) {
console.error(error);
process.exit(1);
} else {
run();
}
2018-06-05 16:37:52 -03:00
}
2018-08-08 23:49:22 +08:00
);