@soybeanjs/cli 0.7.0 → 0.7.1
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/dist/index.cjs +2 -334
- package/dist/index.mjs +2 -325
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -1,336 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
"use strict";const m=require("cac"),r=require("enquirer"),cryptoJs=require("crypto-js"),s=require("path"),fs=require("fs"),kolorist=require("kolorist"),rimraf=require("rimraf"),changelog=require("@soybeanjs/changelog"),e=require("bumpp"),c12=require("c12"),promises=require("fs/promises");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const m__default=_interopDefaultCompat(m),r__default=_interopDefaultCompat(r),s__default=_interopDefaultCompat(s),e__default=_interopDefaultCompat(e),version="0.7.1";async function execCommand(t,n,o){const{execa:a}=await import("execa");return(await a(t,n,o))?.stdout?.trim()||""}class Crypto{constructor(n){this.secret=n}enCrypto(n){const o=JSON.stringify(n);return cryptoJs.AES.encrypt(o,this.secret).toString()}deCrypto(n){const o=cryptoJs.AES.decrypt(n,this.secret).toString(cryptoJs.enc.Utf8);if(o)try{return JSON.parse(o)}catch{return null}return null}}async function gitCommit(t,n){const o=t.map(([F,d])=>{const g=`${`${F}:`.padEnd(12)}${d}`;return{name:F,message:g}}),a=n.map(([F,d])=>({name:F,message:`${F.padEnd(30)} (${d})`})),c=await r__default.prompt([{name:"types",type:"select",message:"\u8BF7\u9009\u62E9\u63D0\u4EA4\u7684\u7C7B\u578B",choices:o},{name:"scopes",type:"select",message:"\u9009\u62E9\u4E00\u4E2Ascope",choices:a},{name:"description",type:"text",message:"\u8BF7\u8F93\u5165\u63D0\u4EA4\u63CF\u8FF0"}]),E=`${c.types}(${c.scopes}): ${c.description}`;execCommand("git",["commit","-m",E],{stdio:"inherit"})}async function gitCommitVerify(){const t=await execCommand("git",["rev-parse","--show-toplevel"]),n=s__default.join(t,".git","COMMIT_EDITMSG"),o=fs.readFileSync(n,"utf-8").trim();if(!/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(o))throw new Error(`${kolorist.bgRed(" ERROR ")} ${kolorist.red(`Git\u63D0\u4EA4\u4FE1\u606F\u4E0D\u7B26\u5408 Angular \u89C4\u8303!
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const enquirer = require('enquirer');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const kolorist = require('kolorist');
|
|
9
|
-
const rimraf = require('rimraf');
|
|
10
|
-
const changelog = require('@soybeanjs/changelog');
|
|
11
|
-
const versionBump = require('bumpp');
|
|
12
|
-
const c12 = require('c12');
|
|
13
|
-
const promises = require('fs/promises');
|
|
14
|
-
|
|
15
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
16
|
-
|
|
17
|
-
const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
|
|
18
|
-
const enquirer__default = /*#__PURE__*/_interopDefaultCompat(enquirer);
|
|
19
|
-
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
20
|
-
const versionBump__default = /*#__PURE__*/_interopDefaultCompat(versionBump);
|
|
21
|
-
|
|
22
|
-
const version = "0.7.0";
|
|
23
|
-
|
|
24
|
-
async function execCommand(cmd, args, options) {
|
|
25
|
-
const { execa } = await import('execa');
|
|
26
|
-
const res = await execa(cmd, args, options);
|
|
27
|
-
return res?.stdout?.trim() || "";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function gitCommit(gitCommitTypes, gitCommitScopes) {
|
|
31
|
-
const typesChoices = gitCommitTypes.map(([name, title]) => {
|
|
32
|
-
const nameWithSuffix = `${name}:`;
|
|
33
|
-
const message = `${nameWithSuffix.padEnd(12)}${title}`;
|
|
34
|
-
return {
|
|
35
|
-
name,
|
|
36
|
-
message
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
const scopesChoices = gitCommitScopes.map(([name, title]) => ({
|
|
40
|
-
name,
|
|
41
|
-
message: `${name.padEnd(30)} (${title})`
|
|
42
|
-
}));
|
|
43
|
-
const result = await enquirer__default.prompt([
|
|
44
|
-
{
|
|
45
|
-
name: "types",
|
|
46
|
-
type: "select",
|
|
47
|
-
message: "\u8BF7\u9009\u62E9\u63D0\u4EA4\u7684\u7C7B\u578B",
|
|
48
|
-
choices: typesChoices
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "scopes",
|
|
52
|
-
type: "select",
|
|
53
|
-
message: "\u9009\u62E9\u4E00\u4E2Ascope",
|
|
54
|
-
choices: scopesChoices
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "description",
|
|
58
|
-
type: "text",
|
|
59
|
-
message: "\u8BF7\u8F93\u5165\u63D0\u4EA4\u63CF\u8FF0"
|
|
60
|
-
}
|
|
61
|
-
]);
|
|
62
|
-
const commitMsg = `${result.types}(${result.scopes}): ${result.description}`;
|
|
63
|
-
execCommand("git", ["commit", "-m", commitMsg], { stdio: "inherit" });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function gitCommitVerify() {
|
|
67
|
-
const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
|
|
68
|
-
const gitMsgPath = path__default.join(gitPath, ".git", "COMMIT_EDITMSG");
|
|
69
|
-
const commitMsg = fs.readFileSync(gitMsgPath, "utf-8").trim();
|
|
70
|
-
const REG_EXP = /(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
|
|
71
|
-
if (!REG_EXP.test(commitMsg)) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`${kolorist.bgRed(" ERROR ")} ${kolorist.red("Git\u63D0\u4EA4\u4FE1\u606F\u4E0D\u7B26\u5408 Angular \u89C4\u8303!\n\n")}${kolorist.green(
|
|
74
|
-
"\u63A8\u8350\u4F7F\u7528\u547D\u4EE4 pnpm commit \u751F\u6210\u7B26\u5408\u89C4\u8303\u7684Git\u63D0\u4EA4\u4FE1\u606F"
|
|
75
|
-
)}`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function cleanup(paths) {
|
|
81
|
-
await rimraf.rimraf(paths, { glob: true });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function initSimpleGitHooks(cwd = process.cwd()) {
|
|
85
|
-
const huskyDir = path__default.join(cwd, ".husky");
|
|
86
|
-
const existHusky = fs.existsSync(huskyDir);
|
|
87
|
-
const gitHooksDir = path__default.join(cwd, ".git", "hooks");
|
|
88
|
-
if (existHusky) {
|
|
89
|
-
await rimraf.rimraf(huskyDir);
|
|
90
|
-
await execCommand("git", ["config", "core.hooksPath", gitHooksDir], { stdio: "inherit" });
|
|
91
|
-
}
|
|
92
|
-
await rimraf.rimraf(gitHooksDir);
|
|
93
|
-
await execCommand("npx", ["simple-git-hooks"], { stdio: "inherit" });
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function ncu(args = ["--deep", "-u"]) {
|
|
97
|
-
execCommand("npx", ["ncu", ...args], { stdio: "inherit" });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function prettierWrite(writeGlob) {
|
|
101
|
-
await execCommand("npx", ["prettier", "--write", ".", ...writeGlob], {
|
|
102
|
-
stdio: "inherit"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function eslintPrettier() {
|
|
107
|
-
await execCommand("npx", ["eslint", ".", "--fix"], {
|
|
108
|
-
stdio: "inherit"
|
|
109
|
-
});
|
|
110
|
-
await execCommand("npx", ["soy", "prettier-format"], {
|
|
111
|
-
stdio: "inherit"
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function execLintStaged(config) {
|
|
116
|
-
const lintStaged = (await import('lint-staged')).default;
|
|
117
|
-
return lintStaged({ config, allowEmpty: true });
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function genChangelog(options, total = false) {
|
|
121
|
-
if (total) {
|
|
122
|
-
await changelog.generateTotalChangelog(options);
|
|
123
|
-
} else {
|
|
124
|
-
await changelog.generateChangelog(options);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function release() {
|
|
129
|
-
await versionBump__default({
|
|
130
|
-
files: ["**/package.json", "!**/node_modules"],
|
|
131
|
-
execute: "npx soy changelog",
|
|
132
|
-
all: true,
|
|
133
|
-
tag: true,
|
|
134
|
-
commit: "chore(projects): release v%s",
|
|
135
|
-
push: true
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const eslintExt = "*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}";
|
|
140
|
-
const defaultOptions = {
|
|
141
|
-
cwd: process.cwd(),
|
|
142
|
-
cleanupDirs: [
|
|
143
|
-
"**/dist",
|
|
144
|
-
"**/package-lock.json",
|
|
145
|
-
"**/yarn.lock",
|
|
146
|
-
"**/pnpm-lock.yaml",
|
|
147
|
-
"**/node_modules",
|
|
148
|
-
"!node_modules/**"
|
|
149
|
-
],
|
|
150
|
-
gitCommitTypes: [
|
|
151
|
-
["init", "\u9879\u76EE\u521D\u59CB\u5316"],
|
|
152
|
-
["feat", "\u6DFB\u52A0\u65B0\u7279\u6027"],
|
|
153
|
-
["fix", "\u4FEE\u590Dbug"],
|
|
154
|
-
["docs", "\u4EC5\u4EC5\u4FEE\u6539\u6587\u6863"],
|
|
155
|
-
["style", "\u4EC5\u4EC5\u4FEE\u6539\u4E86\u7A7A\u683C\u3001\u683C\u5F0F\u7F29\u8FDB\u3001\u9017\u53F7\u7B49\u7B49\uFF0C\u4E0D\u6539\u53D8\u4EE3\u7801\u903B\u8F91"],
|
|
156
|
-
["refactor", "\u4EE3\u7801\u91CD\u6784\uFF0C\u6CA1\u6709\u52A0\u65B0\u529F\u80FD\u6216\u8005\u4FEE\u590Dbug"],
|
|
157
|
-
["perf", "\u4F18\u5316\u76F8\u5173\uFF0C\u6BD4\u5982\u63D0\u5347\u6027\u80FD\u3001\u4F53\u9A8C"],
|
|
158
|
-
["test", "\u6DFB\u52A0\u6D4B\u8BD5\u7528\u4F8B"],
|
|
159
|
-
["build", "\u4F9D\u8D56\u76F8\u5173\u7684\u5185\u5BB9"],
|
|
160
|
-
["ci", "CI\u914D\u7F6E\u76F8\u5173\uFF0C\u4F8B\u5982\u5BF9k8s\uFF0Cdocker\u7684\u914D\u7F6E\u6587\u4EF6\u7684\u4FEE\u6539"],
|
|
161
|
-
["chore", "\u6539\u53D8\u6784\u5EFA\u6D41\u7A0B\u3001\u6216\u8005\u589E\u52A0\u4F9D\u8D56\u5E93\u3001\u5DE5\u5177\u7B49"],
|
|
162
|
-
["revert", "\u56DE\u6EDA\u5230\u4E0A\u4E00\u4E2A\u7248\u672C"]
|
|
163
|
-
],
|
|
164
|
-
gitCommitScopes: [
|
|
165
|
-
["projects", "\u9879\u76EE\u642D\u5EFA"],
|
|
166
|
-
["components", "\u7EC4\u4EF6\u76F8\u5173"],
|
|
167
|
-
["hooks", "hook \u76F8\u5173"],
|
|
168
|
-
["utils", "utils \u76F8\u5173"],
|
|
169
|
-
["types", "ts\u7C7B\u578B\u76F8\u5173"],
|
|
170
|
-
["styles", "\u6837\u5F0F\u76F8\u5173"],
|
|
171
|
-
["deps", "\u9879\u76EE\u4F9D\u8D56"],
|
|
172
|
-
["auth", "\u5BF9 auth \u4FEE\u6539"],
|
|
173
|
-
["release", "\u7248\u672C\u53D1\u5E03"],
|
|
174
|
-
["other", "\u5176\u4ED6\u4FEE\u6539"]
|
|
175
|
-
],
|
|
176
|
-
ncuCommandArgs: ["--deep", "-u"],
|
|
177
|
-
changelogOptions: {},
|
|
178
|
-
prettierWriteGlob: [
|
|
179
|
-
`!**/${eslintExt}`,
|
|
180
|
-
"!*.min.*",
|
|
181
|
-
"!CHANGELOG.md",
|
|
182
|
-
"!dist",
|
|
183
|
-
"!LICENSE*",
|
|
184
|
-
"!output",
|
|
185
|
-
"!coverage",
|
|
186
|
-
"!public",
|
|
187
|
-
"!temp",
|
|
188
|
-
"!package-lock.json",
|
|
189
|
-
"!pnpm-lock.yaml",
|
|
190
|
-
"!yarn.lock",
|
|
191
|
-
"!.github",
|
|
192
|
-
"!__snapshots__",
|
|
193
|
-
"!node_modules"
|
|
194
|
-
],
|
|
195
|
-
lintStagedConfig: {
|
|
196
|
-
[eslintExt]: "eslint --fix",
|
|
197
|
-
"*": "soy prettier-write"
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
201
|
-
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
202
|
-
const { config } = await c12.loadConfig({
|
|
203
|
-
name: "soybean",
|
|
204
|
-
defaults: defaultOptions,
|
|
205
|
-
overrides,
|
|
206
|
-
cwd,
|
|
207
|
-
packageJson: true
|
|
208
|
-
});
|
|
209
|
-
const has = await hasSoybeanInfoFromPkgJson(cwd);
|
|
210
|
-
if (config && has) {
|
|
211
|
-
config.changelogOptions = { ...config.changelogOptions, github: { repo: "", token: SOYBEAN_GITHUB_TOKEN } };
|
|
212
|
-
}
|
|
213
|
-
return config;
|
|
214
|
-
}
|
|
215
|
-
async function hasSoybeanInfoFromPkgJson(cwd) {
|
|
216
|
-
let hasSoybeanInfo = false;
|
|
217
|
-
const REG = "soybean";
|
|
218
|
-
try {
|
|
219
|
-
const pkgJson = await promises.readFile(`${cwd}/package.json`, "utf-8");
|
|
220
|
-
const pkg = JSON.parse(pkgJson);
|
|
221
|
-
hasSoybeanInfo = pkg.name?.includes(REG) || pkg.repository?.url?.includes(REG) || pkg.author?.includes(REG) || pkg.author?.name?.includes(REG) || pkg.author?.url?.includes(REG);
|
|
222
|
-
} catch {
|
|
223
|
-
}
|
|
224
|
-
return hasSoybeanInfo;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async function setupCli() {
|
|
228
|
-
const cliOptions = await loadCliOptions();
|
|
229
|
-
const cli = cac__default("soybean");
|
|
230
|
-
cli.version(version).option("--total", "Generate changelog by total tags").help();
|
|
231
|
-
const commands = {
|
|
232
|
-
"git-commit": {
|
|
233
|
-
desc: "\u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684\u63D0\u4EA4\u4FE1\u606F",
|
|
234
|
-
action: async () => {
|
|
235
|
-
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes);
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
"git-commit-verify": {
|
|
239
|
-
desc: "\u6821\u9A8C git \u63D0\u4EA4\u4FE1\u606F\u662F\u5426\u7B26\u5408 Conventional Commits \u89C4\u8303",
|
|
240
|
-
action: async () => {
|
|
241
|
-
await gitCommitVerify();
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
cleanup: {
|
|
245
|
-
desc: "\u6E05\u7A7A\u4F9D\u8D56\u548C\u6784\u5EFA\u4EA7\u7269",
|
|
246
|
-
action: async () => {
|
|
247
|
-
await cleanup(cliOptions.cleanupDirs);
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
"init-simple-git-hooks": {
|
|
251
|
-
desc: "\u521D\u59CB\u5316 simple-git-hooks \u94A9\u5B50",
|
|
252
|
-
action: async () => {
|
|
253
|
-
await initSimpleGitHooks(cliOptions.cwd);
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
ncu: {
|
|
257
|
-
desc: "\u547D\u4EE4 npm-check-updates, \u5347\u7EA7\u4F9D\u8D56",
|
|
258
|
-
action: async () => {
|
|
259
|
-
await ncu(cliOptions.ncuCommandArgs);
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
"prettier-write": {
|
|
263
|
-
desc: "\u6267\u884C prettier --write \u683C\u5F0F\u5316",
|
|
264
|
-
action: async () => {
|
|
265
|
-
await prettierWrite(cliOptions.prettierWriteGlob);
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
"lint-staged": {
|
|
269
|
-
desc: "\u6267\u884Clint-staged",
|
|
270
|
-
action: async () => {
|
|
271
|
-
const passed = await execLintStaged(cliOptions.lintStagedConfig).catch(() => {
|
|
272
|
-
process.exitCode = 1;
|
|
273
|
-
});
|
|
274
|
-
process.exitCode = passed ? 0 : 1;
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
changelog: {
|
|
278
|
-
desc: "\u751F\u6210changelog",
|
|
279
|
-
action: async (args) => {
|
|
280
|
-
await genChangelog(cliOptions.changelogOptions, args?.total);
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
release: {
|
|
284
|
-
desc: "\u53D1\u5E03\uFF1A\u66F4\u65B0\u7248\u672C\u53F7\u3001\u751F\u6210changelog\u3001\u63D0\u4EA4\u4EE3\u7801",
|
|
285
|
-
action: async () => {
|
|
286
|
-
await release();
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
/**
|
|
290
|
-
* @deprecated
|
|
291
|
-
*/
|
|
292
|
-
"init-git-hooks": {
|
|
293
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 init-simple-git-hooks",
|
|
294
|
-
action: async () => {
|
|
295
|
-
await initSimpleGitHooks(cliOptions.cwd);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
/**
|
|
299
|
-
* @deprecated
|
|
300
|
-
*/
|
|
301
|
-
"update-pkg": {
|
|
302
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 ncu",
|
|
303
|
-
action: async () => {
|
|
304
|
-
await ncu(cliOptions.ncuCommandArgs);
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
/**
|
|
308
|
-
* @deprecated
|
|
309
|
-
*/
|
|
310
|
-
"prettier-format": {
|
|
311
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 prettier-write",
|
|
312
|
-
action: async () => {
|
|
313
|
-
await prettierWrite(cliOptions.prettierWriteGlob);
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
/**
|
|
317
|
-
* @deprecated
|
|
318
|
-
*/
|
|
319
|
-
"eslint-prettier": {
|
|
320
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03",
|
|
321
|
-
action: async () => {
|
|
322
|
-
await eslintPrettier();
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
327
|
-
cli.command(command, desc).action(action);
|
|
328
|
-
}
|
|
329
|
-
cli.parse();
|
|
330
|
-
}
|
|
331
|
-
setupCli();
|
|
332
|
-
function defineConfig(config) {
|
|
333
|
-
return config;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
exports.defineConfig = defineConfig;
|
|
4
|
+
`)}${kolorist.green("\u63A8\u8350\u4F7F\u7528\u547D\u4EE4 pnpm commit \u751F\u6210\u7B26\u5408\u89C4\u8303\u7684Git\u63D0\u4EA4\u4FE1\u606F")}`)}async function cleanup(t){await rimraf.rimraf(t,{glob:!0})}async function initSimpleGitHooks(t=process.cwd()){const n=s__default.join(t,".husky"),o=fs.existsSync(n),a=s__default.join(t,".git","hooks");o&&(await rimraf.rimraf(n),await execCommand("git",["config","core.hooksPath",a],{stdio:"inherit"})),await rimraf.rimraf(a),await execCommand("npx",["simple-git-hooks"],{stdio:"inherit"})}async function ncu(t=["--deep","-u"]){execCommand("npx",["ncu",...t],{stdio:"inherit"})}async function prettierWrite(t){await execCommand("npx",["prettier","--write",".",...t],{stdio:"inherit"})}async function eslintPrettier(){await execCommand("npx",["eslint",".","--fix"],{stdio:"inherit"}),await execCommand("npx",["soy","prettier-format"],{stdio:"inherit"})}async function execLintStaged(t){const n=(await import("lint-staged")).default;return n({config:t,allowEmpty:!0})}async function genChangelog(t,n=!1){n?await changelog.generateTotalChangelog(t):await changelog.generateChangelog(t)}async function release(){await e__default({files:["**/package.json","!**/node_modules"],execute:"npx soy changelog",all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}const i="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",l={cwd:process.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["init","\u9879\u76EE\u521D\u59CB\u5316"],["feat","\u6DFB\u52A0\u65B0\u7279\u6027"],["fix","\u4FEE\u590Dbug"],["docs","\u4EC5\u4EC5\u4FEE\u6539\u6587\u6863"],["style","\u4EC5\u4EC5\u4FEE\u6539\u4E86\u7A7A\u683C\u3001\u683C\u5F0F\u7F29\u8FDB\u3001\u9017\u53F7\u7B49\u7B49\uFF0C\u4E0D\u6539\u53D8\u4EE3\u7801\u903B\u8F91"],["refactor","\u4EE3\u7801\u91CD\u6784\uFF0C\u6CA1\u6709\u52A0\u65B0\u529F\u80FD\u6216\u8005\u4FEE\u590Dbug"],["perf","\u4F18\u5316\u76F8\u5173\uFF0C\u6BD4\u5982\u63D0\u5347\u6027\u80FD\u3001\u4F53\u9A8C"],["test","\u6DFB\u52A0\u6D4B\u8BD5\u7528\u4F8B"],["build","\u4F9D\u8D56\u76F8\u5173\u7684\u5185\u5BB9"],["ci","CI\u914D\u7F6E\u76F8\u5173\uFF0C\u4F8B\u5982\u5BF9k8s\uFF0Cdocker\u7684\u914D\u7F6E\u6587\u4EF6\u7684\u4FEE\u6539"],["chore","\u6539\u53D8\u6784\u5EFA\u6D41\u7A0B\u3001\u6216\u8005\u589E\u52A0\u4F9D\u8D56\u5E93\u3001\u5DE5\u5177\u7B49"],["revert","\u56DE\u6EDA\u5230\u4E0A\u4E00\u4E2A\u7248\u672C"]],gitCommitScopes:[["projects","\u9879\u76EE\u642D\u5EFA"],["components","\u7EC4\u4EF6\u76F8\u5173"],["hooks","hook \u76F8\u5173"],["utils","utils \u76F8\u5173"],["types","ts\u7C7B\u578B\u76F8\u5173"],["styles","\u6837\u5F0F\u76F8\u5173"],["deps","\u9879\u76EE\u4F9D\u8D56"],["auth","\u5BF9 auth \u4FEE\u6539"],["release","\u7248\u672C\u53D1\u5E03"],["other","\u5176\u4ED6\u4FEE\u6539"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${i}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[i]:"eslint --fix","*":"soy prettier-write"}},p="U2FsdGVkX1+vLW5S5+vcx+LKGSR2PtJOAZUZsVCTKM0+ecI3hDuARJn6kdLzzR1LVl0179NmgMoX6fV28TMu3A==";async function loadCliOptions(t,n=process.cwd()){const{config:o}=await c12.loadConfig({name:"soybean",defaults:l,overrides:t,cwd:n,packageJson:!0}),a=await u$1(n);if(o&&a){const c=new Crypto("SOYBEAN_JS");o.changelogOptions={...o.changelogOptions,github:{repo:"",token:c.deCrypto(p)||""}}}return o}async function u$1(t){let n=!1;const o="soybean";try{const a=await promises.readFile(`${t}/package.json`,"utf-8"),c=JSON.parse(a);n=c.name?.includes(o)||c.repository?.url?.includes(o)||c.author?.includes(o)||c.author?.name?.includes(o)||c.author?.url?.includes(o)}catch{}return n}async function u(){const t=await loadCliOptions(),n=m__default("soybean");n.version(version).option("--total","Generate changelog by total tags").help();const o={"git-commit":{desc:"\u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684\u63D0\u4EA4\u4FE1\u606F",action:async()=>{await gitCommit(t.gitCommitTypes,t.gitCommitScopes)}},"git-commit-verify":{desc:"\u6821\u9A8C git \u63D0\u4EA4\u4FE1\u606F\u662F\u5426\u7B26\u5408 Conventional Commits \u89C4\u8303",action:async()=>{await gitCommitVerify()}},cleanup:{desc:"\u6E05\u7A7A\u4F9D\u8D56\u548C\u6784\u5EFA\u4EA7\u7269",action:async()=>{await cleanup(t.cleanupDirs)}},"init-simple-git-hooks":{desc:"\u521D\u59CB\u5316 simple-git-hooks \u94A9\u5B50",action:async()=>{await initSimpleGitHooks(t.cwd)}},ncu:{desc:"\u547D\u4EE4 npm-check-updates, \u5347\u7EA7\u4F9D\u8D56",action:async()=>{await ncu(t.ncuCommandArgs)}},"prettier-write":{desc:"\u6267\u884C prettier --write \u683C\u5F0F\u5316",action:async()=>{await prettierWrite(t.prettierWriteGlob)}},"lint-staged":{desc:"\u6267\u884Clint-staged",action:async()=>{const a=await execLintStaged(t.lintStagedConfig).catch(()=>{process.exitCode=1});process.exitCode=a?0:1}},changelog:{desc:"\u751F\u6210changelog",action:async a=>{await genChangelog(t.changelogOptions,a?.total)}},release:{desc:"\u53D1\u5E03\uFF1A\u66F4\u65B0\u7248\u672C\u53F7\u3001\u751F\u6210changelog\u3001\u63D0\u4EA4\u4EE3\u7801",action:async()=>{await release()}},"init-git-hooks":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 init-simple-git-hooks",action:async()=>{await initSimpleGitHooks(t.cwd)}},"update-pkg":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 ncu",action:async()=>{await ncu(t.ncuCommandArgs)}},"prettier-format":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 prettier-write",action:async()=>{await prettierWrite(t.prettierWriteGlob)}},"eslint-prettier":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03",action:async()=>{await eslintPrettier()}}};for await(const[a,{desc:c,action:E}]of Object.entries(o))n.command(a,c).action(E);n.parse()}u();function defineConfig(t){return t}exports.defineConfig=defineConfig;
|
package/dist/index.mjs
CHANGED
|
@@ -1,327 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import cac from
|
|
3
|
-
import enquirer from 'enquirer';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { readFileSync, existsSync } from 'fs';
|
|
6
|
-
import { bgRed, red, green } from 'kolorist';
|
|
7
|
-
import { rimraf } from 'rimraf';
|
|
8
|
-
import { generateTotalChangelog, generateChangelog } from '@soybeanjs/changelog';
|
|
9
|
-
import versionBump from 'bumpp';
|
|
10
|
-
import { loadConfig } from 'c12';
|
|
11
|
-
import { readFile } from 'fs/promises';
|
|
2
|
+
import C from"cac";import y from"enquirer";import{AES as F,enc as D}from"crypto-js";import r from"path";import{readFileSync as f,existsSync as h}from"fs";import{bgRed as w,red as A,green as B}from"kolorist";import{rimraf as p}from"rimraf";import{generateTotalChangelog as k,generateChangelog as x}from"@soybeanjs/changelog";import S from"bumpp";import{loadConfig as b}from"c12";import{readFile as v}from"fs/promises";const j="0.7.1";async function n(u,t,e){const{execa:i}=await import("execa");return(await i(u,t,e))?.stdout?.trim()||""}class O{constructor(t){this.secret=t}enCrypto(t){const e=JSON.stringify(t);return F.encrypt(e,this.secret).toString()}deCrypto(t){const e=F.decrypt(t,this.secret).toString(D.Utf8);if(e)try{return JSON.parse(e)}catch{return null}return null}}async function $(u,t){const e=u.map(([s,c])=>{const g=`${`${s}:`.padEnd(12)}${c}`;return{name:s,message:g}}),i=t.map(([s,c])=>({name:s,message:`${s.padEnd(30)} (${c})`})),o=await y.prompt([{name:"types",type:"select",message:"\u8BF7\u9009\u62E9\u63D0\u4EA4\u7684\u7C7B\u578B",choices:e},{name:"scopes",type:"select",message:"\u9009\u62E9\u4E00\u4E2Ascope",choices:i},{name:"description",type:"text",message:"\u8BF7\u8F93\u5165\u63D0\u4EA4\u63CF\u8FF0"}]),a=`${o.types}(${o.scopes}): ${o.description}`;n("git",["commit","-m",a],{stdio:"inherit"})}async function G(){const u=await n("git",["rev-parse","--show-toplevel"]),t=r.join(u,".git","COMMIT_EDITMSG"),e=f(t,"utf-8").trim();if(!/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(e))throw new Error(`${w(" ERROR ")} ${A(`Git\u63D0\u4EA4\u4FE1\u606F\u4E0D\u7B26\u5408 Angular \u89C4\u8303!
|
|
12
3
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
async function execCommand(cmd, args, options) {
|
|
16
|
-
const { execa } = await import('execa');
|
|
17
|
-
const res = await execa(cmd, args, options);
|
|
18
|
-
return res?.stdout?.trim() || "";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function gitCommit(gitCommitTypes, gitCommitScopes) {
|
|
22
|
-
const typesChoices = gitCommitTypes.map(([name, title]) => {
|
|
23
|
-
const nameWithSuffix = `${name}:`;
|
|
24
|
-
const message = `${nameWithSuffix.padEnd(12)}${title}`;
|
|
25
|
-
return {
|
|
26
|
-
name,
|
|
27
|
-
message
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
const scopesChoices = gitCommitScopes.map(([name, title]) => ({
|
|
31
|
-
name,
|
|
32
|
-
message: `${name.padEnd(30)} (${title})`
|
|
33
|
-
}));
|
|
34
|
-
const result = await enquirer.prompt([
|
|
35
|
-
{
|
|
36
|
-
name: "types",
|
|
37
|
-
type: "select",
|
|
38
|
-
message: "\u8BF7\u9009\u62E9\u63D0\u4EA4\u7684\u7C7B\u578B",
|
|
39
|
-
choices: typesChoices
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: "scopes",
|
|
43
|
-
type: "select",
|
|
44
|
-
message: "\u9009\u62E9\u4E00\u4E2Ascope",
|
|
45
|
-
choices: scopesChoices
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "description",
|
|
49
|
-
type: "text",
|
|
50
|
-
message: "\u8BF7\u8F93\u5165\u63D0\u4EA4\u63CF\u8FF0"
|
|
51
|
-
}
|
|
52
|
-
]);
|
|
53
|
-
const commitMsg = `${result.types}(${result.scopes}): ${result.description}`;
|
|
54
|
-
execCommand("git", ["commit", "-m", commitMsg], { stdio: "inherit" });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function gitCommitVerify() {
|
|
58
|
-
const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
|
|
59
|
-
const gitMsgPath = path.join(gitPath, ".git", "COMMIT_EDITMSG");
|
|
60
|
-
const commitMsg = readFileSync(gitMsgPath, "utf-8").trim();
|
|
61
|
-
const REG_EXP = /(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
|
|
62
|
-
if (!REG_EXP.test(commitMsg)) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`${bgRed(" ERROR ")} ${red("Git\u63D0\u4EA4\u4FE1\u606F\u4E0D\u7B26\u5408 Angular \u89C4\u8303!\n\n")}${green(
|
|
65
|
-
"\u63A8\u8350\u4F7F\u7528\u547D\u4EE4 pnpm commit \u751F\u6210\u7B26\u5408\u89C4\u8303\u7684Git\u63D0\u4EA4\u4FE1\u606F"
|
|
66
|
-
)}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function cleanup(paths) {
|
|
72
|
-
await rimraf(paths, { glob: true });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function initSimpleGitHooks(cwd = process.cwd()) {
|
|
76
|
-
const huskyDir = path.join(cwd, ".husky");
|
|
77
|
-
const existHusky = existsSync(huskyDir);
|
|
78
|
-
const gitHooksDir = path.join(cwd, ".git", "hooks");
|
|
79
|
-
if (existHusky) {
|
|
80
|
-
await rimraf(huskyDir);
|
|
81
|
-
await execCommand("git", ["config", "core.hooksPath", gitHooksDir], { stdio: "inherit" });
|
|
82
|
-
}
|
|
83
|
-
await rimraf(gitHooksDir);
|
|
84
|
-
await execCommand("npx", ["simple-git-hooks"], { stdio: "inherit" });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function ncu(args = ["--deep", "-u"]) {
|
|
88
|
-
execCommand("npx", ["ncu", ...args], { stdio: "inherit" });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function prettierWrite(writeGlob) {
|
|
92
|
-
await execCommand("npx", ["prettier", "--write", ".", ...writeGlob], {
|
|
93
|
-
stdio: "inherit"
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function eslintPrettier() {
|
|
98
|
-
await execCommand("npx", ["eslint", ".", "--fix"], {
|
|
99
|
-
stdio: "inherit"
|
|
100
|
-
});
|
|
101
|
-
await execCommand("npx", ["soy", "prettier-format"], {
|
|
102
|
-
stdio: "inherit"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function execLintStaged(config) {
|
|
107
|
-
const lintStaged = (await import('lint-staged')).default;
|
|
108
|
-
return lintStaged({ config, allowEmpty: true });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async function genChangelog(options, total = false) {
|
|
112
|
-
if (total) {
|
|
113
|
-
await generateTotalChangelog(options);
|
|
114
|
-
} else {
|
|
115
|
-
await generateChangelog(options);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function release() {
|
|
120
|
-
await versionBump({
|
|
121
|
-
files: ["**/package.json", "!**/node_modules"],
|
|
122
|
-
execute: "npx soy changelog",
|
|
123
|
-
all: true,
|
|
124
|
-
tag: true,
|
|
125
|
-
commit: "chore(projects): release v%s",
|
|
126
|
-
push: true
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const eslintExt = "*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}";
|
|
131
|
-
const defaultOptions = {
|
|
132
|
-
cwd: process.cwd(),
|
|
133
|
-
cleanupDirs: [
|
|
134
|
-
"**/dist",
|
|
135
|
-
"**/package-lock.json",
|
|
136
|
-
"**/yarn.lock",
|
|
137
|
-
"**/pnpm-lock.yaml",
|
|
138
|
-
"**/node_modules",
|
|
139
|
-
"!node_modules/**"
|
|
140
|
-
],
|
|
141
|
-
gitCommitTypes: [
|
|
142
|
-
["init", "\u9879\u76EE\u521D\u59CB\u5316"],
|
|
143
|
-
["feat", "\u6DFB\u52A0\u65B0\u7279\u6027"],
|
|
144
|
-
["fix", "\u4FEE\u590Dbug"],
|
|
145
|
-
["docs", "\u4EC5\u4EC5\u4FEE\u6539\u6587\u6863"],
|
|
146
|
-
["style", "\u4EC5\u4EC5\u4FEE\u6539\u4E86\u7A7A\u683C\u3001\u683C\u5F0F\u7F29\u8FDB\u3001\u9017\u53F7\u7B49\u7B49\uFF0C\u4E0D\u6539\u53D8\u4EE3\u7801\u903B\u8F91"],
|
|
147
|
-
["refactor", "\u4EE3\u7801\u91CD\u6784\uFF0C\u6CA1\u6709\u52A0\u65B0\u529F\u80FD\u6216\u8005\u4FEE\u590Dbug"],
|
|
148
|
-
["perf", "\u4F18\u5316\u76F8\u5173\uFF0C\u6BD4\u5982\u63D0\u5347\u6027\u80FD\u3001\u4F53\u9A8C"],
|
|
149
|
-
["test", "\u6DFB\u52A0\u6D4B\u8BD5\u7528\u4F8B"],
|
|
150
|
-
["build", "\u4F9D\u8D56\u76F8\u5173\u7684\u5185\u5BB9"],
|
|
151
|
-
["ci", "CI\u914D\u7F6E\u76F8\u5173\uFF0C\u4F8B\u5982\u5BF9k8s\uFF0Cdocker\u7684\u914D\u7F6E\u6587\u4EF6\u7684\u4FEE\u6539"],
|
|
152
|
-
["chore", "\u6539\u53D8\u6784\u5EFA\u6D41\u7A0B\u3001\u6216\u8005\u589E\u52A0\u4F9D\u8D56\u5E93\u3001\u5DE5\u5177\u7B49"],
|
|
153
|
-
["revert", "\u56DE\u6EDA\u5230\u4E0A\u4E00\u4E2A\u7248\u672C"]
|
|
154
|
-
],
|
|
155
|
-
gitCommitScopes: [
|
|
156
|
-
["projects", "\u9879\u76EE\u642D\u5EFA"],
|
|
157
|
-
["components", "\u7EC4\u4EF6\u76F8\u5173"],
|
|
158
|
-
["hooks", "hook \u76F8\u5173"],
|
|
159
|
-
["utils", "utils \u76F8\u5173"],
|
|
160
|
-
["types", "ts\u7C7B\u578B\u76F8\u5173"],
|
|
161
|
-
["styles", "\u6837\u5F0F\u76F8\u5173"],
|
|
162
|
-
["deps", "\u9879\u76EE\u4F9D\u8D56"],
|
|
163
|
-
["auth", "\u5BF9 auth \u4FEE\u6539"],
|
|
164
|
-
["release", "\u7248\u672C\u53D1\u5E03"],
|
|
165
|
-
["other", "\u5176\u4ED6\u4FEE\u6539"]
|
|
166
|
-
],
|
|
167
|
-
ncuCommandArgs: ["--deep", "-u"],
|
|
168
|
-
changelogOptions: {},
|
|
169
|
-
prettierWriteGlob: [
|
|
170
|
-
`!**/${eslintExt}`,
|
|
171
|
-
"!*.min.*",
|
|
172
|
-
"!CHANGELOG.md",
|
|
173
|
-
"!dist",
|
|
174
|
-
"!LICENSE*",
|
|
175
|
-
"!output",
|
|
176
|
-
"!coverage",
|
|
177
|
-
"!public",
|
|
178
|
-
"!temp",
|
|
179
|
-
"!package-lock.json",
|
|
180
|
-
"!pnpm-lock.yaml",
|
|
181
|
-
"!yarn.lock",
|
|
182
|
-
"!.github",
|
|
183
|
-
"!__snapshots__",
|
|
184
|
-
"!node_modules"
|
|
185
|
-
],
|
|
186
|
-
lintStagedConfig: {
|
|
187
|
-
[eslintExt]: "eslint --fix",
|
|
188
|
-
"*": "soy prettier-write"
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
const SOYBEAN_GITHUB_TOKEN = "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";
|
|
192
|
-
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
193
|
-
const { config } = await loadConfig({
|
|
194
|
-
name: "soybean",
|
|
195
|
-
defaults: defaultOptions,
|
|
196
|
-
overrides,
|
|
197
|
-
cwd,
|
|
198
|
-
packageJson: true
|
|
199
|
-
});
|
|
200
|
-
const has = await hasSoybeanInfoFromPkgJson(cwd);
|
|
201
|
-
if (config && has) {
|
|
202
|
-
config.changelogOptions = { ...config.changelogOptions, github: { repo: "", token: SOYBEAN_GITHUB_TOKEN } };
|
|
203
|
-
}
|
|
204
|
-
return config;
|
|
205
|
-
}
|
|
206
|
-
async function hasSoybeanInfoFromPkgJson(cwd) {
|
|
207
|
-
let hasSoybeanInfo = false;
|
|
208
|
-
const REG = "soybean";
|
|
209
|
-
try {
|
|
210
|
-
const pkgJson = await readFile(`${cwd}/package.json`, "utf-8");
|
|
211
|
-
const pkg = JSON.parse(pkgJson);
|
|
212
|
-
hasSoybeanInfo = pkg.name?.includes(REG) || pkg.repository?.url?.includes(REG) || pkg.author?.includes(REG) || pkg.author?.name?.includes(REG) || pkg.author?.url?.includes(REG);
|
|
213
|
-
} catch {
|
|
214
|
-
}
|
|
215
|
-
return hasSoybeanInfo;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
async function setupCli() {
|
|
219
|
-
const cliOptions = await loadCliOptions();
|
|
220
|
-
const cli = cac("soybean");
|
|
221
|
-
cli.version(version).option("--total", "Generate changelog by total tags").help();
|
|
222
|
-
const commands = {
|
|
223
|
-
"git-commit": {
|
|
224
|
-
desc: "\u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684\u63D0\u4EA4\u4FE1\u606F",
|
|
225
|
-
action: async () => {
|
|
226
|
-
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes);
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
"git-commit-verify": {
|
|
230
|
-
desc: "\u6821\u9A8C git \u63D0\u4EA4\u4FE1\u606F\u662F\u5426\u7B26\u5408 Conventional Commits \u89C4\u8303",
|
|
231
|
-
action: async () => {
|
|
232
|
-
await gitCommitVerify();
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
cleanup: {
|
|
236
|
-
desc: "\u6E05\u7A7A\u4F9D\u8D56\u548C\u6784\u5EFA\u4EA7\u7269",
|
|
237
|
-
action: async () => {
|
|
238
|
-
await cleanup(cliOptions.cleanupDirs);
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
"init-simple-git-hooks": {
|
|
242
|
-
desc: "\u521D\u59CB\u5316 simple-git-hooks \u94A9\u5B50",
|
|
243
|
-
action: async () => {
|
|
244
|
-
await initSimpleGitHooks(cliOptions.cwd);
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
ncu: {
|
|
248
|
-
desc: "\u547D\u4EE4 npm-check-updates, \u5347\u7EA7\u4F9D\u8D56",
|
|
249
|
-
action: async () => {
|
|
250
|
-
await ncu(cliOptions.ncuCommandArgs);
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
"prettier-write": {
|
|
254
|
-
desc: "\u6267\u884C prettier --write \u683C\u5F0F\u5316",
|
|
255
|
-
action: async () => {
|
|
256
|
-
await prettierWrite(cliOptions.prettierWriteGlob);
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
"lint-staged": {
|
|
260
|
-
desc: "\u6267\u884Clint-staged",
|
|
261
|
-
action: async () => {
|
|
262
|
-
const passed = await execLintStaged(cliOptions.lintStagedConfig).catch(() => {
|
|
263
|
-
process.exitCode = 1;
|
|
264
|
-
});
|
|
265
|
-
process.exitCode = passed ? 0 : 1;
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
changelog: {
|
|
269
|
-
desc: "\u751F\u6210changelog",
|
|
270
|
-
action: async (args) => {
|
|
271
|
-
await genChangelog(cliOptions.changelogOptions, args?.total);
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
release: {
|
|
275
|
-
desc: "\u53D1\u5E03\uFF1A\u66F4\u65B0\u7248\u672C\u53F7\u3001\u751F\u6210changelog\u3001\u63D0\u4EA4\u4EE3\u7801",
|
|
276
|
-
action: async () => {
|
|
277
|
-
await release();
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
/**
|
|
281
|
-
* @deprecated
|
|
282
|
-
*/
|
|
283
|
-
"init-git-hooks": {
|
|
284
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 init-simple-git-hooks",
|
|
285
|
-
action: async () => {
|
|
286
|
-
await initSimpleGitHooks(cliOptions.cwd);
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
/**
|
|
290
|
-
* @deprecated
|
|
291
|
-
*/
|
|
292
|
-
"update-pkg": {
|
|
293
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 ncu",
|
|
294
|
-
action: async () => {
|
|
295
|
-
await ncu(cliOptions.ncuCommandArgs);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
/**
|
|
299
|
-
* @deprecated
|
|
300
|
-
*/
|
|
301
|
-
"prettier-format": {
|
|
302
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 prettier-write",
|
|
303
|
-
action: async () => {
|
|
304
|
-
await prettierWrite(cliOptions.prettierWriteGlob);
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
/**
|
|
308
|
-
* @deprecated
|
|
309
|
-
*/
|
|
310
|
-
"eslint-prettier": {
|
|
311
|
-
desc: "\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03",
|
|
312
|
-
action: async () => {
|
|
313
|
-
await eslintPrettier();
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
318
|
-
cli.command(command, desc).action(action);
|
|
319
|
-
}
|
|
320
|
-
cli.parse();
|
|
321
|
-
}
|
|
322
|
-
setupCli();
|
|
323
|
-
function defineConfig(config) {
|
|
324
|
-
return config;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export { defineConfig };
|
|
4
|
+
`)}${B("\u63A8\u8350\u4F7F\u7528\u547D\u4EE4 pnpm commit \u751F\u6210\u7B26\u5408\u89C4\u8303\u7684Git\u63D0\u4EA4\u4FE1\u606F")}`)}async function _(u){await p(u,{glob:!0})}async function m(u=process.cwd()){const t=r.join(u,".husky"),e=h(t),i=r.join(u,".git","hooks");e&&(await p(t),await n("git",["config","core.hooksPath",i],{stdio:"inherit"})),await p(i),await n("npx",["simple-git-hooks"],{stdio:"inherit"})}async function E(u=["--deep","-u"]){n("npx",["ncu",...u],{stdio:"inherit"})}async function l(u){await n("npx",["prettier","--write",".",...u],{stdio:"inherit"})}async function J(){await n("npx",["eslint",".","--fix"],{stdio:"inherit"}),await n("npx",["soy","prettier-format"],{stdio:"inherit"})}async function L(u){const t=(await import("lint-staged")).default;return t({config:u,allowEmpty:!0})}async function N(u,t=!1){t?await k(u):await x(u)}async function R(){await S({files:["**/package.json","!**/node_modules"],execute:"npx soy changelog",all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}const d="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",T={cwd:process.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["init","\u9879\u76EE\u521D\u59CB\u5316"],["feat","\u6DFB\u52A0\u65B0\u7279\u6027"],["fix","\u4FEE\u590Dbug"],["docs","\u4EC5\u4EC5\u4FEE\u6539\u6587\u6863"],["style","\u4EC5\u4EC5\u4FEE\u6539\u4E86\u7A7A\u683C\u3001\u683C\u5F0F\u7F29\u8FDB\u3001\u9017\u53F7\u7B49\u7B49\uFF0C\u4E0D\u6539\u53D8\u4EE3\u7801\u903B\u8F91"],["refactor","\u4EE3\u7801\u91CD\u6784\uFF0C\u6CA1\u6709\u52A0\u65B0\u529F\u80FD\u6216\u8005\u4FEE\u590Dbug"],["perf","\u4F18\u5316\u76F8\u5173\uFF0C\u6BD4\u5982\u63D0\u5347\u6027\u80FD\u3001\u4F53\u9A8C"],["test","\u6DFB\u52A0\u6D4B\u8BD5\u7528\u4F8B"],["build","\u4F9D\u8D56\u76F8\u5173\u7684\u5185\u5BB9"],["ci","CI\u914D\u7F6E\u76F8\u5173\uFF0C\u4F8B\u5982\u5BF9k8s\uFF0Cdocker\u7684\u914D\u7F6E\u6587\u4EF6\u7684\u4FEE\u6539"],["chore","\u6539\u53D8\u6784\u5EFA\u6D41\u7A0B\u3001\u6216\u8005\u589E\u52A0\u4F9D\u8D56\u5E93\u3001\u5DE5\u5177\u7B49"],["revert","\u56DE\u6EDA\u5230\u4E0A\u4E00\u4E2A\u7248\u672C"]],gitCommitScopes:[["projects","\u9879\u76EE\u642D\u5EFA"],["components","\u7EC4\u4EF6\u76F8\u5173"],["hooks","hook \u76F8\u5173"],["utils","utils \u76F8\u5173"],["types","ts\u7C7B\u578B\u76F8\u5173"],["styles","\u6837\u5F0F\u76F8\u5173"],["deps","\u9879\u76EE\u4F9D\u8D56"],["auth","\u5BF9 auth \u4FEE\u6539"],["release","\u7248\u672C\u53D1\u5E03"],["other","\u5176\u4ED6\u4FEE\u6539"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${d}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[d]:"eslint --fix","*":"soy prettier-write"}},M="U2FsdGVkX1+vLW5S5+vcx+LKGSR2PtJOAZUZsVCTKM0+ecI3hDuARJn6kdLzzR1LVl0179NmgMoX6fV28TMu3A==";async function I(u,t=process.cwd()){const{config:e}=await b({name:"soybean",defaults:T,overrides:u,cwd:t,packageJson:!0}),i=await V(t);if(e&&i){const o=new O("SOYBEAN_JS");e.changelogOptions={...e.changelogOptions,github:{repo:"",token:o.deCrypto(M)||""}}}return e}async function V(u){let t=!1;const e="soybean";try{const i=await v(`${u}/package.json`,"utf-8"),o=JSON.parse(i);t=o.name?.includes(e)||o.repository?.url?.includes(e)||o.author?.includes(e)||o.author?.name?.includes(e)||o.author?.url?.includes(e)}catch{}return t}async function W(){const u=await I(),t=C("soybean");t.version(j).option("--total","Generate changelog by total tags").help();const e={"git-commit":{desc:"\u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684\u63D0\u4EA4\u4FE1\u606F",action:async()=>{await $(u.gitCommitTypes,u.gitCommitScopes)}},"git-commit-verify":{desc:"\u6821\u9A8C git \u63D0\u4EA4\u4FE1\u606F\u662F\u5426\u7B26\u5408 Conventional Commits \u89C4\u8303",action:async()=>{await G()}},cleanup:{desc:"\u6E05\u7A7A\u4F9D\u8D56\u548C\u6784\u5EFA\u4EA7\u7269",action:async()=>{await _(u.cleanupDirs)}},"init-simple-git-hooks":{desc:"\u521D\u59CB\u5316 simple-git-hooks \u94A9\u5B50",action:async()=>{await m(u.cwd)}},ncu:{desc:"\u547D\u4EE4 npm-check-updates, \u5347\u7EA7\u4F9D\u8D56",action:async()=>{await E(u.ncuCommandArgs)}},"prettier-write":{desc:"\u6267\u884C prettier --write \u683C\u5F0F\u5316",action:async()=>{await l(u.prettierWriteGlob)}},"lint-staged":{desc:"\u6267\u884Clint-staged",action:async()=>{const i=await L(u.lintStagedConfig).catch(()=>{process.exitCode=1});process.exitCode=i?0:1}},changelog:{desc:"\u751F\u6210changelog",action:async i=>{await N(u.changelogOptions,i?.total)}},release:{desc:"\u53D1\u5E03\uFF1A\u66F4\u65B0\u7248\u672C\u53F7\u3001\u751F\u6210changelog\u3001\u63D0\u4EA4\u4EE3\u7801",action:async()=>{await R()}},"init-git-hooks":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 init-simple-git-hooks",action:async()=>{await m(u.cwd)}},"update-pkg":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 ncu",action:async()=>{await E(u.ncuCommandArgs)}},"prettier-format":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528 prettier-write",action:async()=>{await l(u.prettierWriteGlob)}},"eslint-prettier":{desc:"\u8BE5\u547D\u4EE4\u5DF2\u5E9F\u5F03",action:async()=>{await J()}}};for await(const[i,{desc:o,action:a}]of Object.entries(e))t.command(i,o).action(a);t.parse()}W();function z(u){return u}export{z as defineConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "SoybeanJS's command line tools",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Soybean",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"c12": "1.4.2",
|
|
42
42
|
"cac": "6.7.14",
|
|
43
43
|
"consola": "3.2.3",
|
|
44
|
+
"crypto-js": "^4.1.1",
|
|
44
45
|
"enquirer": "2.4.1",
|
|
45
46
|
"execa": "8.0.1",
|
|
46
47
|
"kolorist": "1.8.0",
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@soybeanjs/cli": "link:",
|
|
55
|
+
"@types/crypto-js": "^4.1.1",
|
|
54
56
|
"@types/node": "20.5.2",
|
|
55
57
|
"eslint": "8.47.0",
|
|
56
58
|
"eslint-config-soybeanjs": "0.5.5",
|