@done-coding/cli-template 0.7.11 → 0.7.12-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/cli.mjs +1 -1
- package/es/index.mjs +2 -2
- package/es/{main-3510f696.js → main-3e20cca2.js} +65 -61
- package/package.json +4 -4
package/es/cli.mjs
CHANGED
package/es/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { M as r } from "./main-
|
|
3
|
-
import { O as E, S as h, T as b, b as T, c as A, a as H, h as O, i as S } from "./main-
|
|
2
|
+
import { M as r } from "./main-3e20cca2.js";
|
|
3
|
+
import { O as E, S as h, T as b, b as T, c as A, a as H, h as O, i as S } from "./main-3e20cca2.js";
|
|
4
4
|
import t from "node:path";
|
|
5
5
|
import { existsSync as n } from "node:fs";
|
|
6
6
|
import "@done-coding/cli-utils";
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { getConfigFileCommonOptions as
|
|
2
|
+
import { getConfigFileCommonOptions as I, getUseDefaultConfig as V, initHandlerCommon as W, log as a, xPrompts as R, readConfigFile as G, _curry as A, createSubcommand as S, getRootScriptName as J, createMainCommand as Y } from "@done-coding/cli-utils";
|
|
3
3
|
import k from "node:path";
|
|
4
4
|
import f from "node:fs";
|
|
5
|
-
import
|
|
5
|
+
import P from "lodash.template";
|
|
6
6
|
import B from "lodash.assign";
|
|
7
|
-
var
|
|
8
|
-
const
|
|
7
|
+
var N = /* @__PURE__ */ ((e) => (e.INIT = "init", e.COMPILE = "compile", e))(N || {}), K = /* @__PURE__ */ ((e) => (e.REPOSITORY_URL = "REPOSITORY_URL", e))(K || {}), b = /* @__PURE__ */ ((e) => (e.OVERWRITE = "overwrite", e.APPEND = "append", e.REPLACE = "replace", e.RETURN = "return", e))(b || {});
|
|
8
|
+
const L = {
|
|
9
9
|
name: "@done-coding/cli-template",
|
|
10
|
-
version: "0.7.
|
|
10
|
+
version: "0.7.12-alpha.0",
|
|
11
11
|
description: "预编译命令行工具",
|
|
12
|
+
bin: {
|
|
13
|
+
"dc-template": "es/cli.mjs"
|
|
14
|
+
},
|
|
12
15
|
cliConfig: {
|
|
13
16
|
namespaceDir: ".done-coding",
|
|
14
17
|
moduleName: "template"
|
|
15
18
|
}
|
|
16
19
|
}, {
|
|
17
|
-
cliConfig: { namespaceDir:
|
|
18
|
-
} =
|
|
20
|
+
cliConfig: { namespaceDir: q, moduleName: z }
|
|
21
|
+
} = L, Z = `./${q}/${z}`, h = `${Z}.json`, v = {
|
|
19
22
|
rollback: !1,
|
|
20
23
|
dealMarkdown: !1,
|
|
21
24
|
mode: b.OVERWRITE,
|
|
22
25
|
batch: !1,
|
|
23
26
|
rollbackDelNullFile: !1
|
|
24
|
-
},
|
|
27
|
+
}, _ = (e) => {
|
|
25
28
|
const {
|
|
26
29
|
rollback: t,
|
|
27
30
|
dealMarkdown: l,
|
|
@@ -31,7 +34,7 @@ const _ = {
|
|
|
31
34
|
configPath: i,
|
|
32
35
|
rollbackDelNullFile: r,
|
|
33
36
|
...u
|
|
34
|
-
} = e, { rootDir: g, configPath: D } =
|
|
37
|
+
} = e, { rootDir: g, configPath: D } = I({
|
|
35
38
|
configPathDefault: h
|
|
36
39
|
});
|
|
37
40
|
return {
|
|
@@ -44,7 +47,7 @@ const _ = {
|
|
|
44
47
|
configPath: i ?? D.default,
|
|
45
48
|
...u
|
|
46
49
|
};
|
|
47
|
-
},
|
|
50
|
+
}, Q = () => ({
|
|
48
51
|
env: {
|
|
49
52
|
alias: "e",
|
|
50
53
|
describe: "环境数据文件JSON文件相对路径(优先级高于envData)",
|
|
@@ -100,10 +103,10 @@ const _ = {
|
|
|
100
103
|
type: "boolean",
|
|
101
104
|
default: v.batch
|
|
102
105
|
},
|
|
103
|
-
...
|
|
106
|
+
...I({
|
|
104
107
|
configPathDefault: h
|
|
105
108
|
})
|
|
106
|
-
}),
|
|
109
|
+
}), X = {
|
|
107
110
|
globalEnvData: {},
|
|
108
111
|
collectEnvDataForm: [
|
|
109
112
|
{
|
|
@@ -138,12 +141,12 @@ const _ = {
|
|
|
138
141
|
mode: "replace"
|
|
139
142
|
}
|
|
140
143
|
]
|
|
141
|
-
},
|
|
144
|
+
}, ee = () => I({
|
|
142
145
|
configPathDefault: h
|
|
143
|
-
}),
|
|
146
|
+
}), te = async (e) => {
|
|
144
147
|
let t = {};
|
|
145
148
|
if (e)
|
|
146
|
-
t =
|
|
149
|
+
t = X;
|
|
147
150
|
else {
|
|
148
151
|
const { globalEnvCount: l, collectEnvCount: c, compileFileCount: s } = await R([
|
|
149
152
|
{
|
|
@@ -188,8 +191,8 @@ const _ = {
|
|
|
188
191
|
})));
|
|
189
192
|
}
|
|
190
193
|
return t;
|
|
191
|
-
},
|
|
192
|
-
const t = await V(), l = await
|
|
194
|
+
}, ne = async (e) => {
|
|
195
|
+
const t = await V(), l = await te(t);
|
|
193
196
|
await W(l, e, {
|
|
194
197
|
edit: !0,
|
|
195
198
|
onFileGenerated(c) {
|
|
@@ -224,13 +227,13 @@ const _ = {
|
|
|
224
227
|
)), c ? JSON.parse(u) : u;
|
|
225
228
|
} else
|
|
226
229
|
return l ? (a.info(`${s} 为空,将使用${o}作为数据`), c ? JSON.parse(l) : l) : (a.error(`${s}与${o}不能同时为空`), process.exit(1));
|
|
227
|
-
},
|
|
230
|
+
}, w = (e, t) => {
|
|
228
231
|
if (!t)
|
|
229
232
|
return a.error(`${e}模式下output不能为空`), process.exit(1);
|
|
230
|
-
},
|
|
233
|
+
}, F = (e, t) => {
|
|
231
234
|
if (t && e === t)
|
|
232
235
|
return a.error("output与input不能相同"), process.exit(1);
|
|
233
|
-
},
|
|
236
|
+
}, ae = (e, t) => {
|
|
234
237
|
if (!t)
|
|
235
238
|
return a.error(`${e}模式下input不能为空`), process.exit(1);
|
|
236
239
|
}, M = async (e, {
|
|
@@ -268,10 +271,10 @@ rollback: ${u}
|
|
|
268
271
|
filePathKey: "input",
|
|
269
272
|
dataInitKey: "inputData",
|
|
270
273
|
dealMarkdown: D
|
|
271
|
-
}), d =
|
|
274
|
+
}), d = P(m), C = typeof E == "function" ? E() : E, p = d(C);
|
|
272
275
|
switch (r) {
|
|
273
276
|
case b.OVERWRITE: {
|
|
274
|
-
|
|
277
|
+
w(r, i), F(i, s);
|
|
275
278
|
const n = k.resolve(t, i);
|
|
276
279
|
if (f.mkdirSync(k.dirname(n), { recursive: !0 }), f.existsSync(n)) {
|
|
277
280
|
if (u)
|
|
@@ -298,13 +301,13 @@ rollback: ${u}
|
|
|
298
301
|
break;
|
|
299
302
|
}
|
|
300
303
|
case b.APPEND: {
|
|
301
|
-
|
|
304
|
+
w(r, i), F(i, s);
|
|
302
305
|
const n = k.resolve(t, i);
|
|
303
306
|
if (f.mkdirSync(k.dirname(n), { recursive: !0 }), f.existsSync(n)) {
|
|
304
307
|
const $ = f.readFileSync(n, "utf-8");
|
|
305
308
|
if (u) {
|
|
306
|
-
const
|
|
307
|
-
|
|
309
|
+
const O = $.replace(p, "");
|
|
310
|
+
O || !g ? f.writeFileSync(n, O, "utf-8") : (a.stage(`${r}模式下 文件为空 删除`), f.unlinkSync(n)), a.success(`${r}模式下${n}回滚完成`);
|
|
308
311
|
return;
|
|
309
312
|
}
|
|
310
313
|
const y = $ + p;
|
|
@@ -319,11 +322,11 @@ rollback: ${u}
|
|
|
319
322
|
break;
|
|
320
323
|
}
|
|
321
324
|
case b.REPLACE: {
|
|
322
|
-
if (i && a.warn(`output ${i} 将被忽略`),
|
|
325
|
+
if (i && a.warn(`output ${i} 将被忽略`), ae(r, s), c && c === s)
|
|
323
326
|
return a.error("env 与 input 不能相同"), process.exit(1);
|
|
324
327
|
const n = k.resolve(t, s);
|
|
325
328
|
let $ = n;
|
|
326
|
-
const y =
|
|
329
|
+
const y = P(n)(C);
|
|
327
330
|
y !== n && (a.success(`检测输入文件名也需要替换
|
|
328
331
|
${n} => ${y}`), f.rmSync(n), $ = y), f.mkdirSync(k.dirname($), { recursive: !0 }), f.writeFileSync($, p, "utf-8"), a.success(`模板处理完成,输出到 ${$}`);
|
|
329
332
|
break;
|
|
@@ -334,7 +337,7 @@ rollback: ${u}
|
|
|
334
337
|
return a.error(`mode ${r} 不支持`), process.exit(1);
|
|
335
338
|
}
|
|
336
339
|
return p;
|
|
337
|
-
},
|
|
340
|
+
}, oe = async ({
|
|
338
341
|
rootDir: e,
|
|
339
342
|
configPath: t = h,
|
|
340
343
|
itemDefaultRollback: l = !1,
|
|
@@ -369,7 +372,7 @@ rollback: ${u}
|
|
|
369
372
|
input: n,
|
|
370
373
|
output: $,
|
|
371
374
|
...y
|
|
372
|
-
} =
|
|
375
|
+
} = _(m);
|
|
373
376
|
return p && a.warn(`批量处理中 env:${p} 将被忽略, 只读envData`), {
|
|
374
377
|
...y,
|
|
375
378
|
env: p,
|
|
@@ -393,7 +396,7 @@ rollback: ${u}
|
|
|
393
396
|
E.push(d);
|
|
394
397
|
}
|
|
395
398
|
return E;
|
|
396
|
-
},
|
|
399
|
+
}, re = async (e) => {
|
|
397
400
|
const {
|
|
398
401
|
envData: t,
|
|
399
402
|
env: l,
|
|
@@ -407,9 +410,9 @@ rollback: ${u}
|
|
|
407
410
|
batch: D,
|
|
408
411
|
rootDir: E,
|
|
409
412
|
configPath: m
|
|
410
|
-
} =
|
|
413
|
+
} = _(e);
|
|
411
414
|
if (D)
|
|
412
|
-
return a.stage("开始批量处理"),
|
|
415
|
+
return a.stage("开始批量处理"), oe({
|
|
413
416
|
// 回滚默认值 基于全局
|
|
414
417
|
itemDefaultRollback: r,
|
|
415
418
|
rootDir: E,
|
|
@@ -440,50 +443,51 @@ rollback: ${u}
|
|
|
440
443
|
rootDir: E
|
|
441
444
|
}
|
|
442
445
|
);
|
|
443
|
-
}, U = async (e, t) => e ===
|
|
444
|
-
version:
|
|
445
|
-
description:
|
|
446
|
-
cliConfig: { moduleName:
|
|
447
|
-
} =
|
|
448
|
-
command:
|
|
446
|
+
}, U = async (e, t) => e === N.INIT ? ne(t) : e === N.COMPILE ? re(t) : (a.error(`无效的命令: ${e}`), process.exit(1)), {
|
|
447
|
+
version: ie,
|
|
448
|
+
description: se,
|
|
449
|
+
cliConfig: { moduleName: T }
|
|
450
|
+
} = L, le = {
|
|
451
|
+
command: N.INIT,
|
|
449
452
|
describe: "初始化模板配置文件",
|
|
450
|
-
options:
|
|
451
|
-
handler:
|
|
452
|
-
|
|
453
|
+
options: ee(),
|
|
454
|
+
handler: A(U)(
|
|
455
|
+
N.INIT
|
|
453
456
|
)
|
|
454
|
-
},
|
|
455
|
-
command:
|
|
457
|
+
}, ce = {
|
|
458
|
+
command: N.COMPILE,
|
|
456
459
|
describe: "编译模板",
|
|
457
|
-
options:
|
|
458
|
-
handler:
|
|
459
|
-
|
|
460
|
+
options: Q(),
|
|
461
|
+
handler: A(U)(
|
|
462
|
+
N.COMPILE
|
|
460
463
|
)
|
|
461
464
|
}, j = {
|
|
462
|
-
describe:
|
|
463
|
-
version:
|
|
464
|
-
subcommands: [
|
|
465
|
-
|
|
465
|
+
describe: se,
|
|
466
|
+
version: ie,
|
|
467
|
+
subcommands: [le, ce].map(
|
|
468
|
+
S
|
|
466
469
|
),
|
|
467
|
-
demandCommandCount: 1
|
|
470
|
+
demandCommandCount: 1,
|
|
471
|
+
rootScriptName: J({ packageJson: L })
|
|
468
472
|
}, H = (e = !1) => {
|
|
469
|
-
const t = e ?
|
|
473
|
+
const t = e ? T : void 0, l = `$0${e ? ` ${T}` : ""} <command> [options]`;
|
|
470
474
|
return { command: t, usage: l };
|
|
471
|
-
},
|
|
475
|
+
}, be = async () => Y({
|
|
472
476
|
...j,
|
|
473
477
|
...H()
|
|
474
|
-
}),
|
|
478
|
+
}), Ee = () => S({
|
|
475
479
|
...j,
|
|
476
480
|
...H(!0)
|
|
477
481
|
});
|
|
478
482
|
export {
|
|
479
483
|
h as M,
|
|
480
484
|
b as O,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
485
|
+
N as S,
|
|
486
|
+
K as T,
|
|
487
|
+
Ee as a,
|
|
488
|
+
oe as b,
|
|
489
|
+
re as c,
|
|
490
|
+
be as d,
|
|
487
491
|
U as h,
|
|
488
|
-
|
|
492
|
+
ne as i
|
|
489
493
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-template",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12-alpha.0",
|
|
4
4
|
"description": "预编译命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@done-coding/cli-inject": "^0.5.
|
|
43
|
+
"@done-coding/cli-inject": "^0.5.12-alpha.0",
|
|
44
44
|
"@types/lodash.assign": "^4.2.9",
|
|
45
45
|
"@types/lodash.template": "^4.5.3",
|
|
46
46
|
"@types/node": "^18.0.0",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"node": ">=18.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@done-coding/cli-utils": "^0.7.
|
|
57
|
+
"@done-coding/cli-utils": "^0.7.3-alpha.0",
|
|
58
58
|
"lodash.assign": "^4.2.0",
|
|
59
59
|
"lodash.template": "^4.5.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae"
|
|
62
62
|
}
|