-
Notifications
You must be signed in to change notification settings - Fork 26
/
release.mjs
71 lines (61 loc) · 1.7 KB
/
release.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
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { readFileSync } from 'node:fs';
import shell from 'shelljs';
import release from 'release-it';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const exec = (...commands) => {
const res = shell.exec(commands.join(' && '), {
silent: false,
fatal: true,
});
if (res.code !== 0) shell.exit(1);
return res;
};
(async () => {
if (process.argv.slice(2).includes('push')) {
const { version } = JSON.parse(readFileSync('./package.json'));
// 打包代码
exec('pnpm build');
// 将打包出来的脚本文件复制到根目录上
shell.cp(
'-f',
path.join(__dirname, './dist/index.js'),
path.join(__dirname, './ComicRead.user.js'),
);
shell.cp(
'-f',
path.join(__dirname, './dist/adguard.js'),
path.join(__dirname, './ComicRead-AdGuard.user.js'),
);
// 提交上传更改
exec(
'git add .',
`git commit -m "chore: :bookmark: Release ${version}"`,
`git tag --annotate v${version} --message="Release ${version}"`,
'git push --follow-tags',
);
return;
}
// 测试
exec('pnpm test run');
exec('pnpm check');
// 使用 release-it 更新版本,并获得更新日志
const { changelog } = await release({
ci: true,
git: {
requireCommits: true,
commit: false,
tag: false,
push: false,
},
plugins: {
'@release-it/conventional-changelog': {
preset: 'conventionalcommits',
infile: 'docs/.other/CHANGELOG.md',
},
},
});
// 将最新的更改日志写入 LatestChange.md
shell.echo(changelog).to('docs/.other/LatestChange.md');
})();