-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.mjs
More file actions
67 lines (55 loc) · 1.41 KB
/
Copy pathrelease.mjs
File metadata and controls
67 lines (55 loc) · 1.41 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
import { execSync, execFileSync } from 'child_process';
const {
npm_package_version: version,
npm_lifecycle_event: script,
npm_config_local_prefix: prefix,
} = process.env;
const cwd = process.cwd();
// console.log(process.env);
if (!version || script !== 'version') {
throw 'this script must run in "version"'; // eslint-disable-line no-throw-literal
}
// console.log(process.env, process.cwd());
if (prefix === cwd) {
execSync('auto-changelog -p');
execSync('git add package.json CHANGELOG.md', { stdio: 'inherit' });
const messageTemplate = execFileSync(
'npm',
[
'--no-workspaces',
'config',
'get',
'message',
],
{ cwd, encoding: 'utf-8' },
).trim().replaceAll('%s', version);
execFileSync('git', [
'commit',
'-m',
messageTemplate,
], { stdio: 'inherit' });
const tagPrefix = JSON.parse(execFileSync(
'npm',
[
'--no-workspaces',
'pkg',
'get',
'auto-changelog.tagPrefix',
],
{ cwd, encoding: 'utf-8' },
).trim() ?? 'v');
if (!(/^[A-Za-z0-9._@/-]*$/).test(tagPrefix)) {
throw new Error(`refusing to release: auto-changelog.tagPrefix contains unsafe characters: ${JSON.stringify(tagPrefix)}`);
}
execFileSync('git', [
'tag',
'-a',
`${tagPrefix}${version}`,
'-m',
messageTemplate,
], { stdio: 'inherit' });
} else {
console.error('rerun with --no-workspaces to avoid workspace side effects');
execSync('git checkout -- package.json');
process.exitCode = 1;
}