@done-coding/cli-template 0.7.11-alpha.0 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { d as m } from "./main-482a2969.js";
2
+ import { d as m } from "./main-3e20cca2.js";
3
3
  import "@done-coding/cli-utils";
4
4
  import "node:path";
5
5
  import "node:fs";
package/es/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { M as r } from "./main-482a2969.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-482a2969.js";
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,50 +1,53 @@
1
1
  #!/usr/bin/env node
2
- import { getConfigFileCommonOptions as N, getUseDefaultConfig as V, initHandlerCommon as W, log as a, xPrompts as R, readConfigFile as G, _curry as T, createSubcommand as A, createMainCommand as Y } from "@done-coding/cli-utils";
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 O from "lodash.template";
5
+ import P from "lodash.template";
6
6
  import B from "lodash.assign";
7
- var h = /* @__PURE__ */ ((e) => (e.INIT = "init", e.COMPILE = "compile", e))(h || {}), J = /* @__PURE__ */ ((e) => (e.REPOSITORY_URL = "REPOSITORY_URL", e))(J || {}), b = /* @__PURE__ */ ((e) => (e.OVERWRITE = "overwrite", e.APPEND = "append", e.REPLACE = "replace", e.RETURN = "return", e))(b || {});
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.11-alpha.0",
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: K, moduleName: q }
18
- } = _, z = `./${K}/${q}`, I = `${z}.json`, v = {
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
- }, S = (e) => {
27
+ }, _ = (e) => {
25
28
  const {
26
29
  rollback: t,
27
- dealMarkdown: s,
30
+ dealMarkdown: l,
28
31
  mode: c,
29
- batch: l,
32
+ batch: s,
30
33
  rootDir: o,
31
34
  configPath: i,
32
35
  rollbackDelNullFile: r,
33
36
  ...u
34
- } = e, { rootDir: g, configPath: D } = N({
35
- configPathDefault: I
37
+ } = e, { rootDir: g, configPath: D } = I({
38
+ configPathDefault: h
36
39
  });
37
40
  return {
38
41
  rollback: t ?? v.rollback,
39
42
  rollbackDelNullFile: r ?? v.rollbackDelNullFile,
40
- dealMarkdown: s ?? v.dealMarkdown,
43
+ dealMarkdown: l ?? v.dealMarkdown,
41
44
  mode: c ?? v.mode,
42
- batch: l ?? v.batch,
45
+ batch: s ?? v.batch,
43
46
  rootDir: o ?? g.default,
44
47
  configPath: i ?? D.default,
45
48
  ...u
46
49
  };
47
- }, Z = () => ({
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
- ...N({
104
- configPathDefault: I
106
+ ...I({
107
+ configPathDefault: h
105
108
  })
106
- }), Q = {
109
+ }), X = {
107
110
  globalEnvData: {},
108
111
  collectEnvDataForm: [
109
112
  {
@@ -138,14 +141,14 @@ const _ = {
138
141
  mode: "replace"
139
142
  }
140
143
  ]
141
- }, X = () => N({
142
- configPathDefault: I
143
- }), ee = async (e) => {
144
+ }, ee = () => I({
145
+ configPathDefault: h
146
+ }), te = async (e) => {
144
147
  let t = {};
145
148
  if (e)
146
- t = Q;
149
+ t = X;
147
150
  else {
148
- const { globalEnvCount: s, collectEnvCount: c, compileFileCount: l } = await R([
151
+ const { globalEnvCount: l, collectEnvCount: c, compileFileCount: s } = await R([
149
152
  {
150
153
  name: "globalEnvCount",
151
154
  type: "number",
@@ -171,16 +174,16 @@ const _ = {
171
174
  validate: (o) => o >= 0
172
175
  }
173
176
  ]);
174
- s && (t.globalEnvData = Array.from({
175
- length: s
177
+ l && (t.globalEnvData = Array.from({
178
+ length: l
176
179
  }).reduce((o, i, r) => (o[`GLOBAL_${r}`] = "", o), {})), c && (t.collectEnvDataForm = Array.from({
177
180
  length: c
178
181
  }).map((o, i) => ({
179
182
  key: `COLLECT_KEY_${i}`,
180
183
  label: `COLLECT_LABEL_${i}`,
181
184
  initial: void 0
182
- }))), l && (t.list = Array.from({
183
- length: l
185
+ }))), s && (t.list = Array.from({
186
+ length: s
184
187
  }).map((o, i) => ({
185
188
  input: `(相对于命令运行目录)需要编译的模板文件路径${i}`,
186
189
  output: `(相对于命令运行目录)编译后输出的文件路径${i}`,
@@ -188,9 +191,9 @@ const _ = {
188
191
  })));
189
192
  }
190
193
  return t;
191
- }, te = async (e) => {
192
- const t = await V(), s = await ee(t);
193
- await W(s, e, {
194
+ }, ne = async (e) => {
195
+ const t = await V(), l = await te(t);
196
+ await W(l, e, {
194
197
  edit: !0,
195
198
  onFileGenerated(c) {
196
199
  t || a.success(`配置文件已生成:${c}
@@ -204,15 +207,15 @@ const _ = {
204
207
  }, x = ({
205
208
  rootDir: e,
206
209
  filePath: t,
207
- dataInit: s,
210
+ dataInit: l,
208
211
  limitJson: c,
209
- filePathKey: l,
212
+ filePathKey: s,
210
213
  dataInitKey: o,
211
214
  dealMarkdown: i = !1
212
215
  }) => {
213
216
  if (t) {
214
217
  if (c && !t.endsWith(".json"))
215
- return a.error(`${l}必须是json文件,请检查文件后缀名`), process.exit(1);
218
+ return a.error(`${s}必须是json文件,请检查文件后缀名`), process.exit(1);
216
219
  const r = f.readFileSync(
217
220
  k.resolve(e, t),
218
221
  "utf-8"
@@ -223,23 +226,23 @@ const _ = {
223
226
  "$1"
224
227
  )), c ? JSON.parse(u) : u;
225
228
  } else
226
- return s ? (a.info(`${l} 为空,将使用${o}作为数据`), c ? JSON.parse(s) : s) : (a.error(`${l}与${o}不能同时为空`), process.exit(1));
227
- }, P = (e, t) => {
229
+ return l ? (a.info(`${s} 为空,将使用${o}作为数据`), c ? JSON.parse(l) : l) : (a.error(`${s}与${o}不能同时为空`), process.exit(1));
230
+ }, w = (e, t) => {
228
231
  if (!t)
229
232
  return a.error(`${e}模式下output不能为空`), process.exit(1);
230
- }, w = (e, t) => {
233
+ }, F = (e, t) => {
231
234
  if (t && e === t)
232
235
  return a.error("output与input不能相同"), process.exit(1);
233
- }, ne = (e, t) => {
236
+ }, ae = (e, t) => {
234
237
  if (!t)
235
238
  return a.error(`${e}模式下input不能为空`), process.exit(1);
236
239
  }, M = async (e, {
237
240
  rootDir: t,
238
- rollbackDelFileAgree: s = !1
241
+ rollbackDelFileAgree: l = !1
239
242
  }) => {
240
243
  const {
241
244
  env: c,
242
- input: l,
245
+ input: s,
243
246
  inputData: o,
244
247
  output: i,
245
248
  mode: r,
@@ -262,20 +265,20 @@ rollback: ${u}
262
265
  `);
263
266
  const m = x({
264
267
  rootDir: t,
265
- filePath: l,
268
+ filePath: s,
266
269
  dataInit: o,
267
270
  limitJson: !1,
268
271
  filePathKey: "input",
269
272
  dataInitKey: "inputData",
270
273
  dealMarkdown: D
271
- }), d = O(m), C = typeof E == "function" ? E() : E, p = d(C);
274
+ }), d = P(m), C = typeof E == "function" ? E() : E, p = d(C);
272
275
  switch (r) {
273
276
  case b.OVERWRITE: {
274
- P(r, i), w(i, l);
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)
278
- if (s || (await R({
281
+ if (l || (await R({
279
282
  type: "confirm",
280
283
  name: "remove",
281
284
  message: `${r}模式下回滚将删除${n},是否继续?`
@@ -298,13 +301,13 @@ rollback: ${u}
298
301
  break;
299
302
  }
300
303
  case b.APPEND: {
301
- P(r, i), w(i, l);
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 L = $.replace(p, "");
307
- L || !g ? f.writeFileSync(n, L, "utf-8") : (a.stage(`${r}模式下 文件为空 删除`), f.unlinkSync(n)), a.success(`${r}模式下${n}回滚完成`);
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} 将被忽略`), ne(r, l), c && c === l)
325
+ if (i && a.warn(`output ${i} 将被忽略`), ae(r, s), c && c === s)
323
326
  return a.error("env 与 input 不能相同"), process.exit(1);
324
- const n = k.resolve(t, l);
327
+ const n = k.resolve(t, s);
325
328
  let $ = n;
326
- const y = O(n)(C);
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,14 +337,14 @@ rollback: ${u}
334
337
  return a.error(`mode ${r} 不支持`), process.exit(1);
335
338
  }
336
339
  return p;
337
- }, ae = async ({
340
+ }, oe = async ({
338
341
  rootDir: e,
339
- configPath: t = I,
340
- itemDefaultRollback: s = !1,
342
+ configPath: t = h,
343
+ itemDefaultRollback: l = !1,
341
344
  extraEnvData: c = {}
342
- }, l) => {
345
+ }, s) => {
343
346
  let o;
344
- if (l ? o = l : o = await G({
347
+ if (s ? o = s : o = await G({
345
348
  rootDir: e,
346
349
  configPath: t
347
350
  }), !o)
@@ -363,13 +366,13 @@ rollback: ${u}
363
366
  }))[d];
364
367
  }
365
368
  const D = i.map((m) => {
366
- const { rollback: d = s } = m, {
369
+ const { rollback: d = l } = m, {
367
370
  envData: C,
368
371
  env: p,
369
372
  input: n,
370
373
  output: $,
371
374
  ...y
372
- } = S(m);
375
+ } = _(m);
373
376
  return p && a.warn(`批量处理中 env:${p} 将被忽略, 只读envData`), {
374
377
  ...y,
375
378
  env: p,
@@ -393,12 +396,12 @@ rollback: ${u}
393
396
  E.push(d);
394
397
  }
395
398
  return E;
396
- }, oe = async (e) => {
399
+ }, re = async (e) => {
397
400
  const {
398
401
  envData: t,
399
- env: s,
402
+ env: l,
400
403
  input: c,
401
- inputData: l,
404
+ inputData: s,
402
405
  output: o,
403
406
  mode: i,
404
407
  rollback: r,
@@ -407,9 +410,9 @@ rollback: ${u}
407
410
  batch: D,
408
411
  rootDir: E,
409
412
  configPath: m
410
- } = S(e);
413
+ } = _(e);
411
414
  if (D)
412
- return a.stage("开始批量处理"), ae({
415
+ return a.stage("开始批量处理"), oe({
413
416
  // 回滚默认值 基于全局
414
417
  itemDefaultRollback: r,
415
418
  rootDir: E,
@@ -418,7 +421,7 @@ rollback: ${u}
418
421
  a.stage("开始单个处理");
419
422
  const d = x({
420
423
  rootDir: E,
421
- filePath: s,
424
+ filePath: l,
422
425
  dataInit: t,
423
426
  limitJson: !0,
424
427
  filePathKey: "env",
@@ -428,7 +431,7 @@ rollback: ${u}
428
431
  return M(
429
432
  {
430
433
  input: c,
431
- inputData: l,
434
+ inputData: s,
432
435
  output: o,
433
436
  mode: i,
434
437
  rollback: r,
@@ -440,50 +443,51 @@ rollback: ${u}
440
443
  rootDir: E
441
444
  }
442
445
  );
443
- }, U = async (e, t) => e === h.INIT ? te(t) : e === h.COMPILE ? oe(t) : (a.error(`无效的命令: ${e}`), process.exit(1)), {
444
- version: re,
445
- description: ie,
446
- cliConfig: { moduleName: F }
447
- } = _, le = {
448
- command: h.INIT,
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: X(),
451
- handler: T(U)(
452
- h.INIT
453
+ options: ee(),
454
+ handler: A(U)(
455
+ N.INIT
453
456
  )
454
- }, se = {
455
- command: h.COMPILE,
457
+ }, ce = {
458
+ command: N.COMPILE,
456
459
  describe: "编译模板",
457
- options: Z(),
458
- handler: T(U)(
459
- h.COMPILE
460
+ options: Q(),
461
+ handler: A(U)(
462
+ N.COMPILE
460
463
  )
461
464
  }, j = {
462
- describe: ie,
463
- version: re,
464
- subcommands: [le, se].map(
465
- A
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 ? F : void 0, s = `$0${e ? ` ${F}` : ""} <command> [options]`;
470
- return { command: t, usage: s };
471
- }, de = async () => Y({
473
+ const t = e ? T : void 0, l = `$0${e ? ` ${T}` : ""} <command> [options]`;
474
+ return { command: t, usage: l };
475
+ }, be = async () => Y({
472
476
  ...j,
473
477
  ...H()
474
- }), be = () => A({
478
+ }), Ee = () => S({
475
479
  ...j,
476
480
  ...H(!0)
477
481
  });
478
482
  export {
479
- I as M,
483
+ h as M,
480
484
  b as O,
481
- h as S,
482
- J as T,
483
- be as a,
484
- ae as b,
485
- oe as c,
486
- de as d,
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
- te as i
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.11-alpha.0",
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.11-alpha.0",
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.1",
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": "dcc654349de82facba0b8d58c0001adb18144236"
61
+ "gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae"
62
62
  }