@soybeanjs/cli 1.7.1 → 1.7.3
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.d.ts +1 -2
- package/dist/index.js +105 -55
- package/package.json +21 -31
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ChangelogOption } from "@soybeanjs/changelog";
|
|
2
|
-
|
|
3
2
|
//#region src/types/index.d.ts
|
|
4
3
|
interface CliOption {
|
|
5
4
|
/** The project root directory */
|
|
@@ -18,7 +17,7 @@ interface CliOption {
|
|
|
18
17
|
/**
|
|
19
18
|
* Npm-check-updates command args
|
|
20
19
|
*
|
|
21
|
-
*
|
|
20
|
+
* If not set, soybean-cli will resolve workspace package.json files automatically and fall back to package.json in single-package repos.
|
|
22
21
|
*/
|
|
23
22
|
ncuCommandArgs: string[];
|
|
24
23
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,61 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cac } from "cac";
|
|
3
|
-
import
|
|
3
|
+
import process$1 from "node:process";
|
|
4
|
+
import { loadConfig } from "c12";
|
|
4
5
|
import { readFileSync } from "node:fs";
|
|
6
|
+
import path, { join, posix } from "node:path";
|
|
5
7
|
import enquirer from "enquirer";
|
|
6
8
|
import { bgRed, green, red, yellow } from "kolorist";
|
|
7
9
|
import { rimraf } from "rimraf";
|
|
8
|
-
import {
|
|
10
|
+
import { readFile } from "node:fs/promises";
|
|
11
|
+
import { glob } from "tinyglobby";
|
|
9
12
|
import { existsSync } from "fs";
|
|
13
|
+
import { join as join$1 } from "path";
|
|
10
14
|
import { generateChangelog, generateTotalChangelog } from "@soybeanjs/changelog";
|
|
11
15
|
import { versionBump } from "bumpp";
|
|
12
|
-
import process$1 from "node:process";
|
|
13
|
-
import { loadConfig } from "c12";
|
|
14
|
-
|
|
15
16
|
//#region package.json
|
|
16
|
-
var version = "1.7.
|
|
17
|
-
|
|
17
|
+
var version = "1.7.3";
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/config/index.ts
|
|
20
|
+
const defaultOptions = {
|
|
21
|
+
cwd: process$1.cwd(),
|
|
22
|
+
cleanupDirs: [
|
|
23
|
+
"**/dist",
|
|
24
|
+
"**/package-lock.json",
|
|
25
|
+
"**/yarn.lock",
|
|
26
|
+
"**/pnpm-lock.yaml",
|
|
27
|
+
"**/node_modules",
|
|
28
|
+
"!node_modules/**"
|
|
29
|
+
],
|
|
30
|
+
ncuCommandArgs: [],
|
|
31
|
+
changelogOptions: {},
|
|
32
|
+
gitCommitVerifyIgnores: [
|
|
33
|
+
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m,
|
|
34
|
+
/^(Merge tag (.*?))(?:\r?\n)*$/m,
|
|
35
|
+
/^(R|r)evert (.*)/,
|
|
36
|
+
/^(amend|fixup|squash)!/,
|
|
37
|
+
/^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))/,
|
|
38
|
+
/^Merge remote-tracking branch(\s*)(.*)/,
|
|
39
|
+
/^Automatic merge(.*)/,
|
|
40
|
+
/^Auto-merged (.*?) into (.*)/
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
async function loadCliOptions(overrides, cwd = process$1.cwd()) {
|
|
44
|
+
const { config } = await loadConfig({
|
|
45
|
+
name: "soybean",
|
|
46
|
+
defaults: defaultOptions,
|
|
47
|
+
overrides,
|
|
48
|
+
cwd,
|
|
49
|
+
packageJson: true
|
|
50
|
+
});
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
18
53
|
//#endregion
|
|
19
54
|
//#region src/shared/index.ts
|
|
20
55
|
async function execCommand(cmd, args, options) {
|
|
21
56
|
const { execa } = await import("execa");
|
|
22
57
|
return ((await execa(cmd, args, options))?.stdout)?.trim() || "";
|
|
23
58
|
}
|
|
24
|
-
|
|
25
59
|
//#endregion
|
|
26
60
|
//#region src/locales/index.ts
|
|
27
61
|
const locales = {
|
|
@@ -94,7 +128,6 @@ const locales = {
|
|
|
94
128
|
gitCommitVerify: `${bgRed(" ERROR ")} ${red("git commit message must match the Conventional Commits standard!")}\n\n${green("Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org")}`
|
|
95
129
|
}
|
|
96
130
|
};
|
|
97
|
-
|
|
98
131
|
//#endregion
|
|
99
132
|
//#region src/command/git-commit.ts
|
|
100
133
|
/**
|
|
@@ -151,28 +184,83 @@ async function gitCommitVerify(lang = "en-us", ignores = []) {
|
|
|
151
184
|
throw new Error(errorMsg);
|
|
152
185
|
}
|
|
153
186
|
}
|
|
154
|
-
|
|
155
187
|
//#endregion
|
|
156
188
|
//#region src/command/cleanup.ts
|
|
157
189
|
async function cleanup(paths) {
|
|
158
190
|
await rimraf(paths, { glob: true });
|
|
159
191
|
}
|
|
160
|
-
|
|
161
192
|
//#endregion
|
|
162
193
|
//#region src/command/ncu.ts
|
|
163
|
-
async function ncu(args = [
|
|
164
|
-
await execCommand("pnpm", ["npm-check-updates", ...args], { stdio: "inherit" });
|
|
194
|
+
async function ncu(args = []) {
|
|
195
|
+
await execCommand("pnpm", ["npm-check-updates", ...args.length ? args : await resolveDefaultNcuArgs()], { stdio: "inherit" });
|
|
196
|
+
}
|
|
197
|
+
function parsePnpmWorkspacePackages(content) {
|
|
198
|
+
const lines = content.split(/\r?\n/u);
|
|
199
|
+
const packages = [];
|
|
200
|
+
let inPackages = false;
|
|
201
|
+
for (const line of lines) {
|
|
202
|
+
const trimmedLine = line.trim();
|
|
203
|
+
if (!inPackages) {
|
|
204
|
+
if (trimmedLine === "packages:") inPackages = true;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) continue;
|
|
208
|
+
if (/^\S/u.test(line)) break;
|
|
209
|
+
const match = line.match(/^\s*-\s*['"]?(.+?)['"]?\s*$/u);
|
|
210
|
+
if (match?.[1]) packages.push(match[1]);
|
|
211
|
+
}
|
|
212
|
+
return packages;
|
|
213
|
+
}
|
|
214
|
+
function resolveWorkspacePatterns(packageJson, pnpmWorkspaceContent) {
|
|
215
|
+
const workspaces = Array.isArray(packageJson?.workspaces) ? packageJson.workspaces : packageJson?.workspaces?.packages ?? [];
|
|
216
|
+
const pnpmWorkspacePackages = pnpmWorkspaceContent ? parsePnpmWorkspacePackages(pnpmWorkspaceContent) : [];
|
|
217
|
+
return [.../* @__PURE__ */ new Set([...workspaces, ...pnpmWorkspacePackages])];
|
|
218
|
+
}
|
|
219
|
+
function toPackageFilePattern(pattern) {
|
|
220
|
+
const normalizedPattern = pattern.trim();
|
|
221
|
+
if (!normalizedPattern) return "";
|
|
222
|
+
const isNegated = normalizedPattern.startsWith("!");
|
|
223
|
+
const cleanPattern = (isNegated ? normalizedPattern.slice(1) : normalizedPattern).replace(/\/$/u, "");
|
|
224
|
+
const packageFilePattern = cleanPattern.endsWith("package.json") ? cleanPattern : posix.join(cleanPattern, "package.json");
|
|
225
|
+
return isNegated ? `!${packageFilePattern}` : packageFilePattern;
|
|
226
|
+
}
|
|
227
|
+
async function resolveDefaultNcuArgs(cwd = process$1.cwd()) {
|
|
228
|
+
const [packageJsonContent, pnpmWorkspaceContent] = await Promise.all([readFile(join(cwd, "package.json"), "utf8").catch(() => null), readFile(join(cwd, "pnpm-workspace.yaml"), "utf8").catch(() => null)]);
|
|
229
|
+
const workspacePatterns = resolveWorkspacePatterns(packageJsonContent ? JSON.parse(packageJsonContent) : null, pnpmWorkspaceContent).map(toPackageFilePattern).filter(Boolean);
|
|
230
|
+
if (!workspacePatterns.length) return [
|
|
231
|
+
"-u",
|
|
232
|
+
"--packageFile",
|
|
233
|
+
"package.json"
|
|
234
|
+
];
|
|
235
|
+
const packageFiles = await glob(["package.json", ...workspacePatterns], {
|
|
236
|
+
cwd,
|
|
237
|
+
followSymbolicLinks: false,
|
|
238
|
+
onlyFiles: true
|
|
239
|
+
});
|
|
240
|
+
const uniquePackageFiles = [...new Set(packageFiles)].sort((left, right) => {
|
|
241
|
+
if (left === "package.json") return -1;
|
|
242
|
+
if (right === "package.json") return 1;
|
|
243
|
+
return left.localeCompare(right);
|
|
244
|
+
});
|
|
245
|
+
if (!uniquePackageFiles.length) return [
|
|
246
|
+
"-u",
|
|
247
|
+
"--packageFile",
|
|
248
|
+
"package.json"
|
|
249
|
+
];
|
|
250
|
+
return [
|
|
251
|
+
"-u",
|
|
252
|
+
"--packageFile",
|
|
253
|
+
`{${uniquePackageFiles.join(",")}}`
|
|
254
|
+
];
|
|
165
255
|
}
|
|
166
|
-
|
|
167
256
|
//#endregion
|
|
168
257
|
//#region src/command/changelog.ts
|
|
169
258
|
async function genChangelog(options, total = false) {
|
|
170
|
-
const hasChangelog = existsSync(join(process.cwd(), "CHANGELOG.md"));
|
|
259
|
+
const hasChangelog = existsSync(join$1(process.cwd(), "CHANGELOG.md"));
|
|
171
260
|
if (total) await generateTotalChangelog(options);
|
|
172
261
|
else await generateChangelog(options);
|
|
173
262
|
if (!hasChangelog) await execCommand("git", ["add", "CHANGELOG.md"]);
|
|
174
263
|
}
|
|
175
|
-
|
|
176
264
|
//#endregion
|
|
177
265
|
//#region src/command/release.ts
|
|
178
266
|
async function release(execute = "pnpm soy changelog", push = true) {
|
|
@@ -185,43 +273,6 @@ async function release(execute = "pnpm soy changelog", push = true) {
|
|
|
185
273
|
push
|
|
186
274
|
});
|
|
187
275
|
}
|
|
188
|
-
|
|
189
|
-
//#endregion
|
|
190
|
-
//#region src/config/index.ts
|
|
191
|
-
const defaultOptions = {
|
|
192
|
-
cwd: process$1.cwd(),
|
|
193
|
-
cleanupDirs: [
|
|
194
|
-
"**/dist",
|
|
195
|
-
"**/package-lock.json",
|
|
196
|
-
"**/yarn.lock",
|
|
197
|
-
"**/pnpm-lock.yaml",
|
|
198
|
-
"**/node_modules",
|
|
199
|
-
"!node_modules/**"
|
|
200
|
-
],
|
|
201
|
-
ncuCommandArgs: ["--deep", "-u"],
|
|
202
|
-
changelogOptions: {},
|
|
203
|
-
gitCommitVerifyIgnores: [
|
|
204
|
-
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m,
|
|
205
|
-
/^(Merge tag (.*?))(?:\r?\n)*$/m,
|
|
206
|
-
/^(R|r)evert (.*)/,
|
|
207
|
-
/^(amend|fixup|squash)!/,
|
|
208
|
-
/^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))/,
|
|
209
|
-
/^Merge remote-tracking branch(\s*)(.*)/,
|
|
210
|
-
/^Automatic merge(.*)/,
|
|
211
|
-
/^Auto-merged (.*?) into (.*)/
|
|
212
|
-
]
|
|
213
|
-
};
|
|
214
|
-
async function loadCliOptions(overrides, cwd = process$1.cwd()) {
|
|
215
|
-
const { config } = await loadConfig({
|
|
216
|
-
name: "soybean",
|
|
217
|
-
defaults: defaultOptions,
|
|
218
|
-
overrides,
|
|
219
|
-
cwd,
|
|
220
|
-
packageJson: true
|
|
221
|
-
});
|
|
222
|
-
return config;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
276
|
//#endregion
|
|
226
277
|
//#region src/index.ts
|
|
227
278
|
async function setupCli() {
|
|
@@ -284,6 +335,5 @@ setupCli();
|
|
|
284
335
|
function defineConfig(config) {
|
|
285
336
|
return config;
|
|
286
337
|
}
|
|
287
|
-
|
|
288
338
|
//#endregion
|
|
289
|
-
export { defineConfig };
|
|
339
|
+
export { defineConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "SoybeanJS's command line tools",
|
|
5
5
|
"homepage": "https://github.com/soybeanjs/cli",
|
|
6
6
|
"bugs": {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"url": "https://github.com/soybeanjs/cli.git"
|
|
17
17
|
},
|
|
18
18
|
"bin": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"soy": "dist/index.js",
|
|
20
|
+
"soybean": "dist/index.js"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
@@ -37,48 +37,38 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@soybeanjs/changelog": "^0.4.
|
|
41
|
-
"bumpp": "^
|
|
42
|
-
"c12": "^3.3.
|
|
40
|
+
"@soybeanjs/changelog": "^0.4.7",
|
|
41
|
+
"bumpp": "^12.0.0",
|
|
42
|
+
"c12": "^3.3.4",
|
|
43
43
|
"cac": "^7.0.0",
|
|
44
44
|
"consola": "^3.4.2",
|
|
45
45
|
"enquirer": "^2.4.1",
|
|
46
|
-
"execa": "^
|
|
46
|
+
"execa": "^10.0.0",
|
|
47
47
|
"kolorist": "^1.8.0",
|
|
48
|
-
"npm-check-updates": "^
|
|
48
|
+
"npm-check-updates": "^22.2.9",
|
|
49
49
|
"rimraf": "^6.1.3",
|
|
50
|
-
"tinyglobby": "^0.2.
|
|
50
|
+
"tinyglobby": "^0.2.17"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@soybeanjs/cli": "link:",
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
56
|
-
"oxfmt": "^0.
|
|
57
|
-
"oxlint": "^1.
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
},
|
|
63
|
-
"simple-git-hooks": {
|
|
64
|
-
"commit-msg": "pnpm soy git-commit-verify",
|
|
65
|
-
"pre-commit": "pnpm typecheck && pnpm lint-staged"
|
|
66
|
-
},
|
|
67
|
-
"lint-staged": {
|
|
68
|
-
"*": "oxlint --fix && oxfmt"
|
|
54
|
+
"@soybeanjs/oxc-config": "^0.2.3",
|
|
55
|
+
"@types/node": "^26.1.1",
|
|
56
|
+
"oxfmt": "^0.60.0",
|
|
57
|
+
"oxlint": "^1.75.0",
|
|
58
|
+
"tsdown": "^0.22.14",
|
|
59
|
+
"tsx": "^4.23.1",
|
|
60
|
+
"typescript": "^7.0.2",
|
|
61
|
+
"vite-plus": "0.2.6"
|
|
69
62
|
},
|
|
70
63
|
"scripts": {
|
|
71
|
-
"build": "
|
|
72
|
-
"cleanup": "soy cleanup",
|
|
64
|
+
"build": "vp pack",
|
|
73
65
|
"commit": "soy git-commit",
|
|
74
66
|
"commit:zh": "soy git-commit -l=zh-cn",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
67
|
+
"fmt": "vp fmt",
|
|
68
|
+
"lint": "vp lint",
|
|
77
69
|
"publish-pkg": "pnpm -r publish --access public",
|
|
78
70
|
"release": "soy release",
|
|
79
|
-
"stub": "pnpm -r run stub",
|
|
80
71
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
81
|
-
"upkg": "soy ncu"
|
|
82
|
-
"rei": "pnpm cleanup && pnpm i"
|
|
72
|
+
"upkg": "soy ncu"
|
|
83
73
|
}
|
|
84
74
|
}
|