-
Notifications
You must be signed in to change notification settings - Fork 2
/
check-lerna.mjs
88 lines (78 loc) · 2.56 KB
/
check-lerna.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
/*
package.json 加入
"scripts": {
"prepublish": "node ./check-lerna.mjs --prepublish",
"preversion": "node ./check-lerna.mjs --preversion",
"version": "node ./check-lerna.mjs --version",
"postversion": "node ./check-lerna.mjs --postversion",
}
*/
import parser from 'yargs-parser';
import chalk from 'chalk';
import { join } from 'path';
import { spawn } from 'child_process';
import semver from 'semver';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const lernaCli = require.resolve('lerna/cli');
// console.log('lernaCli: ', lernaCli);
// 发布到 npm
// await execa('npm', ['publish', '--tag', 'beta'], {
// cwd: path.join(packagesPath, pkg.replace(namePrefix, '')),
// });
async function exec(command, args, opts) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
shell: true,
stdio: 'inherit',
env: process.env,
...opts,
});
child.once('error', (err) => {
console.log(err);
reject(err);
});
child.once('close', (code) => {
if (code === 1) {
process.exit(1);
} else {
resolve();
}
});
});
}
// await exec('npm', ['run', 'build']);
test();
async function test() {
console.log('patch: ', semver.inc('1.2.3-beta.1', 'patch'));
console.log('semver.inc', semver.inc('1.2.3', 'prerelease', 'beta'));
console.log('beta: ', semver.inc('1.2.3-beta', 'prerelease', 'beta'));
console.log('beta: ', semver.inc('1.2.3-beta.0', 'prerelease', 'beta'));
console.log('semver.valid', semver.valid('1.2.3-beta.20+aseds'));
console.log('semver.parse: ', semver.parse('1.2.3'));
return;
// https://warmhug.github.io/2024/08/06/lerna-usage.html
// dev: npx lerna version --conventional-commits --conventional-prerelease --preid beta --yes
// prod: npx lerna version --conventional-commits --conventional-graduate --yes
await exec('node', [
[lernaCli],
'version',
'patch',
'--message',
'chore(release): Publish',
'--conventional-commits',
// ], {});
], { shell: false });
const args = parser(process.argv);
const cwd = process.cwd();
// console.log('args: ', args);
console.log('args: ', chalk.red(JSON.stringify(args)));
// __dirname is not defined in ES module scope
// const pkgFile = join(__dirname, './packages');
// console.log('pkgFile: ', pkgFile);
const pkgPath = join(cwd, 'packages', 'pkg'.replace('', ''));
// console.log('pkgPath: ', pkgPath);
// console.error('测试抛错');
// process.exit(1);
// console.log('process.exit(1): 后还会执行吗');
}