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 +1 -1
- package/es/{index-e4f5918d.js → index-94e9946e.js} +108 -98
- package/es/index.mjs +1 -1
- package/package.json +5 -5
package/es/cli.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as r, e as
|
|
3
|
-
import { log as s, _get as
|
|
4
|
-
import
|
|
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
|
|
7
|
-
const
|
|
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.
|
|
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:
|
|
17
|
-
} =
|
|
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:
|
|
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
|
|
44
|
+
return J(e, c);
|
|
42
45
|
}
|
|
43
46
|
default: {
|
|
44
47
|
s.warn(`未知的配置类型${a}`);
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
|
-
},
|
|
51
|
+
}, R = {
|
|
49
52
|
name: "@done-coding/cli-inject",
|
|
50
|
-
version: "0.5.
|
|
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:
|
|
58
|
-
} =
|
|
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
|
-
},
|
|
73
|
-
configPathDefault:
|
|
74
|
-
}),
|
|
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
|
-
}),
|
|
79
|
-
command:
|
|
87
|
+
}), te = {
|
|
88
|
+
command: V.INIT,
|
|
80
89
|
describe: "初始化配置文件",
|
|
81
|
-
options:
|
|
82
|
-
handler:
|
|
83
|
-
},
|
|
84
|
-
...
|
|
85
|
-
configPathDefault:
|
|
90
|
+
options: ee(),
|
|
91
|
+
handler: ne
|
|
92
|
+
}, oe = () => ({
|
|
93
|
+
...h({
|
|
94
|
+
configPathDefault: T
|
|
86
95
|
})
|
|
87
|
-
}),
|
|
96
|
+
}), se = async ({
|
|
88
97
|
rootDir: e = process.cwd(),
|
|
89
|
-
config: n =
|
|
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,
|
|
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 =
|
|
105
|
-
(
|
|
106
|
-
const
|
|
107
|
-
return
|
|
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
|
-
),
|
|
111
|
-
if (y.existsSync(
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
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(
|
|
119
|
-
},
|
|
120
|
-
const n = await
|
|
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
|
|
125
|
-
},
|
|
126
|
-
command:
|
|
133
|
+
await se({ rootDir: o, config: n });
|
|
134
|
+
}, ce = {
|
|
135
|
+
command: "$0",
|
|
127
136
|
describe: "生成文件",
|
|
128
|
-
options:
|
|
129
|
-
handler:
|
|
130
|
-
}, { version:
|
|
131
|
-
[
|
|
137
|
+
options: oe(),
|
|
138
|
+
handler: re
|
|
139
|
+
}, { version: ie, description: ae } = R;
|
|
140
|
+
[te, ce].map(
|
|
132
141
|
N
|
|
133
|
-
);
|
|
134
|
-
const
|
|
142
|
+
), v({ packageJson: R });
|
|
143
|
+
const ue = ({
|
|
135
144
|
input: e,
|
|
136
145
|
rootDir: n
|
|
137
146
|
}) => {
|
|
138
|
-
const o =
|
|
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
|
-
},
|
|
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 (!
|
|
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
|
-
},
|
|
192
|
+
}, me = {
|
|
184
193
|
name: "${name}",
|
|
185
194
|
version: "${version}",
|
|
186
195
|
description: "${description}"
|
|
187
|
-
},
|
|
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:
|
|
226
|
-
inputData: JSON.stringify(
|
|
234
|
+
mode: H.OVERWRITE,
|
|
235
|
+
inputData: JSON.stringify(me, null, 2),
|
|
227
236
|
output: "./src/extractInfo.json"
|
|
228
237
|
}
|
|
229
238
|
]
|
|
230
239
|
}
|
|
231
|
-
},
|
|
232
|
-
configPathDefault:
|
|
233
|
-
}), G = async (e) =>
|
|
240
|
+
}, le = () => h({
|
|
241
|
+
configPathDefault: A
|
|
242
|
+
}), G = async (e) => F(k, e, {
|
|
234
243
|
onFileGenerated: () => {
|
|
235
244
|
s.info("文件生成成功");
|
|
236
245
|
}
|
|
237
|
-
}),
|
|
238
|
-
command:
|
|
246
|
+
}), fe = {
|
|
247
|
+
command: D.INIT,
|
|
239
248
|
describe: "初始化配置文件",
|
|
240
|
-
options:
|
|
249
|
+
options: le(),
|
|
241
250
|
handler: G
|
|
242
|
-
},
|
|
243
|
-
...
|
|
244
|
-
configPathDefault:
|
|
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:
|
|
258
|
+
choices: Object.values(S),
|
|
259
|
+
default: S.RESULT,
|
|
251
260
|
describe: "生成模式"
|
|
252
261
|
}
|
|
253
|
-
}),
|
|
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, [
|
|
259
|
-
const f =
|
|
267
|
+
(c, [m, l]) => {
|
|
268
|
+
const f = ue({
|
|
260
269
|
rootDir: e,
|
|
261
|
-
input:
|
|
270
|
+
input: m
|
|
262
271
|
});
|
|
263
272
|
return Object.entries(l).reduce(
|
|
264
|
-
(d, [i,
|
|
265
|
-
const
|
|
273
|
+
(d, [i, p]) => {
|
|
274
|
+
const g = pe({
|
|
266
275
|
content: f,
|
|
267
276
|
targetKey: i,
|
|
268
|
-
keyConfig:
|
|
277
|
+
keyConfig: p
|
|
269
278
|
});
|
|
270
|
-
return d[i] =
|
|
279
|
+
return d[i] = g, d;
|
|
271
280
|
},
|
|
272
281
|
c
|
|
273
282
|
);
|
|
274
283
|
},
|
|
275
284
|
{}
|
|
276
285
|
);
|
|
277
|
-
await
|
|
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
|
|
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
|
|
298
|
+
await ye({ rootDir: o, config: n });
|
|
290
299
|
}, Ee = {
|
|
291
|
-
command:
|
|
300
|
+
command: "$0",
|
|
292
301
|
describe: "生成文件",
|
|
293
|
-
options:
|
|
302
|
+
options: ge(),
|
|
294
303
|
handler: I
|
|
295
|
-
},
|
|
304
|
+
}, Re = async (e, n) => {
|
|
296
305
|
switch (e) {
|
|
297
|
-
case
|
|
306
|
+
case D.INIT:
|
|
298
307
|
return G(n);
|
|
299
|
-
case
|
|
308
|
+
case D.GENERATE:
|
|
300
309
|
return I(n);
|
|
301
310
|
default:
|
|
302
311
|
return I(n);
|
|
303
312
|
}
|
|
304
|
-
}, { version:
|
|
305
|
-
describe:
|
|
306
|
-
version:
|
|
307
|
-
subcommands: [
|
|
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
|
-
} =
|
|
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 () =>
|
|
317
|
-
...
|
|
318
|
-
...
|
|
319
|
-
}),
|
|
320
|
-
...
|
|
321
|
-
...
|
|
326
|
+
}, Oe = async () => W({
|
|
327
|
+
..._,
|
|
328
|
+
...P()
|
|
329
|
+
}), be = () => N({
|
|
330
|
+
..._,
|
|
331
|
+
...P(!0)
|
|
322
332
|
});
|
|
323
333
|
export {
|
|
324
|
-
|
|
325
|
-
|
|
334
|
+
be as a,
|
|
335
|
+
fe as b,
|
|
326
336
|
Oe as c,
|
|
327
337
|
I as d,
|
|
328
338
|
Ee as e,
|
|
329
|
-
|
|
330
|
-
|
|
339
|
+
Re as f,
|
|
340
|
+
ye as g,
|
|
331
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-
|
|
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.
|
|
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.
|
|
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.
|
|
58
|
-
"@done-coding/cli-utils": "^0.7.
|
|
57
|
+
"@done-coding/cli-template": "0.7.12-alpha.0",
|
|
58
|
+
"@done-coding/cli-utils": "^0.7.3-alpha.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae",
|
|
61
61
|
"scripts": {}
|
|
62
62
|
}
|