@done-coding/cli-extract 0.1.10 → 0.1.11-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 { c as m } from "./index-e4f5918d.js";
2
+ import { c as m } from "./index-fae67bc6.js";
3
3
  import "./index-a1ee6691-8c73eb4d.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
@@ -1,43 +1,43 @@
1
1
  #!/usr/bin/env node
2
- import { a as r, e as T, E as u, S as h, G as $ } from "./index-a1ee6691-8c73eb4d.js";
3
- import { log as s, _get as b, createSubcommand as N, getConfigFileCommonOptions as D, initHandlerCommon as v, readConfigFile as F, _set as L, createMainCommand as V } from "@done-coding/cli-utils";
2
+ import { a as r, e as T, E as u, S as h, G as F } from "./index-a1ee6691-8c73eb4d.js";
3
+ import { log as s, _get as b, createSubcommand as I, getConfigFileCommonOptions as D, initHandlerCommon as v, readConfigFile as J, _set as V, createMainCommand as U } from "@done-coding/cli-utils";
4
4
  import j from "node:path";
5
5
  import y from "node:fs";
6
- import { OutputModeEnum as U, batchCompileHandler as W } from "@done-coding/cli-template";
7
- const O = {
6
+ import { OutputModeEnum as W, batchCompileHandler as H } from "@done-coding/cli-template";
7
+ const N = {
8
8
  name: "@done-coding/cli-extract",
9
- version: "0.1.10",
9
+ version: "0.1.11-alpha.0",
10
10
  description: "信息提取命令行工具",
11
11
  cliConfig: {
12
12
  namespaceDir: ".done-coding",
13
13
  moduleName: "extract"
14
14
  }
15
15
  }, {
16
- cliConfig: { namespaceDir: H, moduleName: X }
17
- } = O, K = `./${H}/${X}`, J = `${K}.json5`, C = ({
16
+ cliConfig: { namespaceDir: X, moduleName: K }
17
+ } = N, q = `./${X}/${K}`, S = `${q}.json5`, C = ({
18
18
  sourceJson: e,
19
19
  targetKey: n,
20
- keyConfig: o
20
+ keyConfig: t
21
21
  }) => {
22
- let t;
23
- typeof o == "string" ? t = {
22
+ let o;
23
+ typeof t == "string" ? o = {
24
24
  type: r.FIXED,
25
- value: o
26
- } : t = o;
27
- const { type: a = r.READ } = t;
25
+ value: t
26
+ } : o = t;
27
+ const { type: a = r.READ } = o;
28
28
  switch (a) {
29
29
  case r.REG: {
30
- const { sourceKey: c, pattern: p, replaceValue: l, flags: f } = t, d = new RegExp(p, f ?? void 0), i = b(e, c);
30
+ const { sourceKey: c, pattern: m, replaceValue: l, flags: f } = o, d = new RegExp(m, f ?? void 0), i = b(e, c);
31
31
  return typeof i == "string" ? i.replace(d, l) : (s.warn(
32
32
  `${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
33
33
  ), i);
34
34
  }
35
35
  case r.FIXED: {
36
- const { value: c } = t;
36
+ const { value: c } = o;
37
37
  return c;
38
38
  }
39
39
  case r.READ: {
40
- const { sourceKey: c = n } = t;
40
+ const { sourceKey: c = n } = o;
41
41
  return b(e, c);
42
42
  }
43
43
  default: {
@@ -45,17 +45,17 @@ const O = {
45
45
  return;
46
46
  }
47
47
  }
48
- }, S = {
48
+ }, A = {
49
49
  name: "@done-coding/cli-inject",
50
- version: "0.5.10",
50
+ version: "0.5.11-alpha.0",
51
51
  description: "信息(JSON)注入命令行工具",
52
52
  cliConfig: {
53
53
  namespaceDir: ".done-coding",
54
54
  moduleName: "inject"
55
55
  }
56
56
  }, {
57
- cliConfig: { namespaceDir: q, moduleName: z }
58
- } = S, B = `./${q}/${z}`, A = `${B}.json`, x = {
57
+ cliConfig: { namespaceDir: z, moduleName: B }
58
+ } = A, Q = `./${z}/${B}`, x = `${Q}.json`, O = {
59
59
  sourceFilePath: "./package.json",
60
60
  keyConfigMap: {
61
61
  name: {
@@ -69,84 +69,84 @@ const O = {
69
69
  }
70
70
  },
71
71
  injectFilePath: "./src/injectInfo.json"
72
- }, Q = () => D({
73
- configPathDefault: A
74
- }), Y = async (e) => v(x, e, {
72
+ }, Y = () => D({
73
+ configPathDefault: x
74
+ }), Z = async (e) => v(O, e, {
75
75
  onFileGenerated: () => {
76
76
  s.info("文件生成成功");
77
77
  }
78
- }), Z = {
78
+ }), ee = {
79
79
  command: T.INIT,
80
80
  describe: "初始化配置文件",
81
- options: Q(),
82
- handler: Y
83
- }, ee = () => ({
81
+ options: Y(),
82
+ handler: Z
83
+ }, ne = () => ({
84
84
  ...D({
85
- configPathDefault: A
85
+ configPathDefault: x
86
86
  })
87
- }), ne = async ({
87
+ }), oe = async ({
88
88
  rootDir: e = process.cwd(),
89
- config: n = x,
90
- keyConfigMap: o = {}
89
+ config: n = O,
90
+ keyConfigMap: t = {}
91
91
  } = {}) => {
92
92
  const {
93
- sourceFilePath: t,
93
+ sourceFilePath: o,
94
94
  keyConfigMap: a,
95
95
  injectFilePath: c
96
- } = n, p = {
96
+ } = n, m = {
97
97
  ...a,
98
- ...o
98
+ ...t
99
99
  };
100
- if (!t.endsWith(".json"))
100
+ if (!o.endsWith(".json"))
101
101
  return s.error("源文件必须是json"), process.exit(1);
102
102
  if (!c.endsWith(".json"))
103
103
  return s.error("注入文件必须是json"), process.exit(1);
104
- const l = j.resolve(e, t), f = y.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(p).reduce(
105
- (g, [R, P]) => {
106
- const M = C({ sourceJson: d, targetKey: R, keyConfig: P });
107
- return L(g, R, M), g;
104
+ const l = j.resolve(e, o), f = y.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(m).reduce(
105
+ (g, [R, M]) => {
106
+ const L = C({ sourceJson: d, targetKey: R, keyConfig: M });
107
+ return V(g, R, L), g;
108
108
  },
109
109
  {}
110
- ), m = j.resolve(e, c), E = JSON.stringify(i, null, 2);
111
- if (y.existsSync(m)) {
112
- const g = y.readFileSync(m, "utf-8");
110
+ ), p = j.resolve(e, c), E = JSON.stringify(i, null, 2);
111
+ if (y.existsSync(p)) {
112
+ const g = y.readFileSync(p, "utf-8");
113
113
  if (E === g)
114
114
  return s.skip("注入文件已存在且内容相同,无需重复注入"), i;
115
115
  s.stage("文件内容变化,开始覆盖注入文件");
116
116
  } else
117
117
  s.stage("开始注入文件");
118
- y.writeFileSync(m, E), s.success(`文件注入成功: ${m}`), s.info(E);
118
+ y.writeFileSync(p, E), s.success(`文件注入成功: ${p}`), s.info(E);
119
119
  }, te = async (e) => {
120
- const n = await F(e);
120
+ const n = await J(e, () => (s.info("配置文件为空,使用默认配置"), O));
121
121
  if (!n)
122
122
  return s.error("配置文件为空"), process.exit(1);
123
- const { rootDir: o } = e;
124
- await ne({ rootDir: o, config: n });
125
- }, oe = {
123
+ const { rootDir: t } = e;
124
+ await oe({ rootDir: t, config: n });
125
+ }, se = {
126
126
  command: T.GENERATE,
127
127
  describe: "生成文件",
128
- options: ee(),
128
+ options: ne(),
129
129
  handler: te
130
- }, { version: se, description: re } = S;
131
- [Z, oe].map(
132
- N
130
+ }, { version: re, description: ce } = A;
131
+ [ee, se].map(
132
+ I
133
133
  );
134
- const ce = ({
134
+ const ie = ({
135
135
  input: e,
136
136
  rootDir: n
137
137
  }) => {
138
- const o = j.resolve(n, e), t = y.readFileSync(o, "utf-8");
139
- return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
140
- }, ie = (e) => typeof e == "object" && !!e, ae = ({
138
+ const t = j.resolve(n, e), o = y.readFileSync(t, "utf-8");
139
+ return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(o) : o;
140
+ }, ae = (e) => typeof e == "object" && !!e, ue = ({
141
141
  content: e,
142
142
  targetKey: n,
143
- keyConfig: o
143
+ keyConfig: t
144
144
  }) => {
145
- const { type: t, ...a } = o;
146
- switch (t) {
145
+ const { type: o, ...a } = t;
146
+ switch (o) {
147
147
  case u.REG: {
148
148
  if (typeof e != "string")
149
- throw new Error(`${t} 类型的keyConfig需要content为字符串`);
149
+ throw new Error(`${o} 类型的keyConfig需要content为字符串`);
150
150
  return C({
151
151
  sourceJson: {
152
152
  [n]: e
@@ -160,12 +160,12 @@ const ce = ({
160
160
  });
161
161
  }
162
162
  case u.JSON_INJECT: {
163
- if (!ie(e))
164
- throw new Error(`${t} 类型的keyConfig需要content为json`);
163
+ if (!ae(e))
164
+ throw new Error(`${o} 类型的keyConfig需要content为json`);
165
165
  return C({
166
166
  sourceJson: e,
167
167
  targetKey: n,
168
- keyConfig: o.inject
168
+ keyConfig: t.inject
169
169
  });
170
170
  }
171
171
  case u.FIXED:
@@ -178,13 +178,13 @@ const ce = ({
178
178
  }
179
179
  });
180
180
  default:
181
- throw new Error(`不支持的类型${t}`);
181
+ throw new Error(`不支持的类型${o}`);
182
182
  }
183
- }, ue = {
183
+ }, de = {
184
184
  name: "${name}",
185
185
  version: "${version}",
186
186
  description: "${description}"
187
- }, de = {
187
+ }, G = {
188
188
  extractInput: {
189
189
  "./package.json": {
190
190
  name: {
@@ -222,50 +222,50 @@ const ce = ({
222
222
  extractOutput: {
223
223
  list: [
224
224
  {
225
- mode: U.OVERWRITE,
226
- inputData: JSON.stringify(ue, null, 2),
225
+ mode: W.OVERWRITE,
226
+ inputData: JSON.stringify(de, null, 2),
227
227
  output: "./src/extractInfo.json"
228
228
  }
229
229
  ]
230
230
  }
231
- }, me = () => D({
232
- configPathDefault: J
233
- }), G = async (e) => v(de, e, {
231
+ }, pe = () => D({
232
+ configPathDefault: S
233
+ }), k = async (e) => v(G, e, {
234
234
  onFileGenerated: () => {
235
235
  s.info("文件生成成功");
236
236
  }
237
- }), pe = {
237
+ }), me = {
238
238
  command: h.INIT,
239
239
  describe: "初始化配置文件",
240
- options: me(),
241
- handler: G
240
+ options: pe(),
241
+ handler: k
242
242
  }, le = () => ({
243
243
  ...D({
244
- configPathDefault: J
244
+ configPathDefault: S
245
245
  }),
246
246
  mode: {
247
247
  type: "string",
248
248
  alias: "m",
249
- choices: Object.values($),
250
- default: $.RESULT,
249
+ choices: Object.values(F),
250
+ default: F.RESULT,
251
251
  describe: "生成模式"
252
252
  }
253
253
  }), fe = async ({
254
254
  rootDir: e = process.cwd(),
255
255
  config: n
256
256
  }) => {
257
- const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
258
- (c, [p, l]) => {
259
- const f = ce({
257
+ const { extractInput: t, extractOutput: o } = n, a = Object.entries(t).reduce(
258
+ (c, [m, l]) => {
259
+ const f = ie({
260
260
  rootDir: e,
261
- input: p
261
+ input: m
262
262
  });
263
263
  return Object.entries(l).reduce(
264
- (d, [i, m]) => {
265
- const E = ae({
264
+ (d, [i, p]) => {
265
+ const E = ue({
266
266
  content: f,
267
267
  targetKey: i,
268
- keyConfig: m
268
+ keyConfig: p
269
269
  });
270
270
  return d[i] = E, d;
271
271
  },
@@ -274,60 +274,60 @@ const ce = ({
274
274
  },
275
275
  {}
276
276
  );
277
- await W(
277
+ await H(
278
278
  {
279
279
  rootDir: e,
280
280
  extraEnvData: a
281
281
  },
282
- t
282
+ o
283
283
  );
284
- }, I = async (e) => {
285
- const n = await F(e);
284
+ }, $ = async (e) => {
285
+ const n = await J(e, () => (s.info("配置文件为空,使用默认配置"), G));
286
286
  if (!n)
287
287
  return s.error("配置文件为空"), process.exit(1);
288
- const { rootDir: o } = e;
289
- await fe({ rootDir: o, config: n });
288
+ const { rootDir: t } = e;
289
+ await fe({ rootDir: t, config: n });
290
290
  }, Ee = {
291
291
  command: h.GENERATE,
292
292
  describe: "生成文件",
293
293
  options: le(),
294
- handler: I
295
- }, Ne = async (e, n) => {
294
+ handler: $
295
+ }, Ie = async (e, n) => {
296
296
  switch (e) {
297
297
  case h.INIT:
298
- return G(n);
298
+ return k(n);
299
299
  case h.GENERATE:
300
- return I(n);
300
+ return $(n);
301
301
  default:
302
- return I(n);
302
+ return $(n);
303
303
  }
304
- }, { version: ye, description: ge } = O, k = {
304
+ }, { version: ye, description: ge } = N, _ = {
305
305
  describe: ge,
306
306
  version: ye,
307
- subcommands: [pe, Ee].map(
308
- N
307
+ subcommands: [me, Ee].map(
308
+ I
309
309
  ),
310
310
  demandCommandCount: 1
311
311
  }, {
312
312
  cliConfig: { moduleName: w }
313
- } = O, _ = (e = !1) => {
314
- const n = e ? w : void 0, o = `$0${e ? ` ${w}` : ""} <command> [options]`;
315
- return { command: n, usage: o };
316
- }, Oe = async () => V({
317
- ...k,
318
- ..._()
319
- }), Re = () => N({
320
- ...k,
321
- ..._(!0)
313
+ } = N, P = (e = !1) => {
314
+ const n = e ? w : void 0, t = `$0${e ? ` ${w}` : ""} <command> [options]`;
315
+ return { command: n, usage: t };
316
+ }, Ne = async () => U({
317
+ ..._,
318
+ ...P()
319
+ }), Oe = () => I({
320
+ ..._,
321
+ ...P(!0)
322
322
  });
323
323
  export {
324
- Re as a,
325
- pe as b,
326
- Oe as c,
327
- I as d,
324
+ Oe as a,
325
+ me as b,
326
+ Ne as c,
327
+ $ as d,
328
328
  Ee as e,
329
- Ne as f,
329
+ Ie as f,
330
330
  fe as g,
331
- G as h,
332
- k as i
331
+ k as h,
332
+ _ as i
333
333
  };
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as t, a as i, e as s, g as d, d as l, f as p, b as f, h as u } from "./index-e4f5918d.js";
2
+ import { i as t, a as i, e as s, g as d, d as l, f as p, b as f, h as u } from "./index-fae67bc6.js";
3
3
  import { E as C, G as E, S as b } from "./index-a1ee6691-8c73eb4d.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-extract",
3
- "version": "0.1.10",
3
+ "version": "0.1.11-alpha.0",
4
4
  "description": "信息提取命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -52,7 +52,7 @@
52
52
  "license": "MIT",
53
53
  "sideEffects": false,
54
54
  "devDependencies": {
55
- "@done-coding/cli-inject": "^0.5.10",
55
+ "@done-coding/cli-inject": "^0.5.11-alpha.0",
56
56
  "@types/node": "^18.0.0",
57
57
  "@types/yargs": "^17.0.28",
58
58
  "rimraf": "^6.0.1",
@@ -64,8 +64,8 @@
64
64
  "node": ">=18.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@done-coding/cli-template": "0.7.10",
67
+ "@done-coding/cli-template": "0.7.11-alpha.0",
68
68
  "@done-coding/cli-utils": "^0.7.1"
69
69
  },
70
- "gitHead": "299ab3991d6842c83d65816dfba6efd175aa885a"
70
+ "gitHead": "dcc654349de82facba0b8d58c0001adb18144236"
71
71
  }