@done-coding/cli-utils 0.3.2 → 0.3.3-alpha.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/es/index.mjs +91 -89
- package/package.json +2 -2
- package/types/config-file.d.ts +2 -1
package/es/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import P from "chalk";
|
|
3
|
-
import { default as
|
|
3
|
+
import { default as ae } from "chalk";
|
|
4
4
|
import f from "node:path";
|
|
5
5
|
import b, { existsSync as h, mkdirSync as k, writeFileSync as g, readFileSync as m } from "node:fs";
|
|
6
6
|
import l from "crypto";
|
|
@@ -10,42 +10,42 @@ import { hideBin as F } from "yargs/helpers";
|
|
|
10
10
|
import { execSync as y } from "node:child_process";
|
|
11
11
|
import v from "json5";
|
|
12
12
|
export * from "json5";
|
|
13
|
-
import { default as
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as
|
|
16
|
-
import { default as
|
|
13
|
+
import { default as le } from "json5";
|
|
14
|
+
import { default as de } from "lodash.get";
|
|
15
|
+
import { default as me } from "lodash.set";
|
|
16
|
+
import { default as he } from "lodash.curry";
|
|
17
17
|
const c = Object.assign(
|
|
18
|
-
(
|
|
18
|
+
(e, ...r) => console.log(...r.map((t) => P[e](t))),
|
|
19
19
|
{
|
|
20
20
|
/** 成功 */
|
|
21
|
-
success: (...
|
|
21
|
+
success: (...e) => c("green", ...e),
|
|
22
22
|
/** /步骤 */
|
|
23
|
-
stage: (...
|
|
23
|
+
stage: (...e) => c("blue", ...e),
|
|
24
24
|
/** 提示信息 */
|
|
25
|
-
info: (...
|
|
25
|
+
info: (...e) => c("cyan", ...e),
|
|
26
26
|
/** 警告 */
|
|
27
|
-
warn: (...
|
|
27
|
+
warn: (...e) => c("yellow", ...e),
|
|
28
28
|
/** 错误 */
|
|
29
|
-
error: (...
|
|
29
|
+
error: (...e) => c("red", ...e),
|
|
30
30
|
/** 跳过 */
|
|
31
|
-
skip: (...
|
|
31
|
+
skip: (...e) => c("gray", ...e)
|
|
32
32
|
}
|
|
33
|
-
), Q = (
|
|
33
|
+
), Q = (e, {
|
|
34
34
|
/** 当前目录 */
|
|
35
|
-
currentDir:
|
|
35
|
+
currentDir: r = process.cwd(),
|
|
36
36
|
/** 优先找最远的父目录 */
|
|
37
37
|
isFindFarthest: t = !0
|
|
38
38
|
} = {}) => {
|
|
39
|
-
const o = f.resolve(
|
|
39
|
+
const o = f.resolve(r).split(f.sep).map((n, i, a) => i ? f.join(a.slice(0, i).join(f.sep), n) : n);
|
|
40
40
|
for (; o.length; ) {
|
|
41
|
-
const n = t ? o.shift() : o.pop(), i = f.join(n,
|
|
41
|
+
const n = t ? o.shift() : o.pop(), i = f.join(n, e);
|
|
42
42
|
if (b.existsSync(i))
|
|
43
43
|
return n;
|
|
44
44
|
}
|
|
45
45
|
}, C = "aes-256-cbc", S = 16, p = "hex", d = ":";
|
|
46
|
-
function $(
|
|
46
|
+
function $(e) {
|
|
47
47
|
return l.pbkdf2Sync(
|
|
48
|
-
|
|
48
|
+
e,
|
|
49
49
|
"done-coding-cli-salt",
|
|
50
50
|
// 使用固定的盐值
|
|
51
51
|
1e4,
|
|
@@ -56,12 +56,12 @@ function $(r) {
|
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
function X({
|
|
59
|
-
text:
|
|
60
|
-
secretKey:
|
|
59
|
+
text: e,
|
|
60
|
+
secretKey: r
|
|
61
61
|
}) {
|
|
62
62
|
try {
|
|
63
|
-
const t = $(
|
|
64
|
-
let i = n.update(
|
|
63
|
+
const t = $(r), o = l.randomBytes(S), n = l.createCipheriv(C, t, o);
|
|
64
|
+
let i = n.update(e);
|
|
65
65
|
i = Buffer.concat([i, n.final()]);
|
|
66
66
|
const a = o.toString(p), s = i.toString(p);
|
|
67
67
|
return `${a}${d}${s}`;
|
|
@@ -72,13 +72,13 @@ function X({
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
function Z({
|
|
75
|
-
encryptedText:
|
|
76
|
-
secretKey:
|
|
75
|
+
encryptedText: e,
|
|
76
|
+
secretKey: r
|
|
77
77
|
}) {
|
|
78
78
|
try {
|
|
79
|
-
if (!
|
|
79
|
+
if (!e.includes(d))
|
|
80
80
|
return "";
|
|
81
|
-
const t = $(
|
|
81
|
+
const t = $(r), [o, n] = e.split(d);
|
|
82
82
|
if (o.length !== S * 2)
|
|
83
83
|
return "";
|
|
84
84
|
const i = Buffer.from(o, p), a = Buffer.from(n, p), s = l.createDecipheriv(C, t, i);
|
|
@@ -90,39 +90,39 @@ function Z({
|
|
|
90
90
|
), "";
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
const x = (...
|
|
94
|
-
const [
|
|
95
|
-
return H(
|
|
93
|
+
const x = (...e) => {
|
|
94
|
+
const [r, t = {}] = e;
|
|
95
|
+
return H(r, {
|
|
96
96
|
onCancel(o) {
|
|
97
97
|
return c.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
|
|
98
98
|
},
|
|
99
99
|
...t
|
|
100
100
|
});
|
|
101
|
-
}, R = (
|
|
102
|
-
|
|
101
|
+
}, R = (e, r) => {
|
|
102
|
+
e ? c.error(e) : c.error(r.message), r != null && r.stack && c.error(r.stack), process.exit(1);
|
|
103
103
|
}, T = () => {
|
|
104
|
-
const
|
|
105
|
-
return E(
|
|
106
|
-
}, j = (
|
|
107
|
-
usage:
|
|
104
|
+
const e = F(process.argv);
|
|
105
|
+
return E(e);
|
|
106
|
+
}, j = (e, {
|
|
107
|
+
usage: r,
|
|
108
108
|
version: t,
|
|
109
109
|
demandCommandCount: o,
|
|
110
110
|
options: n,
|
|
111
111
|
positionals: i,
|
|
112
112
|
subcommands: a
|
|
113
113
|
}) => {
|
|
114
|
-
let s =
|
|
115
|
-
|
|
114
|
+
let s = e.strict();
|
|
115
|
+
r && (s = s.usage(`Usage: ${r}`)), o && (s = s.demandCommand(o));
|
|
116
116
|
const u = "help";
|
|
117
117
|
return s = s.help(u), t ? s = s.version(t).alias("h", u).alias("v", "version") : s = s.alias("h", u), n && (s = s.options(n)), i && (s = Object.entries(i).reduce((w, [D, O]) => w.positional(D, O), s)), a && (s = s.command(a)), s;
|
|
118
|
-
},
|
|
119
|
-
const t = await j(T(),
|
|
120
|
-
return
|
|
121
|
-
},
|
|
122
|
-
const { command:
|
|
123
|
-
}, ...n } =
|
|
118
|
+
}, ee = async ({ handler: e, ...r }) => {
|
|
119
|
+
const t = await j(T(), r).fail(R).argv;
|
|
120
|
+
return e ? e(t) : t;
|
|
121
|
+
}, re = (e) => {
|
|
122
|
+
const { command: r, describe: t, handler: o = () => {
|
|
123
|
+
}, ...n } = e;
|
|
124
124
|
return {
|
|
125
|
-
command:
|
|
125
|
+
command: r,
|
|
126
126
|
describe: t,
|
|
127
127
|
builder(i) {
|
|
128
128
|
return j(i, n);
|
|
@@ -130,9 +130,9 @@ const x = (...r) => {
|
|
|
130
130
|
handler: o
|
|
131
131
|
};
|
|
132
132
|
};
|
|
133
|
-
var _ = /* @__PURE__ */ ((
|
|
133
|
+
var _ = /* @__PURE__ */ ((e) => (e.VSCODE = "VsCode", e.CURSOR = "Cursor", e.OTHER = "其他", e))(_ || {});
|
|
134
134
|
const A = async () => {
|
|
135
|
-
const { editorType:
|
|
135
|
+
const { editorType: e } = await x([
|
|
136
136
|
{
|
|
137
137
|
name: "editorType",
|
|
138
138
|
type: "select",
|
|
@@ -142,31 +142,31 @@ const A = async () => {
|
|
|
142
142
|
"VsCode",
|
|
143
143
|
"其他"
|
|
144
144
|
/* OTHER */
|
|
145
|
-
].map((
|
|
146
|
-
title:
|
|
147
|
-
value:
|
|
145
|
+
].map((r) => ({
|
|
146
|
+
title: r,
|
|
147
|
+
value: r
|
|
148
148
|
}))
|
|
149
149
|
}
|
|
150
150
|
]);
|
|
151
|
-
return
|
|
151
|
+
return e;
|
|
152
152
|
}, B = {
|
|
153
153
|
Cursor: "cursor",
|
|
154
154
|
VsCode: "code"
|
|
155
|
-
}, N = (
|
|
155
|
+
}, N = (e, r, t) => {
|
|
156
156
|
try {
|
|
157
|
-
y(`${
|
|
157
|
+
y(`${e} -v`, { stdio: "ignore" }), y(`${e} ${r}`);
|
|
158
158
|
} catch {
|
|
159
159
|
t();
|
|
160
160
|
}
|
|
161
|
-
}, V = (
|
|
161
|
+
}, V = (e, r) => {
|
|
162
162
|
const t = (o) => c.info(`
|
|
163
|
-
${o}, 请用编辑器打开 ${
|
|
163
|
+
${o}, 请用编辑器打开 ${e} 进行编辑
|
|
164
164
|
`);
|
|
165
|
-
switch (
|
|
165
|
+
switch (r) {
|
|
166
166
|
case "Cursor":
|
|
167
167
|
case "VsCode": {
|
|
168
|
-
const o = B[
|
|
169
|
-
N(o,
|
|
168
|
+
const o = B[r];
|
|
169
|
+
N(o, e, () => {
|
|
170
170
|
t(`${o}命令未安装`);
|
|
171
171
|
});
|
|
172
172
|
break;
|
|
@@ -174,77 +174,79 @@ const A = async () => {
|
|
|
174
174
|
default:
|
|
175
175
|
t("其他编辑器");
|
|
176
176
|
}
|
|
177
|
-
}, L = (
|
|
177
|
+
}, L = (e = process.cwd()) => ({
|
|
178
178
|
/** 必须保留 */
|
|
179
179
|
rootDir: {
|
|
180
180
|
type: "string",
|
|
181
181
|
alias: "r",
|
|
182
182
|
describe: "运行目录",
|
|
183
183
|
/** 必须设置默认值 */
|
|
184
|
-
default:
|
|
184
|
+
default: e
|
|
185
185
|
}
|
|
186
|
-
}),
|
|
187
|
-
configPathDefault:
|
|
188
|
-
rootDirDefault:
|
|
186
|
+
}), te = ({
|
|
187
|
+
configPathDefault: e,
|
|
188
|
+
rootDirDefault: r
|
|
189
189
|
}) => ({
|
|
190
190
|
/** 必须保留 */
|
|
191
|
-
...L(
|
|
191
|
+
...L(r),
|
|
192
192
|
/** 必须保留 */
|
|
193
193
|
configPath: {
|
|
194
194
|
type: "string",
|
|
195
195
|
alias: "c",
|
|
196
196
|
describe: "配置文件相对路径",
|
|
197
197
|
/** 必须设置默认值 */
|
|
198
|
-
default:
|
|
198
|
+
default: e
|
|
199
199
|
}
|
|
200
|
-
}), I = async (
|
|
201
|
-
const { configPath: t, rootDir: o } =
|
|
200
|
+
}), I = async (e, r) => {
|
|
201
|
+
const { configPath: t, rootDir: o } = r, n = f.resolve(o, t), i = f.dirname(n);
|
|
202
202
|
return h(i) || k(i, {
|
|
203
203
|
recursive: !0
|
|
204
|
-
}), n.endsWith(".json5") ? (c.info(`json5模式写入 ${n}`), g(n, v.stringify(
|
|
205
|
-
},
|
|
206
|
-
onFileGenerated: t
|
|
204
|
+
}), n.endsWith(".json5") ? (c.info(`json5模式写入 ${n}`), g(n, v.stringify(e, null, 2)), n) : (c.info(`json模式写入 ${n}`), g(n, JSON.stringify(e, null, 2)), n);
|
|
205
|
+
}, oe = async (e, r, {
|
|
206
|
+
onFileGenerated: t,
|
|
207
|
+
edit: o = !1
|
|
207
208
|
} = {}) => {
|
|
208
|
-
const
|
|
209
|
-
t == null || t(o)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
209
|
+
const n = await I(e, r);
|
|
210
|
+
if (t == null || t(n), o) {
|
|
211
|
+
const i = await A();
|
|
212
|
+
V(r.configPath, i);
|
|
213
|
+
}
|
|
214
|
+
}, ne = async (e) => {
|
|
215
|
+
const { configPath: r, rootDir: t } = e, o = f.resolve(t, r);
|
|
214
216
|
if (!h(o)) {
|
|
215
217
|
c.warn(`配置文件不存在 ${o}`);
|
|
216
218
|
return;
|
|
217
219
|
}
|
|
218
220
|
return o.endsWith(".json5") ? (c.info(`json5模式解析 ${o}`), v.parse(m(o, "utf8"))) : (c.info(`json模式解析 ${o}`), JSON.parse(m(o, "utf8")));
|
|
219
|
-
},
|
|
220
|
-
const { useDefaultConfig:
|
|
221
|
+
}, se = async () => {
|
|
222
|
+
const { useDefaultConfig: e } = await x({
|
|
221
223
|
name: "useDefaultConfig",
|
|
222
224
|
type: "confirm",
|
|
223
225
|
message: "使用默认模板配置",
|
|
224
226
|
initial: !0
|
|
225
227
|
});
|
|
226
|
-
return
|
|
228
|
+
return e;
|
|
227
229
|
};
|
|
228
230
|
export {
|
|
229
231
|
_ as EditorTypeEnum,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
he as _curry,
|
|
233
|
+
de as _get,
|
|
234
|
+
me as _set,
|
|
235
|
+
ae as chalk,
|
|
236
|
+
ee as createMainCommand,
|
|
237
|
+
re as createSubcommand,
|
|
236
238
|
Z as decryptAES,
|
|
237
239
|
X as encryptAES,
|
|
238
|
-
|
|
240
|
+
te as getConfigFileCommonOptions,
|
|
239
241
|
A as getEditorType,
|
|
240
242
|
L as getRootDirOptions,
|
|
241
|
-
|
|
243
|
+
se as getUseDefaultConfig,
|
|
242
244
|
I as initConfigFile,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
oe as initHandlerCommon,
|
|
246
|
+
le as json5,
|
|
245
247
|
c as log,
|
|
246
248
|
Q as lookForParentTarget,
|
|
247
249
|
V as openFileInEditor,
|
|
248
|
-
|
|
250
|
+
ne as readConfigFile,
|
|
249
251
|
x as xPrompts
|
|
250
252
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-alpha.0",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"prompts": "^2.4.2",
|
|
62
62
|
"yargs": "^17.7.2"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "9b65389752c25c4b7fff7fa8dfd46e5788ef2390"
|
|
65
65
|
}
|
package/types/config-file.d.ts
CHANGED
|
@@ -26,9 +26,10 @@ export declare const getConfigFileCommonOptions: ({ configPathDefault, rootDirDe
|
|
|
26
26
|
/** 初始化配置文件 */
|
|
27
27
|
export declare const initConfigFile: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>) => Promise<string>;
|
|
28
28
|
/** 初始化配置文件通用处理器 */
|
|
29
|
-
export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, }?: {
|
|
29
|
+
export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, edit, }?: {
|
|
30
30
|
/** 文件已生成 */
|
|
31
31
|
onFileGenerated?: ((path: string) => void) | undefined;
|
|
32
|
+
edit?: boolean | undefined;
|
|
32
33
|
}) => Promise<void>;
|
|
33
34
|
/** 读取配置文件 */
|
|
34
35
|
export declare const readConfigFile: <T>(argv: CliHandlerArgv<ReadConfigFileOptions>) => Promise<T | undefined>;
|