@done-coding/cli-utils 0.5.0-alpha.0 → 0.6.0-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 +332 -196
- package/package.json +6 -2
- package/types/cli-config.d.ts +15 -0
- package/types/file-operate.d.ts +2 -0
- package/types/git.d.ts +2 -0
- package/types/husky.d.ts +16 -0
- package/types/index.d.ts +3 -0
- package/types/package-json.d.ts +21 -0
package/es/index.mjs
CHANGED
|
@@ -1,52 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { default as
|
|
2
|
+
import u from "chalk";
|
|
3
|
+
import { default as Ae } from "chalk";
|
|
4
4
|
import g from "node:path";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import d, { existsSync as p, mkdirSync as j, writeFileSync as S, readFileSync as $, rmSync as A } from "node:fs";
|
|
6
|
+
import y from "crypto";
|
|
7
|
+
import I from "prompts";
|
|
8
8
|
import N from "yargs";
|
|
9
|
-
import { hideBin as
|
|
10
|
-
import { execSync as
|
|
11
|
-
import
|
|
9
|
+
import { hideBin as M } from "yargs/helpers";
|
|
10
|
+
import { execSync as f } from "node:child_process";
|
|
11
|
+
import k from "json5";
|
|
12
12
|
export * from "json5";
|
|
13
|
-
import { default as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
import { default as Me } from "json5";
|
|
14
|
+
import Y from "lodash.merge";
|
|
15
|
+
import m from "pinyin";
|
|
16
|
+
import J from "semver";
|
|
17
|
+
import { tmpdir as L } from "node:os";
|
|
18
|
+
import { default as Je } from "lodash.get";
|
|
19
|
+
import { default as Ge } from "lodash.set";
|
|
20
|
+
import { default as Be } from "lodash.curry";
|
|
21
|
+
const a = Object.assign(
|
|
22
|
+
(e, ...o) => console.log(...o.map((t) => u[e](t))),
|
|
20
23
|
{
|
|
21
24
|
/** 成功 */
|
|
22
|
-
success: (...
|
|
25
|
+
success: (...e) => a("green", ...e),
|
|
23
26
|
/** /步骤 */
|
|
24
|
-
stage: (...
|
|
27
|
+
stage: (...e) => a("blue", ...e),
|
|
25
28
|
/** 提示信息 */
|
|
26
|
-
info: (...
|
|
29
|
+
info: (...e) => a("cyan", ...e),
|
|
27
30
|
/** 警告 */
|
|
28
|
-
warn: (...
|
|
31
|
+
warn: (...e) => a("yellow", ...e),
|
|
29
32
|
/** 错误 */
|
|
30
|
-
error: (...
|
|
33
|
+
error: (...e) => a("red", ...e),
|
|
31
34
|
/** 跳过 */
|
|
32
|
-
skip: (...
|
|
35
|
+
skip: (...e) => a("gray", ...e)
|
|
33
36
|
}
|
|
34
|
-
),
|
|
37
|
+
), Se = (e, {
|
|
35
38
|
/** 当前目录 */
|
|
36
|
-
currentDir:
|
|
39
|
+
currentDir: o = process.cwd(),
|
|
37
40
|
/** 优先找最远的父目录 */
|
|
38
|
-
isFindFarthest:
|
|
41
|
+
isFindFarthest: t = !0
|
|
39
42
|
} = {}) => {
|
|
40
|
-
const
|
|
41
|
-
for (;
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
43
|
+
const r = g.resolve(o).split(g.sep).map((n, s, c) => s ? g.join(c.slice(0, s).join(g.sep), n) : n);
|
|
44
|
+
for (; r.length; ) {
|
|
45
|
+
const n = t ? r.shift() : r.pop(), s = g.join(n, e);
|
|
46
|
+
if (d.existsSync(s))
|
|
47
|
+
return n;
|
|
45
48
|
}
|
|
46
|
-
},
|
|
47
|
-
function
|
|
48
|
-
return
|
|
49
|
-
|
|
49
|
+
}, w = "aes-256-cbc", _ = 16, h = "hex", v = ":";
|
|
50
|
+
function P(e) {
|
|
51
|
+
return y.pbkdf2Sync(
|
|
52
|
+
e,
|
|
50
53
|
"done-coding-cli-salt",
|
|
51
54
|
// 使用固定的盐值
|
|
52
55
|
1e4,
|
|
@@ -56,84 +59,84 @@ function w(t) {
|
|
|
56
59
|
"sha256"
|
|
57
60
|
);
|
|
58
61
|
}
|
|
59
|
-
function
|
|
60
|
-
text:
|
|
61
|
-
secretKey:
|
|
62
|
+
function $e({
|
|
63
|
+
text: e,
|
|
64
|
+
secretKey: o
|
|
62
65
|
}) {
|
|
63
66
|
try {
|
|
64
|
-
const
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
return `${
|
|
69
|
-
} catch (
|
|
70
|
-
return
|
|
71
|
-
`加密失败: ${
|
|
67
|
+
const t = P(o), r = y.randomBytes(_), n = y.createCipheriv(w, t, r);
|
|
68
|
+
let s = n.update(e);
|
|
69
|
+
s = Buffer.concat([s, n.final()]);
|
|
70
|
+
const c = r.toString(h), i = s.toString(h);
|
|
71
|
+
return `${c}${v}${i}`;
|
|
72
|
+
} catch (t) {
|
|
73
|
+
return a.error(
|
|
74
|
+
`加密失败: ${t instanceof Error ? t.message : String(t)}`
|
|
72
75
|
), "";
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
function
|
|
76
|
-
encryptedText:
|
|
77
|
-
secretKey:
|
|
78
|
+
function ve({
|
|
79
|
+
encryptedText: e,
|
|
80
|
+
secretKey: o
|
|
78
81
|
}) {
|
|
79
82
|
try {
|
|
80
|
-
if (!
|
|
83
|
+
if (!e.includes(v))
|
|
81
84
|
return "";
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
85
|
+
const t = P(o), [r, n] = e.split(v);
|
|
86
|
+
if (r.length !== _ * 2)
|
|
84
87
|
return "";
|
|
85
|
-
const
|
|
86
|
-
let
|
|
87
|
-
return
|
|
88
|
-
} catch (
|
|
89
|
-
return
|
|
90
|
-
`解密失败: ${
|
|
88
|
+
const s = Buffer.from(r, h), c = Buffer.from(n, h), i = y.createDecipheriv(w, t, s);
|
|
89
|
+
let l = i.update(c);
|
|
90
|
+
return l = Buffer.concat([l, i.final()]), l.toString();
|
|
91
|
+
} catch (t) {
|
|
92
|
+
return a.error(
|
|
93
|
+
`解密失败: ${t instanceof Error ? t.message : String(t)}`
|
|
91
94
|
), "";
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
|
-
const
|
|
95
|
-
const [
|
|
96
|
-
return
|
|
97
|
-
onCancel(
|
|
98
|
-
return
|
|
97
|
+
const D = (...e) => {
|
|
98
|
+
const [o, t = {}] = e;
|
|
99
|
+
return I(o, {
|
|
100
|
+
onCancel(r) {
|
|
101
|
+
return a.error(`退出${r == null ? void 0 : r.name}输入`), process.exit(1);
|
|
99
102
|
},
|
|
100
|
-
...
|
|
103
|
+
...t
|
|
101
104
|
});
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
const
|
|
106
|
-
return N(
|
|
107
|
-
},
|
|
108
|
-
usage:
|
|
109
|
-
version:
|
|
110
|
-
demandCommandCount:
|
|
111
|
-
options:
|
|
112
|
-
positionals:
|
|
113
|
-
subcommands:
|
|
105
|
+
}, G = (e, o) => {
|
|
106
|
+
e ? a.error(e) : a.error(o.message), o != null && o.stack && a.error(o.stack), process.exit(1);
|
|
107
|
+
}, V = () => {
|
|
108
|
+
const e = M(process.argv);
|
|
109
|
+
return N(e);
|
|
110
|
+
}, x = (e, {
|
|
111
|
+
usage: o,
|
|
112
|
+
version: t,
|
|
113
|
+
demandCommandCount: r,
|
|
114
|
+
options: n,
|
|
115
|
+
positionals: s,
|
|
116
|
+
subcommands: c
|
|
114
117
|
}) => {
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
return
|
|
119
|
-
},
|
|
120
|
-
const
|
|
121
|
-
return
|
|
122
|
-
},
|
|
123
|
-
const { command:
|
|
124
|
-
}, ...
|
|
118
|
+
let i = e.strict();
|
|
119
|
+
o && (i = i.usage(`Usage: ${o}`)), r && (i = i.demandCommand(r));
|
|
120
|
+
const l = "help";
|
|
121
|
+
return i = i.help(l), t ? i = i.version(t).alias("h", l).alias("v", "version") : i = i.alias("h", l), n && (i = i.options(n)), s && (i = Object.entries(s).reduce((E, [H, T]) => E.positional(H, T), i)), c && (i = i.command(c)), i;
|
|
122
|
+
}, Re = async ({ handler: e, ...o }) => {
|
|
123
|
+
const t = await x(V(), o).fail(G).argv;
|
|
124
|
+
return e ? e(t) : t;
|
|
125
|
+
}, Ee = (e) => {
|
|
126
|
+
const { command: o, describe: t, handler: r = () => {
|
|
127
|
+
}, ...n } = e;
|
|
125
128
|
return {
|
|
126
|
-
command:
|
|
127
|
-
describe:
|
|
128
|
-
builder(
|
|
129
|
-
return
|
|
129
|
+
command: o,
|
|
130
|
+
describe: t,
|
|
131
|
+
builder(s) {
|
|
132
|
+
return x(s, n);
|
|
130
133
|
},
|
|
131
|
-
handler:
|
|
134
|
+
handler: r
|
|
132
135
|
};
|
|
133
136
|
};
|
|
134
|
-
var
|
|
135
|
-
const
|
|
136
|
-
const { editorType:
|
|
137
|
+
var B = /* @__PURE__ */ ((e) => (e.VSCODE = "VsCode", e.CURSOR = "Cursor", e.OTHER = "其他", e))(B || {});
|
|
138
|
+
const K = async () => {
|
|
139
|
+
const { editorType: e } = await D([
|
|
137
140
|
{
|
|
138
141
|
name: "editorType",
|
|
139
142
|
type: "select",
|
|
@@ -143,169 +146,302 @@ const L = async () => {
|
|
|
143
146
|
"VsCode",
|
|
144
147
|
"其他"
|
|
145
148
|
/* OTHER */
|
|
146
|
-
].map((
|
|
147
|
-
title:
|
|
148
|
-
value:
|
|
149
|
+
].map((o) => ({
|
|
150
|
+
title: o,
|
|
151
|
+
value: o
|
|
149
152
|
}))
|
|
150
153
|
}
|
|
151
154
|
]);
|
|
152
|
-
return
|
|
153
|
-
},
|
|
155
|
+
return e;
|
|
156
|
+
}, U = {
|
|
154
157
|
Cursor: "cursor",
|
|
155
158
|
VsCode: "code"
|
|
156
|
-
},
|
|
159
|
+
}, W = (e, o, t) => {
|
|
157
160
|
try {
|
|
158
|
-
|
|
161
|
+
f(`${e} -v`, { stdio: "ignore" }), f(`${e} ${o}`);
|
|
159
162
|
} catch {
|
|
160
|
-
|
|
163
|
+
t();
|
|
161
164
|
}
|
|
162
|
-
},
|
|
163
|
-
const
|
|
164
|
-
${
|
|
165
|
+
}, X = (e, o) => {
|
|
166
|
+
const t = (r) => a.info(`
|
|
167
|
+
${r}, 请用编辑器打开 ${e} 进行编辑
|
|
165
168
|
`);
|
|
166
|
-
switch (
|
|
169
|
+
switch (o) {
|
|
167
170
|
case "Cursor":
|
|
168
171
|
case "VsCode": {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
const r = U[o];
|
|
173
|
+
W(r, e, () => {
|
|
174
|
+
t(`${r}命令未安装`);
|
|
172
175
|
});
|
|
173
176
|
break;
|
|
174
177
|
}
|
|
175
178
|
default:
|
|
176
|
-
|
|
179
|
+
t("其他编辑器");
|
|
177
180
|
}
|
|
178
|
-
},
|
|
181
|
+
}, q = (e = process.cwd()) => ({
|
|
179
182
|
/** 必须保留 */
|
|
180
183
|
rootDir: {
|
|
181
184
|
type: "string",
|
|
182
185
|
alias: "R",
|
|
183
186
|
describe: "运行目录",
|
|
184
187
|
/** 必须设置默认值 */
|
|
185
|
-
default:
|
|
188
|
+
default: e
|
|
186
189
|
}
|
|
187
|
-
}),
|
|
188
|
-
configPathDefault:
|
|
189
|
-
rootDirDefault:
|
|
190
|
+
}), Oe = ({
|
|
191
|
+
configPathDefault: e,
|
|
192
|
+
rootDirDefault: o
|
|
190
193
|
}) => ({
|
|
191
194
|
/** 必须保留 */
|
|
192
|
-
...
|
|
195
|
+
...q(o),
|
|
193
196
|
/** 必须保留 */
|
|
194
197
|
configPath: {
|
|
195
198
|
type: "string",
|
|
196
199
|
alias: "C",
|
|
197
200
|
describe: "配置文件相对路径",
|
|
198
201
|
/** 必须设置默认值 */
|
|
199
|
-
default:
|
|
202
|
+
default: e
|
|
200
203
|
}
|
|
201
|
-
}),
|
|
202
|
-
const { configPath:
|
|
203
|
-
return
|
|
204
|
+
}), z = async (e, o) => {
|
|
205
|
+
const { configPath: t, rootDir: r } = o, n = g.resolve(r, t), s = g.dirname(n);
|
|
206
|
+
return p(s) || j(s, {
|
|
204
207
|
recursive: !0
|
|
205
|
-
}),
|
|
206
|
-
},
|
|
207
|
-
onFileGenerated:
|
|
208
|
-
edit:
|
|
208
|
+
}), n.endsWith(".json5") ? (a.info(`json5模式写入 ${n}`), S(n, k.stringify(e, null, 2)), n) : (a.info(`json模式写入 ${n}`), S(n, JSON.stringify(e, null, 2)), n);
|
|
209
|
+
}, ke = async (e, o, {
|
|
210
|
+
onFileGenerated: t,
|
|
211
|
+
edit: r = !1
|
|
209
212
|
} = {}) => {
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
const
|
|
213
|
-
|
|
213
|
+
const n = await z(e, o);
|
|
214
|
+
if (t == null || t(n), r) {
|
|
215
|
+
const s = await K();
|
|
216
|
+
X(o.configPath, s);
|
|
214
217
|
}
|
|
215
|
-
},
|
|
216
|
-
const { configPath:
|
|
217
|
-
if (!
|
|
218
|
-
if (
|
|
219
|
-
return
|
|
220
|
-
const
|
|
221
|
-
throw new Error(
|
|
218
|
+
}, we = async (e, o) => {
|
|
219
|
+
const { configPath: t, rootDir: r } = e, n = g.resolve(r, t);
|
|
220
|
+
if (!p(n)) {
|
|
221
|
+
if (o)
|
|
222
|
+
return a.info("配置文件不存在,使用onNotExists返回值"), o();
|
|
223
|
+
const s = `配置文件不存在 ${n}`;
|
|
224
|
+
throw new Error(s);
|
|
222
225
|
}
|
|
223
|
-
return
|
|
224
|
-
},
|
|
225
|
-
const { useDefaultConfig:
|
|
226
|
+
return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), k.parse($(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse($(n, "utf8")));
|
|
227
|
+
}, _e = async () => {
|
|
228
|
+
const { useDefaultConfig: e } = await D({
|
|
226
229
|
name: "useDefaultConfig",
|
|
227
230
|
type: "confirm",
|
|
228
231
|
message: "使用默认模板配置",
|
|
229
232
|
initial: !0
|
|
230
233
|
});
|
|
231
|
-
return
|
|
232
|
-
},
|
|
233
|
-
rootDir:
|
|
234
|
+
return e;
|
|
235
|
+
}, b = "package.json", R = ({
|
|
236
|
+
rootDir: e
|
|
234
237
|
}) => {
|
|
235
|
-
const
|
|
236
|
-
if (!
|
|
237
|
-
throw new Error(`${
|
|
238
|
-
const
|
|
239
|
-
return JSON.parse(
|
|
240
|
-
},
|
|
241
|
-
|
|
238
|
+
const o = g.resolve(e, b);
|
|
239
|
+
if (!p(o))
|
|
240
|
+
throw new Error(`${e}未找到package.json文件`);
|
|
241
|
+
const t = $(o, "utf-8");
|
|
242
|
+
return JSON.parse(t);
|
|
243
|
+
}, Q = ({
|
|
244
|
+
rootDir: e,
|
|
245
|
+
pkgJson: o,
|
|
246
|
+
pkgName: t,
|
|
247
|
+
isDevPkg: r
|
|
248
|
+
}) => {
|
|
249
|
+
const n = o || R({ rootDir: e }), s = r ? n.devDependencies : n.dependencies;
|
|
250
|
+
let c = s == null ? void 0 : s[t];
|
|
251
|
+
if (!c) {
|
|
252
|
+
const i = r ? n.dependencies : n.devDependencies;
|
|
253
|
+
c = i == null ? void 0 : i[t], c && console.log(
|
|
254
|
+
u.yellow(
|
|
255
|
+
`${r ? "开发" : "生产"}依赖包${t}可能错误的安装在${r ? "dependencies" : "devDependencies"}`
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
return c || console.log(u.cyan(`依赖包${t}未安装`)), c;
|
|
261
|
+
}, Pe = ({
|
|
262
|
+
patchConfig: e,
|
|
263
|
+
rootDir: o
|
|
264
|
+
}) => {
|
|
265
|
+
if (!e)
|
|
266
|
+
return;
|
|
267
|
+
const t = R({ rootDir: o }), r = Y(t, e), n = g.resolve(o, b);
|
|
268
|
+
S(n, JSON.stringify(r, null, 2), "utf-8");
|
|
269
|
+
}, De = (e) => {
|
|
270
|
+
const t = f("git rev-parse --show-toplevel", {
|
|
271
|
+
cwd: e
|
|
272
|
+
}).toString();
|
|
273
|
+
if (!t)
|
|
274
|
+
throw new Error("获取git根目录失败");
|
|
275
|
+
return t.trim();
|
|
276
|
+
}, xe = ({
|
|
277
|
+
remoteAlias: e
|
|
242
278
|
} = {}) => {
|
|
243
279
|
try {
|
|
244
|
-
const
|
|
245
|
-
let
|
|
280
|
+
const o = f("git rev-parse HEAD").toString().trim(), t = f('git log -1 --pretty=format:"%an"').toString().trim(), r = f('git log -1 --pretty=format:"%ae"').toString().trim(), n = f('git log -1 --pretty=format:"%s"').toString().trim(), s = f("git config user.name").toString().trim(), c = f("git config user.email").toString().trim(), i = f("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
281
|
+
let l = "";
|
|
246
282
|
try {
|
|
247
|
-
|
|
283
|
+
l = f(`git config --get remote.${e}.url`).toString().trim();
|
|
248
284
|
} catch {
|
|
249
|
-
|
|
285
|
+
a.warn("git远程仓库地址获取失败或者不存在");
|
|
250
286
|
}
|
|
251
287
|
return {
|
|
252
|
-
lastHash:
|
|
253
|
-
lastCommitter:
|
|
254
|
-
lastCommitterPinYin:
|
|
255
|
-
style:
|
|
288
|
+
lastHash: o,
|
|
289
|
+
lastCommitter: t,
|
|
290
|
+
lastCommitterPinYin: m(t, {
|
|
291
|
+
style: m.STYLE_NORMAL,
|
|
256
292
|
heteronym: !1
|
|
257
293
|
}).join(""),
|
|
258
|
-
lastCommitEmail:
|
|
259
|
-
lastCommitMsg:
|
|
260
|
-
userName:
|
|
261
|
-
userNamePinYin:
|
|
262
|
-
style:
|
|
294
|
+
lastCommitEmail: r,
|
|
295
|
+
lastCommitMsg: n,
|
|
296
|
+
userName: s,
|
|
297
|
+
userNamePinYin: m(s, {
|
|
298
|
+
style: m.STYLE_NORMAL,
|
|
263
299
|
heteronym: !1
|
|
264
300
|
}).join(""),
|
|
265
|
-
userEmail:
|
|
266
|
-
branchName:
|
|
267
|
-
remoteInfo:
|
|
268
|
-
alias:
|
|
269
|
-
url:
|
|
301
|
+
userEmail: c,
|
|
302
|
+
branchName: i,
|
|
303
|
+
remoteInfo: l ? {
|
|
304
|
+
alias: e,
|
|
305
|
+
url: l
|
|
270
306
|
} : void 0
|
|
271
307
|
};
|
|
272
|
-
} catch (
|
|
273
|
-
throw
|
|
308
|
+
} catch (o) {
|
|
309
|
+
throw a.error("获取git最后提交信息失败"), o;
|
|
274
310
|
}
|
|
275
|
-
},
|
|
276
|
-
branchName:
|
|
277
|
-
version:
|
|
278
|
-
remoteInfo:
|
|
311
|
+
}, be = ({
|
|
312
|
+
branchName: e,
|
|
313
|
+
version: o,
|
|
314
|
+
remoteInfo: t
|
|
279
315
|
}) => {
|
|
280
|
-
|
|
316
|
+
t && (f(`git push ${t.alias} v${o}`, {
|
|
281
317
|
stdio: "inherit"
|
|
282
|
-
}),
|
|
318
|
+
}), f(`git push ${t.alias} ${e}`, {
|
|
283
319
|
stdio: "inherit"
|
|
284
320
|
}));
|
|
321
|
+
}, C = 73, Z = (e) => {
|
|
322
|
+
const t = d.statSync(e).mode;
|
|
323
|
+
if ((t & C) === C)
|
|
324
|
+
return;
|
|
325
|
+
console.log(u.blue(`${e} 没有执行权限 添加... `));
|
|
326
|
+
const r = t | C;
|
|
327
|
+
d.chmodSync(e, r), console.log(u.green(`${e} 添加执行权限成功`));
|
|
328
|
+
}, ee = "husky", te = ".husky", oe = ({
|
|
329
|
+
projectRootDir: e
|
|
330
|
+
}) => {
|
|
331
|
+
const o = Q({
|
|
332
|
+
rootDir: e,
|
|
333
|
+
pkgJson: R({ rootDir: e }),
|
|
334
|
+
pkgName: ee,
|
|
335
|
+
isDevPkg: !0
|
|
336
|
+
});
|
|
337
|
+
if (!o)
|
|
338
|
+
throw new Error("husky版本获取失败, 可能husky未安装");
|
|
339
|
+
const t = o.replace(/^(\^|~)/, ""), r = "<9.0.0";
|
|
340
|
+
return J.satisfies(t, r) ? (console.log(u.cyan(`${t}符合${r}`)), `#!/usr/bin/env sh
|
|
341
|
+
. "$(dirname -- "$0")/_/husky.sh"`) : (console.log(u.cyan(`${t}不符合${r}`)), "");
|
|
342
|
+
}, re = ({
|
|
343
|
+
projectRootDir: e
|
|
344
|
+
}) => g.resolve(e, te), Fe = ({
|
|
345
|
+
hookNames: e,
|
|
346
|
+
projectRootDir: o,
|
|
347
|
+
getCode: t
|
|
348
|
+
}) => {
|
|
349
|
+
const r = re({ projectRootDir: o });
|
|
350
|
+
d.existsSync(r) || d.mkdirSync(r, { recursive: !0 }), e.forEach((n) => {
|
|
351
|
+
const s = g.resolve(r, n), c = d.existsSync(s);
|
|
352
|
+
let i = t(n);
|
|
353
|
+
if (c)
|
|
354
|
+
d.readFileSync(s, "utf-8").includes(i) ? console.log(
|
|
355
|
+
u.gray(`${s} ${n}相关调用 ${i} 已存在 跳过`)
|
|
356
|
+
) : (d.appendFileSync(
|
|
357
|
+
s,
|
|
358
|
+
`
|
|
359
|
+
${i}
|
|
360
|
+
`
|
|
361
|
+
), console.log(u.green(`${s} 添加 ${n}相关调用成功`)));
|
|
362
|
+
else {
|
|
363
|
+
const l = oe({
|
|
364
|
+
projectRootDir: o
|
|
365
|
+
});
|
|
366
|
+
d.writeFileSync(
|
|
367
|
+
s,
|
|
368
|
+
`${l}
|
|
369
|
+
|
|
370
|
+
${i}
|
|
371
|
+
`,
|
|
372
|
+
"utf-8"
|
|
373
|
+
), console.log(u.green(`${s} 添加 ${n}相关调用成功`));
|
|
374
|
+
}
|
|
375
|
+
Z(s);
|
|
376
|
+
});
|
|
377
|
+
}, O = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", ne = (e) => `./.DONE_CODING_CLI_CONFIG_TEMPORARY_DIRECTORY_FOR_${e}`, F = (e) => `./assets/${e}`, se = (e) => `${F(e)}/index.json`, He = async ({
|
|
378
|
+
moduleName: e,
|
|
379
|
+
onSuccess: o
|
|
380
|
+
}) => {
|
|
381
|
+
console.log(u.blue(`拉取${e}配置,请稍等...`));
|
|
382
|
+
const t = ne(e), r = g.resolve(
|
|
383
|
+
L(),
|
|
384
|
+
t
|
|
385
|
+
);
|
|
386
|
+
if (p(r))
|
|
387
|
+
return console.log(
|
|
388
|
+
u.red(`${r} 已存在,请手动删除该目录再试`)
|
|
389
|
+
), process.exit(1);
|
|
390
|
+
const n = () => {
|
|
391
|
+
A(r, { recursive: !0, force: !0 });
|
|
392
|
+
};
|
|
393
|
+
let s;
|
|
394
|
+
try {
|
|
395
|
+
f(`git clone ${O} ${r} --depth=1`);
|
|
396
|
+
const c = se(e), i = F(e), l = g.resolve(
|
|
397
|
+
r,
|
|
398
|
+
c
|
|
399
|
+
);
|
|
400
|
+
s = JSON.parse(d.readFileSync(l, "utf-8")), process.once("exit", () => {
|
|
401
|
+
p(r) && (console.log("发现进程退出,正在清理临时目录..."), n());
|
|
402
|
+
}), await o({
|
|
403
|
+
repoUrl: O,
|
|
404
|
+
config: s,
|
|
405
|
+
cliConfigFileRelativePath: c,
|
|
406
|
+
cliConfigDirRelativePath: i,
|
|
407
|
+
configTemporaryDir: r
|
|
408
|
+
});
|
|
409
|
+
} finally {
|
|
410
|
+
n();
|
|
411
|
+
}
|
|
412
|
+
return s;
|
|
285
413
|
};
|
|
286
414
|
export {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
415
|
+
B as EditorTypeEnum,
|
|
416
|
+
Be as _curry,
|
|
417
|
+
Je as _get,
|
|
418
|
+
Ge as _set,
|
|
419
|
+
Fe as addHuskyHooks,
|
|
420
|
+
Pe as addPackageConfig,
|
|
421
|
+
Ae as chalk,
|
|
422
|
+
Re as createMainCommand,
|
|
423
|
+
Ee as createSubcommand,
|
|
424
|
+
ve as decryptAES,
|
|
425
|
+
$e as encryptAES,
|
|
426
|
+
Z as fileAddX,
|
|
427
|
+
Oe as getConfigFileCommonOptions,
|
|
428
|
+
K as getEditorType,
|
|
429
|
+
xe as getGitLastCommitInfo,
|
|
430
|
+
De as getGitProjectDir,
|
|
431
|
+
oe as getHuskyBootCode,
|
|
432
|
+
re as getHuskyRootDir,
|
|
433
|
+
R as getPackageJson,
|
|
434
|
+
Q as getRelyPkgVersion,
|
|
435
|
+
q as getRootDirOptions,
|
|
436
|
+
_e as getUseDefaultConfig,
|
|
437
|
+
z as initConfigFile,
|
|
438
|
+
ke as initHandlerCommon,
|
|
439
|
+
Me as json5,
|
|
440
|
+
a as log,
|
|
441
|
+
Se as lookForParentTarget,
|
|
442
|
+
X as openFileInEditor,
|
|
443
|
+
be as pushGitPublishInfoToRemote,
|
|
444
|
+
He as readCliConfig,
|
|
445
|
+
we as readConfigFile,
|
|
446
|
+
D as xPrompts
|
|
311
447
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha.0",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -40,10 +40,12 @@
|
|
|
40
40
|
"@types/json5": "^2.2.0",
|
|
41
41
|
"@types/lodash.curry": "^4.1.8",
|
|
42
42
|
"@types/lodash.get": "^4.4.9",
|
|
43
|
+
"@types/lodash.merge": "^4.6.9",
|
|
43
44
|
"@types/lodash.set": "^4.3.9",
|
|
44
45
|
"@types/node": "^18.0.0",
|
|
45
46
|
"@types/pinyin": "^2.10.0",
|
|
46
47
|
"@types/prompts": "^2.4.6",
|
|
48
|
+
"@types/semver": "^7.5.3",
|
|
47
49
|
"@types/yargs": "^17.0.28",
|
|
48
50
|
"rimraf": "^6.0.1",
|
|
49
51
|
"typescript": "^5.2.2",
|
|
@@ -58,10 +60,12 @@
|
|
|
58
60
|
"json5": "^2.2.3",
|
|
59
61
|
"lodash.curry": "^4.1.1",
|
|
60
62
|
"lodash.get": "^4.4.2",
|
|
63
|
+
"lodash.merge": "^4.6.2",
|
|
61
64
|
"lodash.set": "^4.3.2",
|
|
62
65
|
"pinyin": "^2.11.2",
|
|
63
66
|
"prompts": "^2.4.2",
|
|
67
|
+
"semver": "^7.5.4",
|
|
64
68
|
"yargs": "^17.7.2"
|
|
65
69
|
},
|
|
66
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
|
|
67
71
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 读取配置 */
|
|
2
|
+
export declare const readCliConfig: <R>({ moduleName, onSuccess, }: {
|
|
3
|
+
moduleName: string;
|
|
4
|
+
onSuccess: (params: {
|
|
5
|
+
repoUrl: string;
|
|
6
|
+
/** 配置文件相对路径 */
|
|
7
|
+
cliConfigFileRelativePath: string;
|
|
8
|
+
/** 配置文件目录相对路径 */
|
|
9
|
+
cliConfigDirRelativePath: string;
|
|
10
|
+
/** 配置文件内容 */
|
|
11
|
+
config: R;
|
|
12
|
+
/** 配置临时目录 */
|
|
13
|
+
configTemporaryDir: string;
|
|
14
|
+
}) => void | Promise<void>;
|
|
15
|
+
}) => Promise<R>;
|
package/types/git.d.ts
CHANGED
package/types/husky.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 获取husky引导代码 */
|
|
2
|
+
export declare const getHuskyBootCode: ({ projectRootDir, }: {
|
|
3
|
+
projectRootDir: string;
|
|
4
|
+
}) => "" | "#!/usr/bin/env sh\n. \"$(dirname -- \"$0\")/_/husky.sh\"";
|
|
5
|
+
/** 获取husky根目录 */
|
|
6
|
+
export declare const getHuskyRootDir: ({ projectRootDir, }: {
|
|
7
|
+
projectRootDir: string;
|
|
8
|
+
}) => string;
|
|
9
|
+
/** 添加 husky hooks */
|
|
10
|
+
export declare const addHuskyHooks: <H extends string>({ hookNames, projectRootDir, getCode, }: {
|
|
11
|
+
hookNames: H[];
|
|
12
|
+
/** 项目根目录 */
|
|
13
|
+
projectRootDir: string;
|
|
14
|
+
/** 获取husky hooks 添加的代码 */
|
|
15
|
+
getCode: (hook: string) => string;
|
|
16
|
+
}) => void;
|
package/types/index.d.ts
CHANGED
package/types/package-json.d.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
/** package.json文件内容 */
|
|
1
2
|
export interface PackageJson {
|
|
2
3
|
name: string;
|
|
3
4
|
version?: string;
|
|
5
|
+
bin?: Record<string, string> | string;
|
|
6
|
+
scripts?: Record<string, string>;
|
|
7
|
+
files?: string[];
|
|
8
|
+
dependencies?: Record<string, string>;
|
|
9
|
+
devDependencies?: Record<string, string>;
|
|
10
|
+
peerDependencies?: Record<string, string>;
|
|
4
11
|
}
|
|
12
|
+
/** 获取package.json文件内容 */
|
|
5
13
|
export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
6
14
|
rootDir: string;
|
|
7
15
|
}) => R;
|
|
16
|
+
/** 获取依赖包版本 */
|
|
17
|
+
export declare const getRelyPkgVersion: <R extends PackageJson>({ rootDir, pkgJson, pkgName, isDevPkg, }: {
|
|
18
|
+
rootDir: string;
|
|
19
|
+
pkgJson?: R | undefined;
|
|
20
|
+
pkgName: string;
|
|
21
|
+
/** 是开发依赖包 */
|
|
22
|
+
isDevPkg: boolean;
|
|
23
|
+
}) => string | undefined;
|
|
24
|
+
/** 添加package.json配置 */
|
|
25
|
+
export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
|
|
26
|
+
patchConfig?: Record<string, any> | undefined;
|
|
27
|
+
rootDir: string;
|
|
28
|
+
}) => void;
|