@soybeanjs/cli 1.0.0-beta.7 → 1.0.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/dist/index.cjs +279 -2
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +247 -0
- package/package.json +11 -12
- package/dist/index.d.mts +0 -37
- package/dist/index.mjs +0 -4
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,281 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
3
30
|
|
|
4
|
-
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
defineConfig: () => defineConfig
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var import_cac = __toESM(require("cac"), 1);
|
|
38
|
+
|
|
39
|
+
// package.json
|
|
40
|
+
var version = "1.0.0";
|
|
41
|
+
|
|
42
|
+
// src/command/git-commit.ts
|
|
43
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
44
|
+
var import_node_fs = require("fs");
|
|
45
|
+
var import_enquirer = __toESM(require("enquirer"), 1);
|
|
46
|
+
var import_kolorist = require("kolorist");
|
|
47
|
+
|
|
48
|
+
// src/shared/index.ts
|
|
49
|
+
async function execCommand(cmd, args, options) {
|
|
50
|
+
const { execa } = await import("execa");
|
|
51
|
+
const res = await execa(cmd, args, options);
|
|
52
|
+
return res?.stdout?.trim() || "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/command/git-commit.ts
|
|
56
|
+
async function gitCommit(gitCommitTypes, gitCommitScopes) {
|
|
57
|
+
const typesChoices = gitCommitTypes.map(([name, title]) => {
|
|
58
|
+
const nameWithSuffix = `${name}:`;
|
|
59
|
+
const message = `${nameWithSuffix.padEnd(12)}${title}`;
|
|
60
|
+
return {
|
|
61
|
+
name,
|
|
62
|
+
message
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
const scopesChoices = gitCommitScopes.map(([name, title]) => ({
|
|
66
|
+
name,
|
|
67
|
+
message: `${name.padEnd(30)} (${title})`
|
|
68
|
+
}));
|
|
69
|
+
const result = await import_enquirer.default.prompt([
|
|
70
|
+
{
|
|
71
|
+
name: "types",
|
|
72
|
+
type: "select",
|
|
73
|
+
message: "Please select a type",
|
|
74
|
+
choices: typesChoices
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "scopes",
|
|
78
|
+
type: "select",
|
|
79
|
+
message: "Please select a scope",
|
|
80
|
+
choices: scopesChoices
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "description",
|
|
84
|
+
type: "text",
|
|
85
|
+
message: "Please enter a description"
|
|
86
|
+
}
|
|
87
|
+
]);
|
|
88
|
+
const commitMsg = `${result.types}(${result.scopes}): ${result.description}`;
|
|
89
|
+
await execCommand("git", ["commit", "-m", commitMsg], { stdio: "inherit" });
|
|
90
|
+
}
|
|
91
|
+
async function gitCommitVerify() {
|
|
92
|
+
const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
|
|
93
|
+
const gitMsgPath = import_node_path.default.join(gitPath, ".git", "COMMIT_EDITMSG");
|
|
94
|
+
const commitMsg = (0, import_node_fs.readFileSync)(gitMsgPath, "utf8").trim();
|
|
95
|
+
const REG_EXP = /(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
|
|
96
|
+
if (!REG_EXP.test(commitMsg)) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`${(0, import_kolorist.bgRed)(" ERROR ")} ${(0, import_kolorist.red)("git commit message must match the Conventional Commits standard!")}
|
|
99
|
+
|
|
100
|
+
${(0, import_kolorist.green)(
|
|
101
|
+
"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"
|
|
102
|
+
)}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/command/cleanup.ts
|
|
108
|
+
var import_rimraf = require("rimraf");
|
|
109
|
+
async function cleanup(paths) {
|
|
110
|
+
await (0, import_rimraf.rimraf)(paths, { glob: true });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/command/ncu.ts
|
|
114
|
+
async function ncu(args = ["--deep", "-u"]) {
|
|
115
|
+
execCommand("npx", ["ncu", ...args], { stdio: "inherit" });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/command/changelog.ts
|
|
119
|
+
var import_changelog = require("@soybeanjs/changelog");
|
|
120
|
+
async function genChangelog(options, total = false) {
|
|
121
|
+
if (total) {
|
|
122
|
+
await (0, import_changelog.generateTotalChangelog)(options);
|
|
123
|
+
} else {
|
|
124
|
+
await (0, import_changelog.generateChangelog)(options);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/command/release.ts
|
|
129
|
+
var import_bumpp = require("bumpp");
|
|
130
|
+
async function release(execute = "npx soy changelog", push = true) {
|
|
131
|
+
await (0, import_bumpp.versionBump)({
|
|
132
|
+
files: ["**/package.json", "!**/node_modules"],
|
|
133
|
+
execute,
|
|
134
|
+
all: true,
|
|
135
|
+
tag: true,
|
|
136
|
+
commit: "chore(projects): release v%s",
|
|
137
|
+
push
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/config/index.ts
|
|
142
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
143
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
144
|
+
var import_promises = require("fs/promises");
|
|
145
|
+
var import_node_buffer = require("buffer");
|
|
146
|
+
var import_c12 = require("c12");
|
|
147
|
+
var defaultOptions = {
|
|
148
|
+
cwd: import_node_process.default.cwd(),
|
|
149
|
+
cleanupDirs: [
|
|
150
|
+
"**/dist",
|
|
151
|
+
"**/package-lock.json",
|
|
152
|
+
"**/yarn.lock",
|
|
153
|
+
"**/pnpm-lock.yaml",
|
|
154
|
+
"**/node_modules",
|
|
155
|
+
"!node_modules/**"
|
|
156
|
+
],
|
|
157
|
+
gitCommitTypes: [
|
|
158
|
+
["feat", "A new feature"],
|
|
159
|
+
["fix", "A bug fix"],
|
|
160
|
+
["docs", "Documentation only changes"],
|
|
161
|
+
["style", "Changes that do not affect the meaning of the code"],
|
|
162
|
+
["refactor", "A code change that neither fixes a bug nor adds a feature"],
|
|
163
|
+
["perf", "A code change that improves performance"],
|
|
164
|
+
["test", "Adding missing tests or correcting existing tests"],
|
|
165
|
+
["build", "Changes that affect the build system or external dependencies"],
|
|
166
|
+
["ci", "Changes to our CI configuration files and scripts"],
|
|
167
|
+
["chore", "Other changes that don't modify src or test files"],
|
|
168
|
+
["revert", "Reverts a previous commit"]
|
|
169
|
+
],
|
|
170
|
+
gitCommitScopes: [
|
|
171
|
+
["projects", "project"],
|
|
172
|
+
["components", "components"],
|
|
173
|
+
["hooks", "hook functions"],
|
|
174
|
+
["utils", "utils functions"],
|
|
175
|
+
["types", "TS declaration"],
|
|
176
|
+
["styles", "style"],
|
|
177
|
+
["deps", "project dependencies"],
|
|
178
|
+
["release", "release project"],
|
|
179
|
+
["other", "other changes"]
|
|
180
|
+
],
|
|
181
|
+
ncuCommandArgs: ["--deep", "-u"],
|
|
182
|
+
changelogOptions: {}
|
|
183
|
+
};
|
|
184
|
+
async function loadCliOptions(overrides, cwd = import_node_process.default.cwd()) {
|
|
185
|
+
const { config } = await (0, import_c12.loadConfig)({
|
|
186
|
+
name: "soybean",
|
|
187
|
+
defaults: defaultOptions,
|
|
188
|
+
overrides,
|
|
189
|
+
cwd,
|
|
190
|
+
packageJson: true
|
|
191
|
+
});
|
|
192
|
+
const has = await hasSoybeanInfoFromPkgJson(cwd);
|
|
193
|
+
if (config && has) {
|
|
194
|
+
const SOYBEAN_GT = "Z2hwX3k3TTlSZTlBQUd5TWJtSkgyNDBkNDJPc01rYUc1ZDFFcWJSdw==";
|
|
195
|
+
const token = import_node_buffer.Buffer.from(SOYBEAN_GT, "base64").toString();
|
|
196
|
+
config.changelogOptions = {
|
|
197
|
+
...config.changelogOptions,
|
|
198
|
+
github: { repo: "", token }
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return config;
|
|
202
|
+
}
|
|
203
|
+
async function hasSoybeanInfoFromPkgJson(cwd) {
|
|
204
|
+
let hasSoybeanInfo = false;
|
|
205
|
+
const REG = "soybean";
|
|
206
|
+
try {
|
|
207
|
+
const pkgJson = await (0, import_promises.readFile)(import_node_path2.default.join(cwd, "package.json"), "utf-8");
|
|
208
|
+
const pkg = JSON.parse(pkgJson);
|
|
209
|
+
hasSoybeanInfo = pkg.name?.includes(REG) || pkg.repository?.url?.includes(REG) || pkg.author?.includes(REG) || pkg.author?.name?.includes(REG) || pkg.author?.url?.includes(REG);
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
return hasSoybeanInfo;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/index.ts
|
|
216
|
+
async function setupCli() {
|
|
217
|
+
const cliOptions = await loadCliOptions();
|
|
218
|
+
const cli = (0, import_cac.default)("soybean");
|
|
219
|
+
cli.version(version).option(
|
|
220
|
+
"-e, --execute [command]",
|
|
221
|
+
"Execute additional command after bumping and before git commit. Defaults to 'npx soy changelog'"
|
|
222
|
+
).option("-p, --push", "Indicates whether to push the git commit and tag").option("-t, --total", "Generate changelog by total tags").option(
|
|
223
|
+
"-c, --cleanupDir <dir>",
|
|
224
|
+
'The glob pattern of dirs to cleanup, If not set, it will use the default value, Multiple values use "," to separate them'
|
|
225
|
+
).help();
|
|
226
|
+
const commands = {
|
|
227
|
+
cleanup: {
|
|
228
|
+
desc: "delete dirs: node_modules, dist, etc.",
|
|
229
|
+
action: async (args) => {
|
|
230
|
+
const cleanupDirs = args?.cleanupDir?.split(",") || [];
|
|
231
|
+
const formattedDirs = cleanupDirs.map((dir) => dir.trim()).filter(Boolean);
|
|
232
|
+
if (formattedDirs.length) {
|
|
233
|
+
cliOptions.cleanupDirs = formattedDirs;
|
|
234
|
+
}
|
|
235
|
+
await cleanup(cliOptions.cleanupDirs);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
ncu: {
|
|
239
|
+
desc: "npm-check-updates, it can update package.json dependencies to the latest version",
|
|
240
|
+
action: async () => {
|
|
241
|
+
await ncu(cliOptions.ncuCommandArgs);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"git-commit": {
|
|
245
|
+
desc: "git commit, generate commit message which match Conventional Commits standard",
|
|
246
|
+
action: async () => {
|
|
247
|
+
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
"git-commit-verify": {
|
|
251
|
+
desc: "verify git commit message, make sure it match Conventional Commits standard",
|
|
252
|
+
action: async () => {
|
|
253
|
+
await gitCommitVerify();
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
changelog: {
|
|
257
|
+
desc: "generate changelog",
|
|
258
|
+
action: async (args) => {
|
|
259
|
+
await genChangelog(cliOptions.changelogOptions, args?.total);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
release: {
|
|
263
|
+
desc: "release: update version, generate changelog, commit code",
|
|
264
|
+
action: async (args) => {
|
|
265
|
+
await release(args?.execute, args?.push);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
270
|
+
cli.command(command, desc).action(action);
|
|
271
|
+
}
|
|
272
|
+
cli.parse();
|
|
273
|
+
}
|
|
274
|
+
setupCli();
|
|
275
|
+
function defineConfig(config) {
|
|
276
|
+
return config;
|
|
277
|
+
}
|
|
278
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
279
|
+
0 && (module.exports = {
|
|
280
|
+
defineConfig
|
|
281
|
+
});
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import cac from "cac";
|
|
5
|
+
|
|
6
|
+
// package.json
|
|
7
|
+
var version = "1.0.0";
|
|
8
|
+
|
|
9
|
+
// src/command/git-commit.ts
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import enquirer from "enquirer";
|
|
13
|
+
import { bgRed, green, red } from "kolorist";
|
|
14
|
+
|
|
15
|
+
// src/shared/index.ts
|
|
16
|
+
async function execCommand(cmd, args, options) {
|
|
17
|
+
const { execa } = await import("execa");
|
|
18
|
+
const res = await execa(cmd, args, options);
|
|
19
|
+
return res?.stdout?.trim() || "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/command/git-commit.ts
|
|
23
|
+
async function gitCommit(gitCommitTypes, gitCommitScopes) {
|
|
24
|
+
const typesChoices = gitCommitTypes.map(([name, title]) => {
|
|
25
|
+
const nameWithSuffix = `${name}:`;
|
|
26
|
+
const message = `${nameWithSuffix.padEnd(12)}${title}`;
|
|
27
|
+
return {
|
|
28
|
+
name,
|
|
29
|
+
message
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
const scopesChoices = gitCommitScopes.map(([name, title]) => ({
|
|
33
|
+
name,
|
|
34
|
+
message: `${name.padEnd(30)} (${title})`
|
|
35
|
+
}));
|
|
36
|
+
const result = await enquirer.prompt([
|
|
37
|
+
{
|
|
38
|
+
name: "types",
|
|
39
|
+
type: "select",
|
|
40
|
+
message: "Please select a type",
|
|
41
|
+
choices: typesChoices
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "scopes",
|
|
45
|
+
type: "select",
|
|
46
|
+
message: "Please select a scope",
|
|
47
|
+
choices: scopesChoices
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "description",
|
|
51
|
+
type: "text",
|
|
52
|
+
message: "Please enter a description"
|
|
53
|
+
}
|
|
54
|
+
]);
|
|
55
|
+
const commitMsg = `${result.types}(${result.scopes}): ${result.description}`;
|
|
56
|
+
await execCommand("git", ["commit", "-m", commitMsg], { stdio: "inherit" });
|
|
57
|
+
}
|
|
58
|
+
async function gitCommitVerify() {
|
|
59
|
+
const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
|
|
60
|
+
const gitMsgPath = path.join(gitPath, ".git", "COMMIT_EDITMSG");
|
|
61
|
+
const commitMsg = readFileSync(gitMsgPath, "utf8").trim();
|
|
62
|
+
const REG_EXP = /(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
|
|
63
|
+
if (!REG_EXP.test(commitMsg)) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`${bgRed(" ERROR ")} ${red("git commit message must match the Conventional Commits standard!")}
|
|
66
|
+
|
|
67
|
+
${green(
|
|
68
|
+
"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"
|
|
69
|
+
)}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/command/cleanup.ts
|
|
75
|
+
import { rimraf } from "rimraf";
|
|
76
|
+
async function cleanup(paths) {
|
|
77
|
+
await rimraf(paths, { glob: true });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/command/ncu.ts
|
|
81
|
+
async function ncu(args = ["--deep", "-u"]) {
|
|
82
|
+
execCommand("npx", ["ncu", ...args], { stdio: "inherit" });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/command/changelog.ts
|
|
86
|
+
import { generateChangelog, generateTotalChangelog } from "@soybeanjs/changelog";
|
|
87
|
+
async function genChangelog(options, total = false) {
|
|
88
|
+
if (total) {
|
|
89
|
+
await generateTotalChangelog(options);
|
|
90
|
+
} else {
|
|
91
|
+
await generateChangelog(options);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/command/release.ts
|
|
96
|
+
import { versionBump } from "bumpp";
|
|
97
|
+
async function release(execute = "npx soy changelog", push = true) {
|
|
98
|
+
await versionBump({
|
|
99
|
+
files: ["**/package.json", "!**/node_modules"],
|
|
100
|
+
execute,
|
|
101
|
+
all: true,
|
|
102
|
+
tag: true,
|
|
103
|
+
commit: "chore(projects): release v%s",
|
|
104
|
+
push
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/config/index.ts
|
|
109
|
+
import process from "node:process";
|
|
110
|
+
import path2 from "node:path";
|
|
111
|
+
import { readFile } from "node:fs/promises";
|
|
112
|
+
import { Buffer } from "node:buffer";
|
|
113
|
+
import { loadConfig } from "c12";
|
|
114
|
+
var defaultOptions = {
|
|
115
|
+
cwd: process.cwd(),
|
|
116
|
+
cleanupDirs: [
|
|
117
|
+
"**/dist",
|
|
118
|
+
"**/package-lock.json",
|
|
119
|
+
"**/yarn.lock",
|
|
120
|
+
"**/pnpm-lock.yaml",
|
|
121
|
+
"**/node_modules",
|
|
122
|
+
"!node_modules/**"
|
|
123
|
+
],
|
|
124
|
+
gitCommitTypes: [
|
|
125
|
+
["feat", "A new feature"],
|
|
126
|
+
["fix", "A bug fix"],
|
|
127
|
+
["docs", "Documentation only changes"],
|
|
128
|
+
["style", "Changes that do not affect the meaning of the code"],
|
|
129
|
+
["refactor", "A code change that neither fixes a bug nor adds a feature"],
|
|
130
|
+
["perf", "A code change that improves performance"],
|
|
131
|
+
["test", "Adding missing tests or correcting existing tests"],
|
|
132
|
+
["build", "Changes that affect the build system or external dependencies"],
|
|
133
|
+
["ci", "Changes to our CI configuration files and scripts"],
|
|
134
|
+
["chore", "Other changes that don't modify src or test files"],
|
|
135
|
+
["revert", "Reverts a previous commit"]
|
|
136
|
+
],
|
|
137
|
+
gitCommitScopes: [
|
|
138
|
+
["projects", "project"],
|
|
139
|
+
["components", "components"],
|
|
140
|
+
["hooks", "hook functions"],
|
|
141
|
+
["utils", "utils functions"],
|
|
142
|
+
["types", "TS declaration"],
|
|
143
|
+
["styles", "style"],
|
|
144
|
+
["deps", "project dependencies"],
|
|
145
|
+
["release", "release project"],
|
|
146
|
+
["other", "other changes"]
|
|
147
|
+
],
|
|
148
|
+
ncuCommandArgs: ["--deep", "-u"],
|
|
149
|
+
changelogOptions: {}
|
|
150
|
+
};
|
|
151
|
+
async function loadCliOptions(overrides, cwd = process.cwd()) {
|
|
152
|
+
const { config } = await loadConfig({
|
|
153
|
+
name: "soybean",
|
|
154
|
+
defaults: defaultOptions,
|
|
155
|
+
overrides,
|
|
156
|
+
cwd,
|
|
157
|
+
packageJson: true
|
|
158
|
+
});
|
|
159
|
+
const has = await hasSoybeanInfoFromPkgJson(cwd);
|
|
160
|
+
if (config && has) {
|
|
161
|
+
const SOYBEAN_GT = "Z2hwX3k3TTlSZTlBQUd5TWJtSkgyNDBkNDJPc01rYUc1ZDFFcWJSdw==";
|
|
162
|
+
const token = Buffer.from(SOYBEAN_GT, "base64").toString();
|
|
163
|
+
config.changelogOptions = {
|
|
164
|
+
...config.changelogOptions,
|
|
165
|
+
github: { repo: "", token }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return config;
|
|
169
|
+
}
|
|
170
|
+
async function hasSoybeanInfoFromPkgJson(cwd) {
|
|
171
|
+
let hasSoybeanInfo = false;
|
|
172
|
+
const REG = "soybean";
|
|
173
|
+
try {
|
|
174
|
+
const pkgJson = await readFile(path2.join(cwd, "package.json"), "utf-8");
|
|
175
|
+
const pkg = JSON.parse(pkgJson);
|
|
176
|
+
hasSoybeanInfo = pkg.name?.includes(REG) || pkg.repository?.url?.includes(REG) || pkg.author?.includes(REG) || pkg.author?.name?.includes(REG) || pkg.author?.url?.includes(REG);
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
return hasSoybeanInfo;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/index.ts
|
|
183
|
+
async function setupCli() {
|
|
184
|
+
const cliOptions = await loadCliOptions();
|
|
185
|
+
const cli = cac("soybean");
|
|
186
|
+
cli.version(version).option(
|
|
187
|
+
"-e, --execute [command]",
|
|
188
|
+
"Execute additional command after bumping and before git commit. Defaults to 'npx soy changelog'"
|
|
189
|
+
).option("-p, --push", "Indicates whether to push the git commit and tag").option("-t, --total", "Generate changelog by total tags").option(
|
|
190
|
+
"-c, --cleanupDir <dir>",
|
|
191
|
+
'The glob pattern of dirs to cleanup, If not set, it will use the default value, Multiple values use "," to separate them'
|
|
192
|
+
).help();
|
|
193
|
+
const commands = {
|
|
194
|
+
cleanup: {
|
|
195
|
+
desc: "delete dirs: node_modules, dist, etc.",
|
|
196
|
+
action: async (args) => {
|
|
197
|
+
const cleanupDirs = args?.cleanupDir?.split(",") || [];
|
|
198
|
+
const formattedDirs = cleanupDirs.map((dir) => dir.trim()).filter(Boolean);
|
|
199
|
+
if (formattedDirs.length) {
|
|
200
|
+
cliOptions.cleanupDirs = formattedDirs;
|
|
201
|
+
}
|
|
202
|
+
await cleanup(cliOptions.cleanupDirs);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
ncu: {
|
|
206
|
+
desc: "npm-check-updates, it can update package.json dependencies to the latest version",
|
|
207
|
+
action: async () => {
|
|
208
|
+
await ncu(cliOptions.ncuCommandArgs);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"git-commit": {
|
|
212
|
+
desc: "git commit, generate commit message which match Conventional Commits standard",
|
|
213
|
+
action: async () => {
|
|
214
|
+
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"git-commit-verify": {
|
|
218
|
+
desc: "verify git commit message, make sure it match Conventional Commits standard",
|
|
219
|
+
action: async () => {
|
|
220
|
+
await gitCommitVerify();
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
changelog: {
|
|
224
|
+
desc: "generate changelog",
|
|
225
|
+
action: async (args) => {
|
|
226
|
+
await genChangelog(cliOptions.changelogOptions, args?.total);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
release: {
|
|
230
|
+
desc: "release: update version, generate changelog, commit code",
|
|
231
|
+
action: async (args) => {
|
|
232
|
+
await release(args?.execute, args?.push);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
for await (const [command, { desc, action }] of Object.entries(commands)) {
|
|
237
|
+
cli.command(command, desc).action(action);
|
|
238
|
+
}
|
|
239
|
+
cli.parse();
|
|
240
|
+
}
|
|
241
|
+
setupCli();
|
|
242
|
+
function defineConfig(config) {
|
|
243
|
+
return config;
|
|
244
|
+
}
|
|
245
|
+
export {
|
|
246
|
+
defineConfig
|
|
247
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0
|
|
5
|
-
"packageManager": "pnpm@8.
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"packageManager": "pnpm@8.13.1",
|
|
6
6
|
"description": "SoybeanJS's command line tools",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Soybean",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"registry": "https://registry.npmjs.org/"
|
|
22
22
|
},
|
|
23
23
|
"bin": {
|
|
24
|
-
"soybean": "dist/index.
|
|
24
|
+
"soybean": "dist/index.js",
|
|
25
25
|
"soy": "dist/index.cjs"
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"main": "dist/index.cjs",
|
|
35
|
-
"module": "dist/index.
|
|
35
|
+
"module": "dist/index.js",
|
|
36
36
|
"types": "dist/index.d.ts",
|
|
37
37
|
"files": [
|
|
38
38
|
"dist"
|
|
@@ -43,26 +43,25 @@
|
|
|
43
43
|
"c12": "1.5.1",
|
|
44
44
|
"cac": "6.7.14",
|
|
45
45
|
"consola": "3.2.3",
|
|
46
|
-
"crypto-js": "4.2.0",
|
|
47
46
|
"enquirer": "2.4.1",
|
|
48
47
|
"execa": "8.0.1",
|
|
49
48
|
"kolorist": "1.8.0",
|
|
50
49
|
"minimist": "1.2.8",
|
|
51
|
-
"npm-check-updates": "16.14.
|
|
50
|
+
"npm-check-updates": "16.14.12",
|
|
52
51
|
"rimraf": "5.0.5"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
54
|
"@soybeanjs/cli": "link:",
|
|
56
|
-
"@soybeanjs/eslint-config": "1.
|
|
55
|
+
"@soybeanjs/eslint-config": "1.1.4",
|
|
57
56
|
"@types/crypto-js": "4.2.1",
|
|
58
|
-
"@types/node": "20.10.
|
|
59
|
-
"eslint": "8.
|
|
57
|
+
"@types/node": "20.10.5",
|
|
58
|
+
"eslint": "8.56.0",
|
|
60
59
|
"eslint-plugin-vue": "9.19.2",
|
|
61
60
|
"lint-staged": "15.2.0",
|
|
62
61
|
"simple-git-hooks": "2.9.0",
|
|
63
|
-
"
|
|
62
|
+
"tsup": "8.0.1",
|
|
63
|
+
"tsx": "4.7.0",
|
|
64
64
|
"typescript": "5.3.3",
|
|
65
|
-
"unbuild": "2.0.0",
|
|
66
65
|
"vue-eslint-parser": "9.3.2"
|
|
67
66
|
},
|
|
68
67
|
"simple-git-hooks": {
|
|
@@ -73,7 +72,7 @@
|
|
|
73
72
|
"*": "eslint --fix"
|
|
74
73
|
},
|
|
75
74
|
"scripts": {
|
|
76
|
-
"build": "
|
|
75
|
+
"build": "tsup && pnpm build-pkg",
|
|
77
76
|
"build-pkg": "pnpm -r --filter='./packages/*' run build",
|
|
78
77
|
"cleanup": "soy cleanup",
|
|
79
78
|
"commit": "soy git-commit",
|
package/dist/index.d.mts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ChangelogOption } from '@soybeanjs/changelog';
|
|
2
|
-
|
|
3
|
-
interface CliOption {
|
|
4
|
-
/** The project root directory */
|
|
5
|
-
cwd: string;
|
|
6
|
-
/**
|
|
7
|
-
* Cleanup dirs
|
|
8
|
-
*
|
|
9
|
-
* Glob pattern syntax {@link https://github.com/isaacs/minimatch}
|
|
10
|
-
*
|
|
11
|
-
* @default
|
|
12
|
-
* ```json
|
|
13
|
-
* ["** /dist", "** /pnpm-lock.yaml", "** /node_modules", "!node_modules/**"]
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
cleanupDirs: string[];
|
|
17
|
-
/** Git commit types */
|
|
18
|
-
gitCommitTypes: [string, string][];
|
|
19
|
-
/** Git commit scopes */
|
|
20
|
-
gitCommitScopes: [string, string][];
|
|
21
|
-
/**
|
|
22
|
-
* Npm-check-updates command args
|
|
23
|
-
*
|
|
24
|
-
* @default ['--deep', '-u']
|
|
25
|
-
*/
|
|
26
|
-
ncuCommandArgs: string[];
|
|
27
|
-
/**
|
|
28
|
-
* Options of generate changelog
|
|
29
|
-
*
|
|
30
|
-
* @link https://github.com/soybeanjs/changelog
|
|
31
|
-
*/
|
|
32
|
-
changelogOptions: Partial<ChangelogOption>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
declare function defineConfig(config?: Partial<CliOption>): Partial<CliOption> | undefined;
|
|
36
|
-
|
|
37
|
-
export { type CliOption, defineConfig };
|
package/dist/index.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import g from"cac";import p from"node:path";import{readFileSync as u}from"node:fs";import f from"enquirer";import{bgRed as h,red as y,green as w}from"kolorist";import{createRequire as C}from"node:module";import{rimraf as v}from"rimraf";import{generateTotalChangelog as b,generateChangelog as x}from"@soybeanjs/changelog";import k from"bumpp";import l from"node:process";import{readFile as j}from"node:fs/promises";import{loadConfig as S}from"c12";const $="1.0.0-beta.7";var O=Object.defineProperty,A=(e,t,o)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,E=(e,t,o)=>(A(e,typeof t!="symbol"?t+"":t,o),o);async function r(e,t,o){const{execa:n}=await import("execa");return(await n(e,t,o))?.stdout?.trim()||""}const D=C(import.meta.url),m=D("crypto-js");class R{constructor(t){E(this,"secret"),this.secret=t}enCrypto(t){const o=JSON.stringify(t);return m.AES.encrypt(o,this.secret).toString()}deCrypto(t){const o=m.AES.decrypt(t,this.secret).toString(m.enc.Utf8);if(o)try{return JSON.parse(o)}catch{return null}return null}}async function T(e,t){const o=e.map(([s,c])=>{const d=`${`${s}:`.padEnd(12)}${c}`;return{name:s,message:d}}),n=t.map(([s,c])=>({name:s,message:`${s.padEnd(30)} (${c})`})),a=await f.prompt([{name:"types",type:"select",message:"Please select a type",choices:o},{name:"scopes",type:"select",message:"Please select a scope",choices:n},{name:"description",type:"text",message:"Please enter a description"}]),i=`${a.types}(${a.scopes}): ${a.description}`;await r("git",["commit","-m",i],{stdio:"inherit"})}async function I(){const e=await r("git",["rev-parse","--show-toplevel"]),t=p.join(e,".git","COMMIT_EDITMSG"),o=u(t,"utf8").trim();if(!/(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(o))throw new Error(`${h(" ERROR ")} ${y("git commit message must match the Conventional Commits standard!")}
|
|
3
|
-
|
|
4
|
-
${w("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")}`)}async function J(e){await v(e,{glob:!0})}async function _(e=["--deep","-u"]){r("npx",["ncu",...e],{stdio:"inherit"})}async function G(e,t=!1){t?await b(e):await x(e)}async function M(e="npx soy changelog",t=!0){await k({files:["**/package.json","!**/node_modules"],execute:e,all:!0,tag:!0,commit:"chore(projects): release v%s",push:t})}const N={cwd:l.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["feat","A new feature"],["fix","A bug fix"],["docs","Documentation only changes"],["style","Changes that do not affect the meaning of the code"],["refactor","A code change that neither fixes a bug nor adds a feature"],["perf","A code change that improves performance"],["test","Adding missing tests or correcting existing tests"],["build","Changes that affect the build system or external dependencies"],["ci","Changes to our CI configuration files and scripts"],["chore","Other changes that don't modify src or test files"],["revert","Reverts a previous commit"]],gitCommitScopes:[["projects","project"],["components","components"],["hooks","hook functions"],["utils","utils functions"],["types","TS declaration"],["styles","style"],["deps","project dependencies"],["release","release project"],["other","other changes"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{}},P="U2FsdGVkX18dc7x8PmAq30sl+nyGmi5VJJwninmYBRs8vVILEIjY+kT/F8ajm/6gRTMbDAEmx5WKInQBzeNSig==";async function B(e,t=l.cwd()){const{config:o}=await S({name:"soybean",defaults:N,overrides:e,cwd:t,packageJson:!0}),n=await F(t);if(o&&n){const a=new R("SOYBEAN_JS");o.changelogOptions={...o.changelogOptions,github:{repo:"",token:a.deCrypto(P)||""}}}return o}async function F(e){let t=!1;const o="soybean";try{const n=await j(p.join(e,"package.json"),"utf-8"),a=JSON.parse(n);t=a.name?.includes(o)||a.repository?.url?.includes(o)||a.author?.includes(o)||a.author?.name?.includes(o)||a.author?.url?.includes(o)}catch{}return t}async function V(){const e=await B(),t=g("soybean");t.version($).option("-e, --execute [command]","Execute additional command after bumping and before git commit. Defaults to 'npx soy changelog'").option("-p, --push","Indicates whether to push the git commit and tag").option("-t, --total","Generate changelog by total tags").option("-c, --cleanupDir <dir>",'The glob pattern of dirs to cleanup, If not set, it will use the default value, Multiple values use "," to separate them').help();const o={cleanup:{desc:"delete dirs: node_modules, dist, etc.",action:async n=>{const a=(n?.cleanupDir?.split(",")||[]).map(i=>i.trim()).filter(Boolean);a.length&&(e.cleanupDirs=a),await J(e.cleanupDirs)}},ncu:{desc:"npm-check-updates, it can update package.json dependencies to the latest version",action:async()=>{await _(e.ncuCommandArgs)}},"git-commit":{desc:"git commit, generate commit message which match Conventional Commits standard",action:async()=>{await T(e.gitCommitTypes,e.gitCommitScopes)}},"git-commit-verify":{desc:"verify git commit message, make sure it match Conventional Commits standard",action:async()=>{await I()}},changelog:{desc:"generate changelog",action:async n=>{await G(e.changelogOptions,n?.total)}},release:{desc:"release: update version, generate changelog, commit code",action:async n=>{await M(n?.execute,n?.push)}}};for await(const[n,{desc:a,action:i}]of Object.entries(o))t.command(n,a).action(i);t.parse()}V();function Y(e){return e}export{Y as defineConfig};
|