-
Notifications
You must be signed in to change notification settings - Fork 17
/
release.js
41 lines (34 loc) · 1.21 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
import { execSync } from "child_process";
import { fileURLToPath } from "url";
import { dirname, resolve } from "path";
import fs from "fs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const exec = command => execSync(command, { encoding: "utf8" }).trim();
const exitWithError = error => {
process.stderr.write(`\x1b[1;31m${error}\x1b[0m\n\n`);
process.exit(1);
};
const gitBranchName = exec("git rev-parse --abbrev-ref HEAD");
if (gitBranchName !== "master") {
exitWithError("please checkout the master branch to make a release!");
}
const workingCopyChanges = exec("git status --porcelain");
if (workingCopyChanges) {
exitWithError("please commit your changes before making a release!");
}
const packagePath = resolve(__dirname, "package.json");
const packageText = fs.readFileSync(packagePath);
const packageJson = JSON.parse(packageText);
const tagExists = exec(`git tag -l "${packageJson.version}"`);
if (tagExists) {
exitWithError(`${packageJson.version} has already been released!`);
}
execSync(
`npm run release:dry && git tag ${packageJson.version} && git push && git push --tags && npm publish`,
{
shell: true,
stdio: "inherit",
cwd: __dirname
}
);