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