done-coding-extract 0.1.11 → 0.1.13-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-3b483023.js → index-77430042.js} +139 -129
- package/es/index.mjs +1 -1
- package/package.json +5 -5
package/es/cli.mjs
CHANGED
|
@@ -1,61 +1,67 @@
|
|
|
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.13-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
|
-
keyConfig:
|
|
23
|
+
keyConfig: o
|
|
21
24
|
}) => {
|
|
22
|
-
let
|
|
23
|
-
typeof
|
|
25
|
+
let t;
|
|
26
|
+
typeof o == "string" ? t = {
|
|
24
27
|
type: r.FIXED,
|
|
25
|
-
value:
|
|
26
|
-
} :
|
|
27
|
-
const { type: a = r.READ } =
|
|
28
|
+
value: o
|
|
29
|
+
} : t = o;
|
|
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);
|
|
34
37
|
}
|
|
35
38
|
case r.FIXED: {
|
|
36
|
-
const { value: c } =
|
|
39
|
+
const { value: c } = t;
|
|
37
40
|
return c;
|
|
38
41
|
}
|
|
39
42
|
case r.READ: {
|
|
40
|
-
const { sourceKey: c = n } =
|
|
41
|
-
return
|
|
43
|
+
const { sourceKey: c = n } = t;
|
|
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.13-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,87 +72,90 @@ const N = {
|
|
|
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
98
|
config: n = O,
|
|
90
|
-
keyConfigMap:
|
|
99
|
+
keyConfigMap: o = {}
|
|
91
100
|
} = {}) => {
|
|
92
101
|
const {
|
|
93
|
-
sourceFilePath:
|
|
102
|
+
sourceFilePath: t,
|
|
94
103
|
keyConfigMap: a,
|
|
95
104
|
injectFilePath: c
|
|
96
|
-
} = n,
|
|
105
|
+
} = n, m = {
|
|
97
106
|
...a,
|
|
98
|
-
...
|
|
107
|
+
...o
|
|
99
108
|
};
|
|
100
|
-
if (!
|
|
109
|
+
if (!t.endsWith(".json"))
|
|
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 L = C({ sourceJson: d, targetKey:
|
|
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
|
-
const { rootDir:
|
|
124
|
-
await
|
|
125
|
-
},
|
|
126
|
-
command:
|
|
132
|
+
const { rootDir: o } = e;
|
|
133
|
+
await se({ rootDir: o, config: n });
|
|
134
|
+
}, ce = {
|
|
135
|
+
command: "$0",
|
|
127
136
|
describe: "生成文件",
|
|
128
|
-
options:
|
|
129
|
-
handler:
|
|
130
|
-
}, { version:
|
|
131
|
-
[
|
|
132
|
-
|
|
133
|
-
);
|
|
134
|
-
const
|
|
137
|
+
options: oe(),
|
|
138
|
+
handler: re
|
|
139
|
+
}, { version: ie, description: ae } = R;
|
|
140
|
+
[te, ce].map(
|
|
141
|
+
N
|
|
142
|
+
), v({ packageJson: R });
|
|
143
|
+
const ue = ({
|
|
135
144
|
input: e,
|
|
136
145
|
rootDir: n
|
|
137
146
|
}) => {
|
|
138
|
-
const
|
|
139
|
-
return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(
|
|
140
|
-
},
|
|
147
|
+
const o = $.resolve(n, e), t = y.readFileSync(o, "utf-8");
|
|
148
|
+
return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
|
|
149
|
+
}, de = (e) => typeof e == "object" && !!e, pe = ({
|
|
141
150
|
content: e,
|
|
142
151
|
targetKey: n,
|
|
143
|
-
keyConfig:
|
|
152
|
+
keyConfig: o
|
|
144
153
|
}) => {
|
|
145
|
-
const { type:
|
|
146
|
-
switch (
|
|
154
|
+
const { type: t, ...a } = o;
|
|
155
|
+
switch (t) {
|
|
147
156
|
case u.REG: {
|
|
148
157
|
if (typeof e != "string")
|
|
149
|
-
throw new Error(`${
|
|
158
|
+
throw new Error(`${t} 类型的keyConfig需要content为字符串`);
|
|
150
159
|
return C({
|
|
151
160
|
sourceJson: {
|
|
152
161
|
[n]: e
|
|
@@ -160,12 +169,12 @@ const ie = ({
|
|
|
160
169
|
});
|
|
161
170
|
}
|
|
162
171
|
case u.JSON_INJECT: {
|
|
163
|
-
if (!
|
|
164
|
-
throw new Error(`${
|
|
172
|
+
if (!de(e))
|
|
173
|
+
throw new Error(`${t} 类型的keyConfig需要content为json`);
|
|
165
174
|
return C({
|
|
166
175
|
sourceJson: e,
|
|
167
176
|
targetKey: n,
|
|
168
|
-
keyConfig:
|
|
177
|
+
keyConfig: o.inject
|
|
169
178
|
});
|
|
170
179
|
}
|
|
171
180
|
case u.FIXED:
|
|
@@ -178,13 +187,13 @@ const ie = ({
|
|
|
178
187
|
}
|
|
179
188
|
});
|
|
180
189
|
default:
|
|
181
|
-
throw new Error(`不支持的类型${
|
|
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,112 +231,113 @@ const ie = ({
|
|
|
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
|
-
}),
|
|
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:
|
|
241
|
-
handler:
|
|
242
|
-
},
|
|
243
|
-
...
|
|
244
|
-
configPathDefault:
|
|
249
|
+
options: le(),
|
|
250
|
+
handler: G
|
|
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
|
-
const { extractInput:
|
|
258
|
-
(c, [
|
|
259
|
-
const f =
|
|
266
|
+
const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
|
|
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
|
|
281
290
|
},
|
|
282
|
-
|
|
291
|
+
t
|
|
283
292
|
);
|
|
284
|
-
},
|
|
285
|
-
const n = await
|
|
293
|
+
}, I = async (e) => {
|
|
294
|
+
const n = await x(e, () => (s.info("配置文件为空,使用默认配置"), k));
|
|
286
295
|
if (!n)
|
|
287
296
|
return s.error("配置文件为空"), process.exit(1);
|
|
288
|
-
const { rootDir:
|
|
289
|
-
await
|
|
297
|
+
const { rootDir: o } = e;
|
|
298
|
+
await ye({ rootDir: o, config: n });
|
|
290
299
|
}, Ee = {
|
|
291
|
-
command:
|
|
300
|
+
command: "$0",
|
|
292
301
|
describe: "生成文件",
|
|
293
|
-
options:
|
|
294
|
-
handler:
|
|
295
|
-
},
|
|
302
|
+
options: ge(),
|
|
303
|
+
handler: I
|
|
304
|
+
}, Re = async (e, n) => {
|
|
296
305
|
switch (e) {
|
|
297
|
-
case
|
|
298
|
-
return
|
|
299
|
-
case
|
|
300
|
-
return
|
|
306
|
+
case D.INIT:
|
|
307
|
+
return G(n);
|
|
308
|
+
case D.GENERATE:
|
|
309
|
+
return I(n);
|
|
301
310
|
default:
|
|
302
|
-
return
|
|
311
|
+
return I(n);
|
|
303
312
|
}
|
|
304
|
-
}, { version:
|
|
305
|
-
describe:
|
|
306
|
-
version:
|
|
307
|
-
subcommands: [
|
|
308
|
-
|
|
313
|
+
}, { version: Ce, description: he } = j, _ = {
|
|
314
|
+
describe: he,
|
|
315
|
+
version: Ce,
|
|
316
|
+
subcommands: [fe, Ee].map(
|
|
317
|
+
N
|
|
309
318
|
),
|
|
310
|
-
demandCommandCount: 1
|
|
319
|
+
demandCommandCount: 1,
|
|
320
|
+
rootScriptName: v({ packageJson: j })
|
|
311
321
|
}, {
|
|
312
322
|
cliConfig: { moduleName: w }
|
|
313
|
-
} =
|
|
314
|
-
const n = e ? w : void 0,
|
|
315
|
-
return { command: n, usage:
|
|
316
|
-
},
|
|
323
|
+
} = j, P = (e = !1) => {
|
|
324
|
+
const n = e ? w : void 0, o = `$0${e ? ` ${w}` : ""} <command> [options]`;
|
|
325
|
+
return { command: n, usage: o };
|
|
326
|
+
}, Oe = async () => W({
|
|
317
327
|
..._,
|
|
318
328
|
...P()
|
|
319
|
-
}),
|
|
329
|
+
}), be = () => N({
|
|
320
330
|
..._,
|
|
321
331
|
...P(!0)
|
|
322
332
|
});
|
|
323
333
|
export {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
334
|
+
be as a,
|
|
335
|
+
fe as b,
|
|
336
|
+
Oe as c,
|
|
337
|
+
I as d,
|
|
328
338
|
Ee as e,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
339
|
+
Re as f,
|
|
340
|
+
ye as g,
|
|
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-77430042.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.13-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.13-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.
|
|
58
|
-
"@done-coding/cli-utils": "^0.7.
|
|
57
|
+
"@done-coding/cli-template": "0.8.0-alpha.0",
|
|
58
|
+
"@done-coding/cli-utils": "^0.7.4-alpha.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "a1acffae69586b12aec17d0ad76d6f75ad1d0ca0",
|
|
61
61
|
"scripts": {}
|
|
62
62
|
}
|