@soybeanjs/cli 0.5.7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -34
- package/dist/index.cjs +21 -14
- package/dist/index.mjs +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,37 +20,38 @@ pnpm soy -h
|
|
|
20
20
|
|
|
21
21
|
## 命令介绍
|
|
22
22
|
|
|
23
|
-
| 命令
|
|
24
|
-
|
|
|
25
|
-
| help | 查看全部命令用法 |
|
|
26
|
-
| git-commit
|
|
27
|
-
| git-commit-verify
|
|
28
|
-
| cleanup
|
|
29
|
-
| init-git-hooks
|
|
30
|
-
|
|
|
31
|
-
| prettier-
|
|
32
|
-
| lint-staged
|
|
33
|
-
| changelog
|
|
34
|
-
| release
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
23
|
+
| 命令 | 作用 |
|
|
24
|
+
| --------------------- | ------------------------------------------------------------------ |
|
|
25
|
+
| help(-h) | 查看全部命令用法 |
|
|
26
|
+
| git-commit | 生成符合 Angular 规范的 git 提交信息 |
|
|
27
|
+
| git-commit-verify | 校验 git 的提交信息是否符合 Angular 规范 |
|
|
28
|
+
| cleanup | 清空依赖和构建产物 |
|
|
29
|
+
| init-simple-git-hooks | 初始化 simple-git-hooks 钩子 |
|
|
30
|
+
| ncu | 命令 npm-check-updates, 升级依赖 |
|
|
31
|
+
| prettier-write | 执行 prettier --write 格式化 |
|
|
32
|
+
| lint-staged | 执行 lint-staged |
|
|
33
|
+
| changelog | 根据两次 tag 生成 changelog (--total: 根据所有 tag 生成 changelog) |
|
|
34
|
+
| release | 发布:更新版本号、生成 changelog、提交代码 |
|
|
35
|
+
| init-git-hooks | 该命令已废弃,请使用 init-simple-git-hooks |
|
|
36
|
+
| update-pkg | 该命令已废弃,请使用 ncu |
|
|
37
|
+
| prettier-format | 该命令已废弃,请使用 prettier-write |
|
|
38
|
+
| eslint-prettier | 该命令已废弃 |
|
|
39
|
+
|
|
40
|
+
## 更多自定义配置
|
|
41
|
+
|
|
42
|
+
- 在项目根目录新建 soybean-config.ts
|
|
43
|
+
|
|
44
|
+
- 导入 defineConfig 函数
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { defineConfig } from "@soybeanjs/cli";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
//options
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- 配置参考
|
|
55
|
+
```ts
|
|
56
|
+
import type { CliOption } from "@soybeanjs/cli";
|
|
57
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const cac = require('cac');
|
|
5
5
|
const enquirer = require('enquirer');
|
|
6
|
+
const path = require('path');
|
|
6
7
|
const fs = require('fs');
|
|
7
8
|
const kolorist = require('kolorist');
|
|
8
9
|
const rimraf = require('rimraf');
|
|
@@ -14,9 +15,10 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
14
15
|
|
|
15
16
|
const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
|
|
16
17
|
const enquirer__default = /*#__PURE__*/_interopDefaultCompat(enquirer);
|
|
18
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
17
19
|
const versionBump__default = /*#__PURE__*/_interopDefaultCompat(versionBump);
|
|
18
20
|
|
|
19
|
-
const version = "0.
|
|
21
|
+
const version = "0.6.0";
|
|
20
22
|
|
|
21
23
|
async function execCommand(cmd, args, options) {
|
|
22
24
|
const { execa } = await import('execa');
|
|
@@ -60,8 +62,9 @@ async function gitCommit(gitCommitTypes, gitCommitScopes) {
|
|
|
60
62
|
execCommand("git", ["commit", "-m", commitMsg], { stdio: "inherit" });
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
function gitCommitVerify(
|
|
64
|
-
const
|
|
65
|
+
async function gitCommitVerify() {
|
|
66
|
+
const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
|
|
67
|
+
const gitMsgPath = path__default.join(gitPath, ".git/COMMIT_EDITMSG");
|
|
65
68
|
const commitMsg = fs.readFileSync(gitMsgPath, "utf-8").trim();
|
|
66
69
|
const REG_EXP = /(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
|
|
67
70
|
if (!REG_EXP.test(commitMsg)) {
|
|
@@ -74,17 +77,18 @@ function gitCommitVerify(cwd = process.cwd()) {
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
async function cleanup(paths) {
|
|
77
|
-
await rimraf.rimraf(paths);
|
|
80
|
+
await rimraf.rimraf(paths, { glob: true });
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
async function initSimpleGitHooks(cwd = process.cwd()) {
|
|
81
|
-
const huskyDir =
|
|
84
|
+
const huskyDir = path__default.join(cwd, ".husky");
|
|
82
85
|
const existHusky = fs.existsSync(huskyDir);
|
|
86
|
+
const gitHooksDir = path__default.join(cwd, ".git/hooks");
|
|
83
87
|
if (existHusky) {
|
|
84
88
|
await rimraf.rimraf(huskyDir);
|
|
85
|
-
await execCommand("git", ["config", "core.hooksPath",
|
|
89
|
+
await execCommand("git", ["config", "core.hooksPath", gitHooksDir], { stdio: "inherit" });
|
|
86
90
|
}
|
|
87
|
-
await rimraf.rimraf(
|
|
91
|
+
await rimraf.rimraf(gitHooksDir);
|
|
88
92
|
await execCommand("npx", ["simple-git-hooks"], { stdio: "inherit" });
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -193,6 +197,7 @@ const defaultOptions = {
|
|
|
193
197
|
},
|
|
194
198
|
useSoybeanToken: false
|
|
195
199
|
};
|
|
200
|
+
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
196
201
|
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
197
202
|
const { config } = await c12.loadConfig({
|
|
198
203
|
name: "soybean",
|
|
@@ -201,6 +206,9 @@ async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
|
201
206
|
cwd,
|
|
202
207
|
packageJson: true
|
|
203
208
|
});
|
|
209
|
+
if (config?.useSoybeanToken) {
|
|
210
|
+
config.changelogOptions = { ...config.changelogOptions, github: { repo: "", token: SOYBEAN_GITHUB_TOKEN } };
|
|
211
|
+
}
|
|
204
212
|
return config;
|
|
205
213
|
}
|
|
206
214
|
|
|
@@ -218,7 +226,7 @@ async function setupCli() {
|
|
|
218
226
|
"git-commit-verify": {
|
|
219
227
|
desc: "\u6821\u9A8C git \u7684 commit \u662F\u5426\u7B26\u5408 Angular \u89C4\u8303",
|
|
220
228
|
action: () => {
|
|
221
|
-
gitCommitVerify(
|
|
229
|
+
gitCommitVerify();
|
|
222
230
|
}
|
|
223
231
|
},
|
|
224
232
|
cleanup: {
|
|
@@ -247,12 +255,11 @@ async function setupCli() {
|
|
|
247
255
|
},
|
|
248
256
|
"lint-staged": {
|
|
249
257
|
desc: "\u6267\u884Clint-staged",
|
|
250
|
-
action: () => {
|
|
251
|
-
execLintStaged(cliOptions.lintStagedConfig).
|
|
252
|
-
process.exitCode = passed ? 0 : 1;
|
|
253
|
-
}).catch(() => {
|
|
258
|
+
action: async () => {
|
|
259
|
+
const passed = await execLintStaged(cliOptions.lintStagedConfig).catch(() => {
|
|
254
260
|
process.exitCode = 1;
|
|
255
261
|
});
|
|
262
|
+
process.exitCode = passed ? 0 : 1;
|
|
256
263
|
}
|
|
257
264
|
},
|
|
258
265
|
changelog: {
|
|
@@ -300,9 +307,9 @@ async function setupCli() {
|
|
|
300
307
|
action: eslintPretter
|
|
301
308
|
}
|
|
302
309
|
};
|
|
303
|
-
|
|
310
|
+
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
304
311
|
cli.command(command, desc).action(action);
|
|
305
|
-
}
|
|
312
|
+
}
|
|
306
313
|
cli.parse();
|
|
307
314
|
}
|
|
308
315
|
setupCli();
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import enquirer from 'enquirer';
|
|
4
|
+
import path from 'path';
|
|
4
5
|
import { readFileSync, existsSync } from 'fs';
|
|
5
6
|
import { bgRed, red, green } from 'kolorist';
|
|
6
7
|
import { rimraf } from 'rimraf';
|
|
@@ -8,7 +9,7 @@ import { generateTotalChangelog, generateChangelog } from '@soybeanjs/changelog'
|
|
|
8
9
|
import versionBump from 'bumpp';
|
|
9
10
|
import { loadConfig } from 'c12';
|
|
10
11
|
|
|
11
|
-
const version = "0.
|
|
12
|
+
const version = "0.6.0";
|
|
12
13
|
|
|
13
14
|
async function execCommand(cmd, args, options) {
|
|
14
15
|
const { execa } = await import('execa');
|
|
@@ -52,8 +53,9 @@ async function gitCommit(gitCommitTypes, gitCommitScopes) {
|
|
|
52
53
|
execCommand("git", ["commit", "-m", commitMsg], { stdio: "inherit" });
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
function gitCommitVerify(
|
|
56
|
-
const
|
|
56
|
+
async function gitCommitVerify() {
|
|
57
|
+
const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
|
|
58
|
+
const gitMsgPath = path.join(gitPath, ".git/COMMIT_EDITMSG");
|
|
57
59
|
const commitMsg = readFileSync(gitMsgPath, "utf-8").trim();
|
|
58
60
|
const REG_EXP = /(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
|
|
59
61
|
if (!REG_EXP.test(commitMsg)) {
|
|
@@ -66,17 +68,18 @@ function gitCommitVerify(cwd = process.cwd()) {
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
async function cleanup(paths) {
|
|
69
|
-
await rimraf(paths);
|
|
71
|
+
await rimraf(paths, { glob: true });
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
async function initSimpleGitHooks(cwd = process.cwd()) {
|
|
73
|
-
const huskyDir =
|
|
75
|
+
const huskyDir = path.join(cwd, ".husky");
|
|
74
76
|
const existHusky = existsSync(huskyDir);
|
|
77
|
+
const gitHooksDir = path.join(cwd, ".git/hooks");
|
|
75
78
|
if (existHusky) {
|
|
76
79
|
await rimraf(huskyDir);
|
|
77
|
-
await execCommand("git", ["config", "core.hooksPath",
|
|
80
|
+
await execCommand("git", ["config", "core.hooksPath", gitHooksDir], { stdio: "inherit" });
|
|
78
81
|
}
|
|
79
|
-
await rimraf(
|
|
82
|
+
await rimraf(gitHooksDir);
|
|
80
83
|
await execCommand("npx", ["simple-git-hooks"], { stdio: "inherit" });
|
|
81
84
|
}
|
|
82
85
|
|
|
@@ -185,6 +188,7 @@ const defaultOptions = {
|
|
|
185
188
|
},
|
|
186
189
|
useSoybeanToken: false
|
|
187
190
|
};
|
|
191
|
+
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
188
192
|
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
189
193
|
const { config } = await loadConfig({
|
|
190
194
|
name: "soybean",
|
|
@@ -193,6 +197,9 @@ async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
|
193
197
|
cwd,
|
|
194
198
|
packageJson: true
|
|
195
199
|
});
|
|
200
|
+
if (config?.useSoybeanToken) {
|
|
201
|
+
config.changelogOptions = { ...config.changelogOptions, github: { repo: "", token: SOYBEAN_GITHUB_TOKEN } };
|
|
202
|
+
}
|
|
196
203
|
return config;
|
|
197
204
|
}
|
|
198
205
|
|
|
@@ -210,7 +217,7 @@ async function setupCli() {
|
|
|
210
217
|
"git-commit-verify": {
|
|
211
218
|
desc: "\u6821\u9A8C git \u7684 commit \u662F\u5426\u7B26\u5408 Angular \u89C4\u8303",
|
|
212
219
|
action: () => {
|
|
213
|
-
gitCommitVerify(
|
|
220
|
+
gitCommitVerify();
|
|
214
221
|
}
|
|
215
222
|
},
|
|
216
223
|
cleanup: {
|
|
@@ -239,12 +246,11 @@ async function setupCli() {
|
|
|
239
246
|
},
|
|
240
247
|
"lint-staged": {
|
|
241
248
|
desc: "\u6267\u884Clint-staged",
|
|
242
|
-
action: () => {
|
|
243
|
-
execLintStaged(cliOptions.lintStagedConfig).
|
|
244
|
-
process.exitCode = passed ? 0 : 1;
|
|
245
|
-
}).catch(() => {
|
|
249
|
+
action: async () => {
|
|
250
|
+
const passed = await execLintStaged(cliOptions.lintStagedConfig).catch(() => {
|
|
246
251
|
process.exitCode = 1;
|
|
247
252
|
});
|
|
253
|
+
process.exitCode = passed ? 0 : 1;
|
|
248
254
|
}
|
|
249
255
|
},
|
|
250
256
|
changelog: {
|
|
@@ -292,9 +298,9 @@ async function setupCli() {
|
|
|
292
298
|
action: eslintPretter
|
|
293
299
|
}
|
|
294
300
|
};
|
|
295
|
-
|
|
301
|
+
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
296
302
|
cli.command(command, desc).action(action);
|
|
297
|
-
}
|
|
303
|
+
}
|
|
298
304
|
cli.parse();
|
|
299
305
|
}
|
|
300
306
|
setupCli();
|