-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathrelease.mjs
More file actions
95 lines (84 loc) · 2.34 KB
/
release.mjs
File metadata and controls
95 lines (84 loc) · 2.34 KB
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
import { readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import release from 'release-it';
import shell from 'shelljs';
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'),
);
shell.cp(
'-f',
path.join(__dirname, './dist/umd.js'),
path.join(__dirname, './ComicReader.umd.js'),
);
shell.cp(
'-f',
path.join(__dirname, './dist/umd.d.ts'),
path.join(__dirname, './ComicReader.umd.d.ts'),
);
const code = readFileSync(
path.join(__dirname, './ComicRead.user.js'),
'utf8',
);
writeFileSync(
path.join(__dirname, './ComicRead-jsDelivr.user.js'),
code.replaceAll(
/registry\.npmmirror\.com\/(.+)\/(\d+\.\d+\.\d)\/files\/(.+)/g,
'cdn.jsdelivr.net/npm/$1@$2/$3',
),
);
// 提交上传更改
exec(
'git add .',
`git commit -m "chore: :bookmark: Release ${version}"`,
`git tag --annotate v${version} --message="Release ${version}"`,
'git push --follow-tags',
'npm publish',
);
return;
}
// 测试
exec('pnpm check');
exec('pnpm test run');
// 使用 release-it 更新版本,并获得更新日志
const { changelog } = await release({
ci: true,
npm: { publish: false },
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');
})();