done-coding-extract 0.1.10 → 0.1.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 { c as m } from "./index-e4f5918d.js";
2
+ import { c as m } from "./index-94e9946e.js";
3
3
  import "./index-a1ee6691-8c73eb4d.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
@@ -1,20 +1,23 @@
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";
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 U, batchCompileHandler as W } from "@done-coding/cli-template";
7
- const O = {
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.10",
9
+ version: "0.1.12-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: H, moduleName: X }
17
- } = O, K = `./${H}/${X}`, J = `${K}.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
23
  keyConfig: o
@@ -27,7 +30,7 @@ const O = {
27
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 } = t, 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);
@@ -38,24 +41,27 @@ const O = {
38
41
  }
39
42
  case r.READ: {
40
43
  const { sourceKey: c = n } = t;
41
- return b(e, c);
44
+ return J(e, c);
42
45
  }
43
46
  default: {
44
47
  s.warn(`未知的配置类型${a}`);
45
48
  return;
46
49
  }
47
50
  }
48
- }, S = {
51
+ }, R = {
49
52
  name: "@done-coding/cli-inject",
50
- version: "0.5.10",
53
+ version: "0.5.12-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: q, moduleName: z }
58
- } = S, B = `./${q}/${z}`, A = `${B}.json`, x = {
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,34 +72,37 @@ const O = {
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
- }, Q = () => D({
73
- configPathDefault: A
74
- }), Y = async (e) => v(x, 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
- }), Z = {
79
- command: T.INIT,
87
+ }), te = {
88
+ command: V.INIT,
80
89
  describe: "初始化配置文件",
81
- options: Q(),
82
- handler: Y
83
- }, ee = () => ({
84
- ...D({
85
- configPathDefault: A
90
+ options: ee(),
91
+ handler: ne
92
+ }, oe = () => ({
93
+ ...h({
94
+ configPathDefault: T
86
95
  })
87
- }), ne = async ({
96
+ }), se = async ({
88
97
  rootDir: e = process.cwd(),
89
- config: n = x,
98
+ config: n = O,
90
99
  keyConfigMap: o = {}
91
100
  } = {}) => {
92
101
  const {
93
102
  sourceFilePath: t,
94
103
  keyConfigMap: a,
95
104
  injectFilePath: c
96
- } = n, p = {
105
+ } = n, m = {
97
106
  ...a,
98
107
  ...o
99
108
  };
@@ -101,43 +110,43 @@ const O = {
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, 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;
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 F(e);
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
132
  const { rootDir: o } = e;
124
- await ne({ rootDir: o, config: n });
125
- }, oe = {
126
- command: T.GENERATE,
133
+ await se({ rootDir: o, config: n });
134
+ }, ce = {
135
+ command: "$0",
127
136
  describe: "生成文件",
128
- options: ee(),
129
- handler: te
130
- }, { version: se, description: re } = S;
131
- [Z, oe].map(
137
+ options: oe(),
138
+ handler: re
139
+ }, { version: ie, description: ae } = R;
140
+ [te, ce].map(
132
141
  N
133
- );
134
- const ce = ({
142
+ ), v({ packageJson: R });
143
+ const ue = ({
135
144
  input: e,
136
145
  rootDir: n
137
146
  }) => {
138
- const o = j.resolve(n, e), t = y.readFileSync(o, "utf-8");
147
+ const o = $.resolve(n, e), t = y.readFileSync(o, "utf-8");
139
148
  return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
140
- }, ie = (e) => typeof e == "object" && !!e, ae = ({
149
+ }, de = (e) => typeof e == "object" && !!e, pe = ({
141
150
  content: e,
142
151
  targetKey: n,
143
152
  keyConfig: o
@@ -160,7 +169,7 @@ const ce = ({
160
169
  });
161
170
  }
162
171
  case u.JSON_INJECT: {
163
- if (!ie(e))
172
+ if (!de(e))
164
173
  throw new Error(`${t} 类型的keyConfig需要content为json`);
165
174
  return C({
166
175
  sourceJson: e,
@@ -180,11 +189,11 @@ const ce = ({
180
189
  default:
181
190
  throw new Error(`不支持的类型${t}`);
182
191
  }
183
- }, ue = {
192
+ }, me = {
184
193
  name: "${name}",
185
194
  version: "${version}",
186
195
  description: "${description}"
187
- }, de = {
196
+ }, k = {
188
197
  extractInput: {
189
198
  "./package.json": {
190
199
  name: {
@@ -222,59 +231,59 @@ const ce = ({
222
231
  extractOutput: {
223
232
  list: [
224
233
  {
225
- mode: U.OVERWRITE,
226
- inputData: JSON.stringify(ue, 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: J
233
- }), G = async (e) => v(de, 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(),
249
+ options: le(),
241
250
  handler: G
242
- }, le = () => ({
243
- ...D({
244
- configPathDefault: J
251
+ }, ge = () => ({
252
+ ...h({
253
+ configPathDefault: A
245
254
  }),
246
255
  mode: {
247
256
  type: "string",
248
257
  alias: "m",
249
- choices: Object.values($),
250
- default: $.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
266
  const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
258
- (c, [p, l]) => {
259
- const f = ce({
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 = ae({
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 W(
286
+ await X(
278
287
  {
279
288
  rootDir: e,
280
289
  extraEnvData: a
@@ -282,52 +291,53 @@ const ce = ({
282
291
  t
283
292
  );
284
293
  }, I = async (e) => {
285
- const n = await F(e);
294
+ const n = await x(e, () => (s.info("配置文件为空,使用默认配置"), k));
286
295
  if (!n)
287
296
  return s.error("配置文件为空"), process.exit(1);
288
297
  const { rootDir: o } = e;
289
- await fe({ rootDir: o, config: n });
298
+ await ye({ rootDir: o, config: n });
290
299
  }, Ee = {
291
- command: h.GENERATE,
300
+ command: "$0",
292
301
  describe: "生成文件",
293
- options: le(),
302
+ options: ge(),
294
303
  handler: I
295
- }, Ne = async (e, n) => {
304
+ }, Re = async (e, n) => {
296
305
  switch (e) {
297
- case h.INIT:
306
+ case D.INIT:
298
307
  return G(n);
299
- case h.GENERATE:
308
+ case D.GENERATE:
300
309
  return I(n);
301
310
  default:
302
311
  return I(n);
303
312
  }
304
- }, { version: ye, description: ge } = O, k = {
305
- describe: ge,
306
- version: ye,
307
- subcommands: [pe, Ee].map(
313
+ }, { version: Ce, description: he } = j, _ = {
314
+ describe: he,
315
+ version: Ce,
316
+ subcommands: [fe, Ee].map(
308
317
  N
309
318
  ),
310
- demandCommandCount: 1
319
+ demandCommandCount: 1,
320
+ rootScriptName: v({ packageJson: j })
311
321
  }, {
312
322
  cliConfig: { moduleName: w }
313
- } = O, _ = (e = !1) => {
323
+ } = j, P = (e = !1) => {
314
324
  const n = e ? w : void 0, o = `$0${e ? ` ${w}` : ""} <command> [options]`;
315
325
  return { command: n, usage: o };
316
- }, Oe = async () => V({
317
- ...k,
318
- ..._()
319
- }), Re = () => N({
320
- ...k,
321
- ..._(!0)
326
+ }, Oe = async () => W({
327
+ ..._,
328
+ ...P()
329
+ }), be = () => N({
330
+ ..._,
331
+ ...P(!0)
322
332
  });
323
333
  export {
324
- Re as a,
325
- pe as b,
334
+ be as a,
335
+ fe as b,
326
336
  Oe as c,
327
337
  I as d,
328
338
  Ee as e,
329
- Ne as f,
330
- fe as g,
339
+ Re as f,
340
+ ye as g,
331
341
  G as h,
332
- k as i
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-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-94e9946e.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.10",
3
+ "version": "0.1.12-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.10",
45
+ "@done-coding/cli-inject": "^0.5.12-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.10",
58
- "@done-coding/cli-utils": "^0.7.1"
57
+ "@done-coding/cli-template": "0.7.12-alpha.0",
58
+ "@done-coding/cli-utils": "^0.7.3-alpha.0"
59
59
  },
60
- "gitHead": "299ab3991d6842c83d65816dfba6efd175aa885a",
60
+ "gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae",
61
61
  "scripts": {}
62
62
  }