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