done-coding-extract 0.1.10-alpha.0 → 0.1.10
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-e4f5918d.js} +56 -56
- package/es/index.mjs +1 -1
- package/package.json +5 -5
package/es/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import y from "node:fs";
|
|
|
6
6
|
import { OutputModeEnum as U, batchCompileHandler as W } from "@done-coding/cli-template";
|
|
7
7
|
const O = {
|
|
8
8
|
name: "@done-coding/cli-extract",
|
|
9
|
-
version: "0.1.10
|
|
9
|
+
version: "0.1.10",
|
|
10
10
|
description: "信息提取命令行工具",
|
|
11
11
|
cliConfig: {
|
|
12
12
|
namespaceDir: ".done-coding",
|
|
@@ -27,7 +27,7 @@ const O = {
|
|
|
27
27
|
const { type: a = r.READ } = t;
|
|
28
28
|
switch (a) {
|
|
29
29
|
case r.REG: {
|
|
30
|
-
const { sourceKey: c, pattern:
|
|
30
|
+
const { sourceKey: c, pattern: p, replaceValue: l, flags: f } = t, 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);
|
|
@@ -47,7 +47,7 @@ const O = {
|
|
|
47
47
|
}
|
|
48
48
|
}, S = {
|
|
49
49
|
name: "@done-coding/cli-inject",
|
|
50
|
-
version: "0.5.10
|
|
50
|
+
version: "0.5.10",
|
|
51
51
|
description: "信息(JSON)注入命令行工具",
|
|
52
52
|
cliConfig: {
|
|
53
53
|
namespaceDir: ".done-coding",
|
|
@@ -55,7 +55,7 @@ const O = {
|
|
|
55
55
|
}
|
|
56
56
|
}, {
|
|
57
57
|
cliConfig: { namespaceDir: q, moduleName: z }
|
|
58
|
-
} = S, B = `./${q}/${z}`, A = `${B}.json`,
|
|
58
|
+
} = S, B = `./${q}/${z}`, A = `${B}.json`, x = {
|
|
59
59
|
sourceFilePath: "./package.json",
|
|
60
60
|
keyConfigMap: {
|
|
61
61
|
name: {
|
|
@@ -69,22 +69,22 @@ const O = {
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
injectFilePath: "./src/injectInfo.json"
|
|
72
|
-
},
|
|
72
|
+
}, Q = () => D({
|
|
73
73
|
configPathDefault: A
|
|
74
|
-
}),
|
|
74
|
+
}), Y = async (e) => v(x, e, {
|
|
75
75
|
onFileGenerated: () => {
|
|
76
76
|
s.info("文件生成成功");
|
|
77
77
|
}
|
|
78
|
-
}),
|
|
78
|
+
}), Z = {
|
|
79
79
|
command: T.INIT,
|
|
80
80
|
describe: "初始化配置文件",
|
|
81
|
-
options:
|
|
82
|
-
handler:
|
|
83
|
-
},
|
|
81
|
+
options: Q(),
|
|
82
|
+
handler: Y
|
|
83
|
+
}, ee = () => ({
|
|
84
84
|
...D({
|
|
85
85
|
configPathDefault: A
|
|
86
86
|
})
|
|
87
|
-
}),
|
|
87
|
+
}), ne = async ({
|
|
88
88
|
rootDir: e = process.cwd(),
|
|
89
89
|
config: n = x,
|
|
90
90
|
keyConfigMap: o = {}
|
|
@@ -93,7 +93,7 @@ const O = {
|
|
|
93
93
|
sourceFilePath: t,
|
|
94
94
|
keyConfigMap: a,
|
|
95
95
|
injectFilePath: c
|
|
96
|
-
} = n,
|
|
96
|
+
} = n, p = {
|
|
97
97
|
...a,
|
|
98
98
|
...o
|
|
99
99
|
};
|
|
@@ -101,43 +101,43 @@ const O = {
|
|
|
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, t), f = y.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(
|
|
104
|
+
const l = j.resolve(e, t), f = y.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(p).reduce(
|
|
105
105
|
(g, [R, P]) => {
|
|
106
106
|
const M = C({ sourceJson: d, targetKey: R, keyConfig: P });
|
|
107
107
|
return L(g, R, M), 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
|
-
},
|
|
118
|
+
y.writeFileSync(m, E), s.success(`文件注入成功: ${m}`), s.info(E);
|
|
119
|
+
}, te = async (e) => {
|
|
120
120
|
const n = await F(e);
|
|
121
121
|
if (!n)
|
|
122
122
|
return s.error("配置文件为空"), process.exit(1);
|
|
123
123
|
const { rootDir: o } = e;
|
|
124
|
-
await
|
|
125
|
-
},
|
|
124
|
+
await ne({ rootDir: o, config: n });
|
|
125
|
+
}, oe = {
|
|
126
126
|
command: T.GENERATE,
|
|
127
127
|
describe: "生成文件",
|
|
128
|
-
options:
|
|
129
|
-
handler:
|
|
130
|
-
}, { version:
|
|
131
|
-
[
|
|
128
|
+
options: ee(),
|
|
129
|
+
handler: te
|
|
130
|
+
}, { version: se, description: re } = S;
|
|
131
|
+
[Z, oe].map(
|
|
132
132
|
N
|
|
133
133
|
);
|
|
134
|
-
const
|
|
134
|
+
const ce = ({
|
|
135
135
|
input: e,
|
|
136
136
|
rootDir: n
|
|
137
137
|
}) => {
|
|
138
138
|
const o = j.resolve(n, e), t = y.readFileSync(o, "utf-8");
|
|
139
139
|
return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
|
|
140
|
-
},
|
|
140
|
+
}, ie = (e) => typeof e == "object" && !!e, ae = ({
|
|
141
141
|
content: e,
|
|
142
142
|
targetKey: n,
|
|
143
143
|
keyConfig: o
|
|
@@ -160,7 +160,7 @@ const ie = ({
|
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
case u.JSON_INJECT: {
|
|
163
|
-
if (!
|
|
163
|
+
if (!ie(e))
|
|
164
164
|
throw new Error(`${t} 类型的keyConfig需要content为json`);
|
|
165
165
|
return C({
|
|
166
166
|
sourceJson: e,
|
|
@@ -180,11 +180,11 @@ const ie = ({
|
|
|
180
180
|
default:
|
|
181
181
|
throw new Error(`不支持的类型${t}`);
|
|
182
182
|
}
|
|
183
|
-
},
|
|
183
|
+
}, ue = {
|
|
184
184
|
name: "${name}",
|
|
185
185
|
version: "${version}",
|
|
186
186
|
description: "${description}"
|
|
187
|
-
},
|
|
187
|
+
}, de = {
|
|
188
188
|
extractInput: {
|
|
189
189
|
"./package.json": {
|
|
190
190
|
name: {
|
|
@@ -223,23 +223,23 @@ const ie = ({
|
|
|
223
223
|
list: [
|
|
224
224
|
{
|
|
225
225
|
mode: U.OVERWRITE,
|
|
226
|
-
inputData: JSON.stringify(
|
|
226
|
+
inputData: JSON.stringify(ue, null, 2),
|
|
227
227
|
output: "./src/extractInfo.json"
|
|
228
228
|
}
|
|
229
229
|
]
|
|
230
230
|
}
|
|
231
231
|
}, me = () => D({
|
|
232
232
|
configPathDefault: J
|
|
233
|
-
}), G = async (e) => v(
|
|
233
|
+
}), G = async (e) => v(de, 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
241
|
handler: G
|
|
242
|
-
},
|
|
242
|
+
}, le = () => ({
|
|
243
243
|
...D({
|
|
244
244
|
configPathDefault: J
|
|
245
245
|
}),
|
|
@@ -250,22 +250,22 @@ const ie = ({
|
|
|
250
250
|
default: $.RESULT,
|
|
251
251
|
describe: "生成模式"
|
|
252
252
|
}
|
|
253
|
-
}),
|
|
253
|
+
}), fe = async ({
|
|
254
254
|
rootDir: e = process.cwd(),
|
|
255
255
|
config: n
|
|
256
256
|
}) => {
|
|
257
257
|
const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
|
|
258
|
-
(c, [
|
|
259
|
-
const f =
|
|
258
|
+
(c, [p, l]) => {
|
|
259
|
+
const f = ce({
|
|
260
260
|
rootDir: e,
|
|
261
|
-
input:
|
|
261
|
+
input: p
|
|
262
262
|
});
|
|
263
263
|
return Object.entries(l).reduce(
|
|
264
|
-
(d, [i,
|
|
265
|
-
const E =
|
|
264
|
+
(d, [i, m]) => {
|
|
265
|
+
const E = ae({
|
|
266
266
|
content: f,
|
|
267
267
|
targetKey: i,
|
|
268
|
-
keyConfig:
|
|
268
|
+
keyConfig: m
|
|
269
269
|
});
|
|
270
270
|
return d[i] = E, d;
|
|
271
271
|
},
|
|
@@ -286,13 +286,13 @@ const ie = ({
|
|
|
286
286
|
if (!n)
|
|
287
287
|
return s.error("配置文件为空"), process.exit(1);
|
|
288
288
|
const { rootDir: o } = e;
|
|
289
|
-
await
|
|
290
|
-
},
|
|
289
|
+
await fe({ rootDir: o, config: n });
|
|
290
|
+
}, Ee = {
|
|
291
291
|
command: h.GENERATE,
|
|
292
292
|
describe: "生成文件",
|
|
293
|
-
options:
|
|
293
|
+
options: le(),
|
|
294
294
|
handler: I
|
|
295
|
-
},
|
|
295
|
+
}, Ne = async (e, n) => {
|
|
296
296
|
switch (e) {
|
|
297
297
|
case h.INIT:
|
|
298
298
|
return G(n);
|
|
@@ -301,10 +301,10 @@ const ie = ({
|
|
|
301
301
|
default:
|
|
302
302
|
return I(n);
|
|
303
303
|
}
|
|
304
|
-
}, { version:
|
|
305
|
-
describe:
|
|
306
|
-
version:
|
|
307
|
-
subcommands: [
|
|
304
|
+
}, { version: ye, description: ge } = O, k = {
|
|
305
|
+
describe: ge,
|
|
306
|
+
version: ye,
|
|
307
|
+
subcommands: [pe, Ee].map(
|
|
308
308
|
N
|
|
309
309
|
),
|
|
310
310
|
demandCommandCount: 1
|
|
@@ -313,21 +313,21 @@ const ie = ({
|
|
|
313
313
|
} = O, _ = (e = !1) => {
|
|
314
314
|
const n = e ? w : void 0, o = `$0${e ? ` ${w}` : ""} <command> [options]`;
|
|
315
315
|
return { command: n, usage: o };
|
|
316
|
-
},
|
|
316
|
+
}, Oe = async () => V({
|
|
317
317
|
...k,
|
|
318
318
|
..._()
|
|
319
|
-
}),
|
|
319
|
+
}), Re = () => N({
|
|
320
320
|
...k,
|
|
321
321
|
..._(!0)
|
|
322
322
|
});
|
|
323
323
|
export {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
Re as a,
|
|
325
|
+
pe as b,
|
|
326
|
+
Oe as c,
|
|
327
327
|
I as d,
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
328
|
+
Ee as e,
|
|
329
|
+
Ne as f,
|
|
330
|
+
fe as g,
|
|
331
331
|
G as h,
|
|
332
332
|
k 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-e4f5918d.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.10
|
|
3
|
+
"version": "0.1.10",
|
|
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.10
|
|
45
|
+
"@done-coding/cli-inject": "^0.5.10",
|
|
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.10
|
|
58
|
-
"@done-coding/cli-utils": "^0.7.1
|
|
57
|
+
"@done-coding/cli-template": "0.7.10",
|
|
58
|
+
"@done-coding/cli-utils": "^0.7.1"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "299ab3991d6842c83d65816dfba6efd175aa885a",
|
|
61
61
|
"scripts": {}
|
|
62
62
|
}
|