@done-coding/cli-extract 0.1.5 → 0.1.6-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-a8701010.js → index-a262eb93.js} +24 -24
- package/es/index.mjs +1 -1
- package/package.json +5 -5
- package/types/injectInfo.json.d.ts +1 -1
package/es/cli.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
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
|
|
3
|
+
import { log as r, _get as O, _curry as I, createSubcommand as R, getConfigFileCommonOptions as j, initHandlerCommon as v, readConfigFile as $, _set as H, createMainCommand as V } from "@done-coding/cli-utils";
|
|
4
4
|
import D from "node:path";
|
|
5
5
|
import C from "node:fs";
|
|
6
6
|
import { OutputModeEnum as L, batchCompileHandler as W } from "@done-coding/cli-template";
|
|
7
|
-
const
|
|
7
|
+
const h = ({
|
|
8
8
|
sourceJson: e,
|
|
9
9
|
targetKey: n,
|
|
10
10
|
keyConfig: t
|
|
@@ -17,8 +17,8 @@ const R = ({
|
|
|
17
17
|
const { type: i = s.READ } = o;
|
|
18
18
|
switch (i) {
|
|
19
19
|
case s.REG: {
|
|
20
|
-
const { sourceKey: a, pattern: f, replaceValue: E, flags: g } = o,
|
|
21
|
-
return typeof c == "string" ? c.replace(
|
|
20
|
+
const { sourceKey: a, pattern: f, replaceValue: E, flags: g } = o, p = new RegExp(f, g ?? void 0), c = O(e, a);
|
|
21
|
+
return typeof c == "string" ? c.replace(p, E) : (r.warn(
|
|
22
22
|
`${c}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
23
23
|
), c);
|
|
24
24
|
}
|
|
@@ -49,7 +49,7 @@ const R = ({
|
|
|
49
49
|
injectFilePath: "./src/injectInfo.json"
|
|
50
50
|
}, w = U, x = {
|
|
51
51
|
name: "@done-coding/cli-inject",
|
|
52
|
-
version: "0.5.
|
|
52
|
+
version: "0.5.6-alpha.0",
|
|
53
53
|
description: "信息(JSON)注入命令行工具",
|
|
54
54
|
cliConfig: {
|
|
55
55
|
namespaceDir: ".done-coding",
|
|
@@ -84,21 +84,21 @@ const R = ({
|
|
|
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 = C.readFileSync(E, "utf-8"),
|
|
87
|
+
const E = D.resolve(e, o), g = C.readFileSync(E, "utf-8"), p = JSON.parse(g), c = Object.entries(f).reduce(
|
|
88
88
|
(N, [T, P]) => {
|
|
89
|
-
const M =
|
|
89
|
+
const M = h({ sourceJson: p, targetKey: T, keyConfig: P });
|
|
90
90
|
return H(N, T, M), N;
|
|
91
91
|
},
|
|
92
92
|
{}
|
|
93
|
-
),
|
|
94
|
-
if (C.existsSync(
|
|
95
|
-
const N = C.readFileSync(
|
|
93
|
+
), d = D.resolve(e, a), y = JSON.stringify(c, null, 2);
|
|
94
|
+
if (C.existsSync(d)) {
|
|
95
|
+
const N = C.readFileSync(d, "utf-8");
|
|
96
96
|
if (y === N)
|
|
97
97
|
return r.skip("注入文件已存在且内容相同,无需重复注入"), c;
|
|
98
98
|
r.stage("文件内容变化,开始覆盖注入文件");
|
|
99
99
|
} else
|
|
100
100
|
r.stage("开始注入文件");
|
|
101
|
-
C.writeFileSync(
|
|
101
|
+
C.writeFileSync(d, y), r.success(`文件注入成功: ${d}`), r.info(y);
|
|
102
102
|
}, Z = async (e) => {
|
|
103
103
|
const n = await $(e);
|
|
104
104
|
if (!n)
|
|
@@ -125,7 +125,7 @@ const R = ({
|
|
|
125
125
|
)
|
|
126
126
|
};
|
|
127
127
|
[te, oe].map(
|
|
128
|
-
|
|
128
|
+
R
|
|
129
129
|
);
|
|
130
130
|
const re = {
|
|
131
131
|
name: "${name}",
|
|
@@ -177,7 +177,7 @@ const re = {
|
|
|
177
177
|
}
|
|
178
178
|
}, S = {
|
|
179
179
|
name: "@done-coding/cli-extract",
|
|
180
|
-
version: "0.1.
|
|
180
|
+
version: "0.1.6-alpha.0",
|
|
181
181
|
description: "信息提取命令行工具",
|
|
182
182
|
cliConfig: {
|
|
183
183
|
namespaceDir: ".done-coding",
|
|
@@ -187,11 +187,11 @@ const re = {
|
|
|
187
187
|
cliConfig: { namespaceDir: ce, moduleName: ie }
|
|
188
188
|
} = S, ae = `./${ce}/${ie}`, b = `${ae}.json5`, ue = () => j({
|
|
189
189
|
configPathDefault: b
|
|
190
|
-
}),
|
|
190
|
+
}), pe = async (e) => v(se, e, {
|
|
191
191
|
onFileGenerated: () => {
|
|
192
192
|
r.info("文件生成成功");
|
|
193
193
|
}
|
|
194
|
-
}),
|
|
194
|
+
}), de = ({
|
|
195
195
|
input: e,
|
|
196
196
|
rootDir: n
|
|
197
197
|
}) => {
|
|
@@ -207,7 +207,7 @@ const re = {
|
|
|
207
207
|
case u.REG: {
|
|
208
208
|
if (typeof e != "string")
|
|
209
209
|
throw new Error(`${o} 类型的keyConfig需要content为字符串`);
|
|
210
|
-
return
|
|
210
|
+
return h({
|
|
211
211
|
sourceJson: {
|
|
212
212
|
[n]: e
|
|
213
213
|
},
|
|
@@ -222,7 +222,7 @@ const re = {
|
|
|
222
222
|
case u.JSON_INJECT: {
|
|
223
223
|
if (!me(e))
|
|
224
224
|
throw new Error(`${o} 类型的keyConfig需要content为json`);
|
|
225
|
-
return
|
|
225
|
+
return h({
|
|
226
226
|
sourceJson: e,
|
|
227
227
|
targetKey: n,
|
|
228
228
|
keyConfig: t.inject
|
|
@@ -241,18 +241,18 @@ const re = {
|
|
|
241
241
|
}) => {
|
|
242
242
|
const { extractInput: t, extractOutput: o } = n, i = Object.entries(t).reduce(
|
|
243
243
|
(a, [f, E]) => {
|
|
244
|
-
const g =
|
|
244
|
+
const g = de({
|
|
245
245
|
rootDir: e,
|
|
246
246
|
input: f
|
|
247
247
|
});
|
|
248
248
|
return Object.entries(E).reduce(
|
|
249
|
-
(
|
|
249
|
+
(p, [c, d]) => {
|
|
250
250
|
const y = le({
|
|
251
251
|
content: g,
|
|
252
252
|
targetKey: c,
|
|
253
|
-
keyConfig:
|
|
253
|
+
keyConfig: d
|
|
254
254
|
});
|
|
255
|
-
return
|
|
255
|
+
return p[c] = y, p;
|
|
256
256
|
},
|
|
257
257
|
a
|
|
258
258
|
);
|
|
@@ -272,7 +272,7 @@ const re = {
|
|
|
272
272
|
return r.error("配置文件为空"), process.exit(1);
|
|
273
273
|
const { rootDir: t } = e;
|
|
274
274
|
await Ee({ rootDir: t, config: n });
|
|
275
|
-
}, G = async (e, n) => e === l.INIT ?
|
|
275
|
+
}, G = async (e, n) => e === l.INIT ? pe(n) : e === l.GENERATE ? ge(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
|
|
276
276
|
version: ye,
|
|
277
277
|
description: Ce,
|
|
278
278
|
cliConfig: { moduleName: A }
|
|
@@ -294,7 +294,7 @@ const re = {
|
|
|
294
294
|
describe: Ce,
|
|
295
295
|
version: ye,
|
|
296
296
|
subcommands: [Ne, Ie].map(
|
|
297
|
-
|
|
297
|
+
R
|
|
298
298
|
),
|
|
299
299
|
demandCommandCount: 1
|
|
300
300
|
}, k = (e = !1) => {
|
|
@@ -303,7 +303,7 @@ const re = {
|
|
|
303
303
|
}, Ae = async () => V({
|
|
304
304
|
..._,
|
|
305
305
|
...k()
|
|
306
|
-
}), ve = () =>
|
|
306
|
+
}), ve = () => R({
|
|
307
307
|
..._,
|
|
308
308
|
...k(!0)
|
|
309
309
|
});
|
package/es/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-extract",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-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.
|
|
54
|
+
"@done-coding/cli-inject": "^0.5.6-alpha.0",
|
|
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.
|
|
67
|
-
"@done-coding/cli-utils": "^0.
|
|
66
|
+
"@done-coding/cli-template": "0.7.7-alpha.0",
|
|
67
|
+
"@done-coding/cli-utils": "^0.4.0-alpha.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "360b14a641064f732b01ffd6339c2f1963945b61"
|
|
70
70
|
}
|