generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
commit-and-tag-version.mjs
129 lines (118 loc) · 2.55 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
128
129
import { Command, Option } from "commander";
import commitAndTagVersion from "commit-and-tag-version";
import dedent from "dedent";
import pkg from "ansi-colors";
const { red, dim, gray, italic, bold, cyan, blue, green, underline, yellow, theme } = pkg;
const program = new Command();
theme({
danger: red,
dark: dim.gray,
disabled: gray,
em: italic,
heading: bold.underline,
info: cyan,
muted: dim,
primary: blue,
strong: bold,
success: green.bold,
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(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: "",
scripts: {
postchangelog: "node hooks/_changelog.mjs -b",
},
})
.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,
dryRun: opt.dryRun,
tagPrefix: "",
releaseAs: opt.releaseAs,
scripts: {
postchangelog: "node hooks/_changelog.mjs",
},
})
.then(() => {
console.log("Done");
})
.catch((err) => {
console.error(err);
});
}