generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pub.mjs
executable file
·55 lines (48 loc) · 1.49 KB
/
pub.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
#!/usr/bin/env zx
const calcVersion = require("semver/functions/inc");
async function pub(version) {
await $`npm run version`;
await $`git add --all`;
await $`git commit -m "chore: ${version}"`;
try {
await $`git tag --delete ${version}`;
} catch (error) {}
// 打标签前先删除
await $`git tag -a ${version} -m "version ${version}"`;
await $`git push --follow-tags`;
}
async function getVersion(type) {
const pkg = JSON.parse(await fs.readFile("./package.json"));
const versionTypeMap = {
x: "major",
y: "minor",
z: "patch",
};
const version = calcVersion(pkg.version, versionTypeMap[type]);
return version;
}
async function updatePkgVersion(version) {
let pkg = JSON.parse(await fs.readFile("./package.json"));
pkg.version = version;
await fs.writeFile("./package.json", JSON.stringify(pkg, null, 2));
let manifest = JSON.parse(await fs.readFile("./manifest.json"));
manifest.version = version;
await fs.writeFile("./manifest.json", JSON.stringify(manifest, null, 2));
}
async function main() {
let type = await question(
"which version do you want to upgrade (`x` or `y` or `z`)?"
);
type = type.toLowerCase();
if (["x", "y", "z"].indexOf(type) > -1) {
const version = await getVersion(type);
await updatePkgVersion(version);
await pub(version);
console.log(chalk.green("[Info]: publish successfully!"));
} else {
console.log(
chalk.red("[Error]: you must enter one of `x` or `y` or `z`.\n")
);
}
}
main();