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