@done-coding/cli-extract 0.1.1-alpha.0 → 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-7b2a1d96.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 h, getConfigFileCommonOptions as R, initHandlerCommon as v, readConfigFile as G, _set as H, createMainCommand as V } from "@done-coding/cli-utils";
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";
3
4
  import D from "node:path";
4
- import N from "node:fs";
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 j = ({
7
+ const R = ({
8
8
  sourceJson: e,
9
9
  targetKey: n,
10
10
  keyConfig: t
@@ -14,13 +14,13 @@ const j = ({
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,11 +29,11 @@ const j = ({
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
  }
36
- }, F = {
36
+ }, U = {
37
37
  sourceFilePath: "./package.json",
38
38
  keyConfigMap: {
39
39
  name: {
@@ -47,107 +47,107 @@ const j = ({
47
47
  }
48
48
  },
49
49
  injectFilePath: "./src/injectInfo.json"
50
- }, J = {
50
+ }, w = U, x = {
51
51
  name: "@done-coding/cli-inject",
52
- version: "0.5.2-alpha.0",
52
+ version: "0.5.2",
53
53
  description: "信息(JSON)注入命令行工具",
54
54
  cliConfig: {
55
55
  namespaceDir: ".done-coding",
56
56
  moduleName: "inject"
57
57
  }
58
58
  }, {
59
- cliConfig: { namespaceDir: U, moduleName: X }
60
- } = J, K = `./${U}/${X}`, $ = `${K}.json`, q = () => R({
61
- configPathDefault: $
62
- }), z = async (e) => v(F, e, {
59
+ cliConfig: { namespaceDir: X, moduleName: K }
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
- }), B = () => ({
67
- ...R({
68
- configPathDefault: $
66
+ }), Q = () => ({
67
+ ...j({
68
+ configPathDefault: F
69
69
  })
70
- }), Q = async ({
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 = D.resolve(e, o), g = N.readFileSync(E, "utf-8"), l = JSON.parse(g), i = Object.entries(f).reduce(
88
- (C, [T, P]) => {
89
- const M = j({ sourceJson: l, targetKey: T, keyConfig: P });
90
- return H(C, T, 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 = D.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);
102
- }, Y = async (e) => {
103
- const n = await G(e);
101
+ C.writeFileSync(p, y), r.success(`文件注入成功: ${p}`), r.info(y);
102
+ }, Z = async (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
- await Q({ rootDir: t, config: n });
108
- }, w = async (e, n) => e === p.INIT ? z(n) : e === p.GENERATE ? Y(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
109
- version: Z,
110
- description: ee,
111
- cliConfig: { moduleName: he }
112
- } = J, ne = {
113
- command: p.INIT,
107
+ await Y({ rootDir: t, config: n });
108
+ }, J = async (e, n) => e === m.INIT ? B(n) : e === m.GENERATE ? Z(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
109
+ version: ee,
110
+ description: ne,
111
+ cliConfig: { moduleName: Oe }
112
+ } = x, te = {
113
+ command: m.INIT,
114
114
  describe: "初始化提取配置文件",
115
- options: q(),
116
- handler: I(w)(
117
- p.INIT
115
+ options: z(),
116
+ handler: I(J)(
117
+ m.INIT
118
118
  )
119
- }, te = {
120
- command: p.GENERATE,
119
+ }, oe = {
120
+ command: m.GENERATE,
121
121
  describe: "提取信息",
122
- options: B(),
123
- handler: I(w)(
124
- p.GENERATE
122
+ options: Q(),
123
+ handler: I(J)(
124
+ m.GENERATE
125
125
  )
126
126
  };
127
- [ne, te].map(
127
+ [te, oe].map(
128
128
  h
129
129
  );
130
- const oe = {
130
+ const re = {
131
131
  name: "${name}",
132
132
  version: "${version}",
133
133
  description: "${description}"
134
- }, re = {
134
+ }, se = {
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 oe = {
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
  }
@@ -170,59 +170,59 @@ const oe = {
170
170
  list: [
171
171
  {
172
172
  mode: L.OVERWRITE,
173
- inputData: JSON.stringify(oe, null, 2),
173
+ inputData: JSON.stringify(re, null, 2),
174
174
  output: "./src/extractInfo.json"
175
175
  }
176
176
  ]
177
177
  }
178
- }, x = {
178
+ }, S = {
179
179
  name: "@done-coding/cli-extract",
180
- version: "0.1.1-alpha.0",
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: se, moduleName: ie }
188
- } = x, ce = `./${se}/${ie}`, S = `${ce}.json5`, ae = () => R({
189
- configPathDefault: S
190
- }), de = async (e) => v(re, 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
  }
194
- }), ue = ({
194
+ }), pe = ({
195
195
  input: e,
196
196
  rootDir: n
197
197
  }) => {
198
- const t = D.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
- }, pe = (e) => typeof e == "object" && !!e, le = ({
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 j({
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 (!pe(e))
222
+ case u.JSON_INJECT: {
223
+ if (!me(e))
224
224
  throw new Error(`${o} 类型的keyConfig需要content为json`);
225
- return j({
225
+ return R({
226
226
  sourceJson: e,
227
227
  targetKey: n,
228
228
  keyConfig: t.inject
@@ -231,28 +231,28 @@ const oe = {
231
231
  default:
232
232
  throw new Error(`不支持的类型${o}`);
233
233
  }
234
- }, me = () => ({
235
- ...R({
236
- configPathDefault: S
234
+ }, fe = () => ({
235
+ ...j({
236
+ configPathDefault: b
237
237
  })
238
- }), fe = async ({
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
- const g = ue({
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]) => {
249
+ (d, [c, p]) => {
250
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 oe = {
262
262
  await W(
263
263
  {
264
264
  rootDir: e,
265
- extraEnvData: c
265
+ extraEnvData: i
266
266
  },
267
267
  o
268
268
  );
269
- }, Ee = async (e) => {
270
- const n = await G(e);
269
+ }, ge = async (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
- await fe({ rootDir: t, config: n });
275
- }, b = async (e, n) => e === u.INIT ? de(n) : e === u.GENERATE ? Ee(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
276
- version: ge,
277
- description: ye,
274
+ await Ee({ rootDir: t, config: n });
275
+ }, G = async (e, n) => e === l.INIT ? de(n) : e === l.GENERATE ? ge(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
276
+ version: ye,
277
+ description: Ce,
278
278
  cliConfig: { moduleName: A }
279
- } = x, Ne = {
280
- command: u.INIT,
279
+ } = S, Ne = {
280
+ command: l.INIT,
281
281
  describe: "初始化提取配置文件",
282
- options: ae(),
283
- handler: I(b)(
284
- u.INIT
282
+ options: ue(),
283
+ handler: I(G)(
284
+ l.INIT
285
285
  )
286
- }, Ce = {
287
- command: u.GENERATE,
286
+ }, Ie = {
287
+ command: l.GENERATE,
288
288
  describe: "提取信息",
289
- options: me(),
290
- handler: I(b)(
291
- u.GENERATE
289
+ options: fe(),
290
+ handler: I(G)(
291
+ l.GENERATE
292
292
  )
293
293
  }, _ = {
294
- describe: ye,
295
- version: ge,
296
- subcommands: [Ne, Ce].map(
294
+ describe: Ce,
295
+ version: ye,
296
+ subcommands: [Ne, Ie].map(
297
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
- }, Te = async () => V({
303
+ }, Ae = async () => V({
304
304
  ..._,
305
305
  ...k()
306
- }), Oe = () => h({
306
+ }), ve = () => h({
307
307
  ..._,
308
308
  ...k(!0)
309
309
  });
310
310
  export {
311
- d as E,
312
- u as S,
313
- Oe as a,
314
- Te 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-7b2a1d96.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-alpha.0",
3
+ "version": "0.1.2-alpha.0",
4
4
  "description": "信息提取命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -51,7 +51,7 @@
51
51
  "license": "MIT",
52
52
  "sideEffects": false,
53
53
  "devDependencies": {
54
- "@done-coding/cli-inject": "^0.5.2-alpha.0",
54
+ "@done-coding/cli-inject": "^0.5.2",
55
55
  "@types/node": "^18.0.0",
56
56
  "@types/yargs": "^17.0.28",
57
57
  "rimraf": "^6.0.1",
@@ -63,8 +63,8 @@
63
63
  "node": ">=18.0.0"
64
64
  },
65
65
  "dependencies": {
66
- "@done-coding/cli-template": "0.7.3-alpha.0",
67
- "@done-coding/cli-utils": "^0.3.2-alpha.0"
66
+ "@done-coding/cli-template": "0.7.3",
67
+ "@done-coding/cli-utils": "^0.3.2"
68
68
  },
69
- "gitHead": "7faf662e137d46f776c8e5abdf75ab3db541362c"
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-alpha.0",
3
+ "version": "0.1.2-alpha.0",
4
4
  "description": "信息提取命令行工具",
5
5
  "cliConfig": {
6
6
  "namespaceDir": ".done-coding",