-
Notifications
You must be signed in to change notification settings - Fork 1
/
commit-and-tag-version.mjs
127 lines (115 loc) · 2.44 KB
/
commit-and-tag-version.mjs
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import pkg from "ansi-colors";
import { Command, Option } from "commander";
import commitAndTagVersion from "commit-and-tag-version";
import dedent from "dedent";
const { red, dim, gray, italic, bold, cyan, blue, green, underline, yellow } = pkg;
const program = new Command();
pkg.theme({
danger: red,
dark: dim.gray,
disabled: gray,
em: italic,
heading: bold.underline,
info: cyan,
muted: dim,
primary: blue,
strong: bold,
success: green.bold,
underline,
warning: yellow.underline,
});
const info = (msg) => pkg.info(msg);
const heading = (msg) => pkg.heading(msg);
const em = (msg) => pkg.em(msg);
program
.description("Bump version and create a new tag")
.option("-b, --beta", "Pre-release version")
.option("--dry-run", "Dry run")
.addOption(
new Option("-r, --release-as <size>", "release type version").choices([
"major",
"minor",
"patch",
])
);
program.parse();
const opt = program.opts();
const betaMsg = opt.beta ? em("- Pre-release\n\t") : "";
const dryRunMsg = opt.dryRun ? em("- Dry run\n\t") : "";
const releaseAsMsg = opt.releaseAs
? em(`- Release as ${underline(opt.releaseAs)}`)
: "";
const msg = dedent(`
${heading("Options :")}
${betaMsg}${dryRunMsg}${releaseAsMsg}
`);
console.log(msg);
console.log();
if (opt.beta) {
console.log(`${bold.green(">")} ${info(pkg.underline("Bumping beta version..."))}`);
console.log();
const bumpFiles = [
{
filename: "manifest-beta.json",
type: "json",
},
{
filename: "package.json",
type: "json",
},
{
filename: "package-lock.json",
type: "json",
},
];
commitAndTagVersion({
infile: "CHANGELOG-beta.md",
bumpFiles,
prerelease: "",
dryRun: opt.dryRun,
tagPrefix: "",
})
.then(() => {
console.log("Done");
})
.catch((err) => {
console.error(err);
});
} else {
const versionBumped = opt.releaseAs
? info(`Release as ${underline(opt.releaseAs)}`)
: info("Release");
console.log(`${bold.green(">")} ${underline(versionBumped)}`);
console.log();
const bumpFiles = [
{
filename: "manifest-beta.json",
type: "json",
},
{
filename: "package.json",
type: "json",
},
{
filename: "package-lock.json",
type: "json",
},
{
filename: "manifest.json",
type: "json",
}
];
commitAndTagVersion({
infile: "CHANGELOG.md",
bumpFiles: bumpFiles,
dryRun: opt.dryRun,
tagPrefix: "",
releaseAs: opt.releaseAs,
})
.then(() => {
console.log("Done");
})
.catch((err) => {
console.error(err);
});
}