@soybeanjs/cli 0.5.6 → 0.5.8
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 +24 -17
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +24 -17
- package/package.json +7 -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.5.
|
|
21
|
+
const version = "0.5.8";
|
|
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)) {
|
|
@@ -78,13 +81,14 @@ async function cleanup(paths) {
|
|
|
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
|
|
|
@@ -190,18 +194,23 @@ const defaultOptions = {
|
|
|
190
194
|
lintStagedConfig: {
|
|
191
195
|
[eslintExt]: "eslint --fix",
|
|
192
196
|
"*": "soy prettier-write"
|
|
193
|
-
}
|
|
197
|
+
},
|
|
198
|
+
useSoybeanToken: false
|
|
194
199
|
};
|
|
200
|
+
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
195
201
|
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
196
202
|
const { config } = await c12.loadConfig({
|
|
197
203
|
name: "soybean",
|
|
198
204
|
defaults: defaultOptions,
|
|
199
205
|
overrides,
|
|
200
|
-
cwd
|
|
206
|
+
cwd,
|
|
207
|
+
packageJson: true
|
|
201
208
|
});
|
|
209
|
+
if (config?.useSoybeanToken) {
|
|
210
|
+
config.changelogOptions = { ...config.changelogOptions, github: { repo: "", token: SOYBEAN_GITHUB_TOKEN } };
|
|
211
|
+
}
|
|
202
212
|
return config;
|
|
203
213
|
}
|
|
204
|
-
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
205
214
|
|
|
206
215
|
async function setupCli() {
|
|
207
216
|
const cliOptions = await loadCliOptions();
|
|
@@ -217,7 +226,7 @@ async function setupCli() {
|
|
|
217
226
|
"git-commit-verify": {
|
|
218
227
|
desc: "\u6821\u9A8C git \u7684 commit \u662F\u5426\u7B26\u5408 Angular \u89C4\u8303",
|
|
219
228
|
action: () => {
|
|
220
|
-
gitCommitVerify(
|
|
229
|
+
gitCommitVerify();
|
|
221
230
|
}
|
|
222
231
|
},
|
|
223
232
|
cleanup: {
|
|
@@ -246,12 +255,11 @@ async function setupCli() {
|
|
|
246
255
|
},
|
|
247
256
|
"lint-staged": {
|
|
248
257
|
desc: "\u6267\u884Clint-staged",
|
|
249
|
-
action: () => {
|
|
250
|
-
execLintStaged(cliOptions.lintStagedConfig).
|
|
251
|
-
process.exitCode = passed ? 0 : 1;
|
|
252
|
-
}).catch(() => {
|
|
258
|
+
action: async () => {
|
|
259
|
+
const passed = await execLintStaged(cliOptions.lintStagedConfig).catch(() => {
|
|
253
260
|
process.exitCode = 1;
|
|
254
261
|
});
|
|
262
|
+
process.exitCode = passed ? 0 : 1;
|
|
255
263
|
}
|
|
256
264
|
},
|
|
257
265
|
changelog: {
|
|
@@ -299,9 +307,9 @@ async function setupCli() {
|
|
|
299
307
|
action: eslintPretter
|
|
300
308
|
}
|
|
301
309
|
};
|
|
302
|
-
|
|
310
|
+
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
303
311
|
cli.command(command, desc).action(action);
|
|
304
|
-
}
|
|
312
|
+
}
|
|
305
313
|
cli.parse();
|
|
306
314
|
}
|
|
307
315
|
setupCli();
|
|
@@ -309,5 +317,4 @@ function defineConfig(config) {
|
|
|
309
317
|
return config;
|
|
310
318
|
}
|
|
311
319
|
|
|
312
|
-
exports.SOYBEAN_GITHUB_TOKEN = SOYBEAN_GITHUB_TOKEN;
|
|
313
320
|
exports.defineConfig = defineConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -41,10 +41,12 @@ interface CliOption {
|
|
|
41
41
|
* lint-staged config
|
|
42
42
|
*/
|
|
43
43
|
lintStagedConfig: Record<string, string | string[]>;
|
|
44
|
+
/**
|
|
45
|
+
* use soybean token
|
|
46
|
+
*/
|
|
47
|
+
useSoybeanToken: boolean;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
declare const SOYBEAN_GITHUB_TOKEN = "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";
|
|
47
|
-
|
|
48
50
|
declare function defineConfig(config?: Partial<CliOption>): Partial<CliOption> | undefined;
|
|
49
51
|
|
|
50
|
-
export { CliOption,
|
|
52
|
+
export { CliOption, defineConfig };
|
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.5.
|
|
12
|
+
const version = "0.5.8";
|
|
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)) {
|
|
@@ -70,13 +72,14 @@ async function cleanup(paths) {
|
|
|
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
|
|
|
@@ -182,18 +185,23 @@ const defaultOptions = {
|
|
|
182
185
|
lintStagedConfig: {
|
|
183
186
|
[eslintExt]: "eslint --fix",
|
|
184
187
|
"*": "soy prettier-write"
|
|
185
|
-
}
|
|
188
|
+
},
|
|
189
|
+
useSoybeanToken: false
|
|
186
190
|
};
|
|
191
|
+
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
187
192
|
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
188
193
|
const { config } = await loadConfig({
|
|
189
194
|
name: "soybean",
|
|
190
195
|
defaults: defaultOptions,
|
|
191
196
|
overrides,
|
|
192
|
-
cwd
|
|
197
|
+
cwd,
|
|
198
|
+
packageJson: true
|
|
193
199
|
});
|
|
200
|
+
if (config?.useSoybeanToken) {
|
|
201
|
+
config.changelogOptions = { ...config.changelogOptions, github: { repo: "", token: SOYBEAN_GITHUB_TOKEN } };
|
|
202
|
+
}
|
|
194
203
|
return config;
|
|
195
204
|
}
|
|
196
|
-
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
197
205
|
|
|
198
206
|
async function setupCli() {
|
|
199
207
|
const cliOptions = await loadCliOptions();
|
|
@@ -209,7 +217,7 @@ async function setupCli() {
|
|
|
209
217
|
"git-commit-verify": {
|
|
210
218
|
desc: "\u6821\u9A8C git \u7684 commit \u662F\u5426\u7B26\u5408 Angular \u89C4\u8303",
|
|
211
219
|
action: () => {
|
|
212
|
-
gitCommitVerify(
|
|
220
|
+
gitCommitVerify();
|
|
213
221
|
}
|
|
214
222
|
},
|
|
215
223
|
cleanup: {
|
|
@@ -238,12 +246,11 @@ async function setupCli() {
|
|
|
238
246
|
},
|
|
239
247
|
"lint-staged": {
|
|
240
248
|
desc: "\u6267\u884Clint-staged",
|
|
241
|
-
action: () => {
|
|
242
|
-
execLintStaged(cliOptions.lintStagedConfig).
|
|
243
|
-
process.exitCode = passed ? 0 : 1;
|
|
244
|
-
}).catch(() => {
|
|
249
|
+
action: async () => {
|
|
250
|
+
const passed = await execLintStaged(cliOptions.lintStagedConfig).catch(() => {
|
|
245
251
|
process.exitCode = 1;
|
|
246
252
|
});
|
|
253
|
+
process.exitCode = passed ? 0 : 1;
|
|
247
254
|
}
|
|
248
255
|
},
|
|
249
256
|
changelog: {
|
|
@@ -291,9 +298,9 @@ async function setupCli() {
|
|
|
291
298
|
action: eslintPretter
|
|
292
299
|
}
|
|
293
300
|
};
|
|
294
|
-
|
|
301
|
+
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
295
302
|
cli.command(command, desc).action(action);
|
|
296
|
-
}
|
|
303
|
+
}
|
|
297
304
|
cli.parse();
|
|
298
305
|
}
|
|
299
306
|
setupCli();
|
|
@@ -301,4 +308,4 @@ function defineConfig(config) {
|
|
|
301
308
|
return config;
|
|
302
309
|
}
|
|
303
310
|
|
|
304
|
-
export {
|
|
311
|
+
export { defineConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "SoybeanJS's command line tools",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Soybean",
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.mjs",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
28
31
|
"bin": {
|
|
29
32
|
"soybean": "dist/index.cjs",
|
|
30
33
|
"soy": "dist/index.cjs"
|
|
@@ -59,6 +62,9 @@
|
|
|
59
62
|
"commit-msg": "pnpm soy git-commit-verify",
|
|
60
63
|
"pre-commit": "pnpm typecheck && pnpm soy lint-staged"
|
|
61
64
|
},
|
|
65
|
+
"soybean": {
|
|
66
|
+
"useSoybeanToken": true
|
|
67
|
+
},
|
|
62
68
|
"scripts": {
|
|
63
69
|
"build": "pnpm typecheck && unbuild",
|
|
64
70
|
"lint": "eslint . --fix",
|