@done-coding/cli-extract 0.1.8-alpha.0 → 0.1.8
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-9abc1104.js → index-2f3f403a.js} +23 -23
- package/es/index.mjs +1 -1
- package/package.json +7 -6
- package/types/injectInfo.json.d.ts +1 -1
package/es/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { log as r, _get as O, _curry as D, createSubcommand as
|
|
2
|
+
import { log as r, _get as O, _curry as D, createSubcommand as h, getConfigFileCommonOptions as j, initHandlerCommon as F, readConfigFile as v, _set as H, createMainCommand as V } from "@done-coding/cli-utils";
|
|
3
3
|
import { a as s, e as m, E as u, S as l } from "./types-a1ee6691-9629699d.js";
|
|
4
|
-
import
|
|
4
|
+
import R 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
7
|
const N = ({
|
|
@@ -17,8 +17,8 @@ const N = ({
|
|
|
17
17
|
const { type: a = s.READ } = t;
|
|
18
18
|
switch (a) {
|
|
19
19
|
case s.REG: {
|
|
20
|
-
const { sourceKey: c, pattern: f, replaceValue: E, flags: g } = t,
|
|
21
|
-
return typeof i == "string" ? i.replace(
|
|
20
|
+
const { sourceKey: c, pattern: f, replaceValue: E, flags: g } = t, d = new RegExp(f, g ?? void 0), i = O(e, c);
|
|
21
|
+
return typeof i == "string" ? i.replace(d, E) : (r.warn(
|
|
22
22
|
`${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
23
23
|
), i);
|
|
24
24
|
}
|
|
@@ -51,7 +51,7 @@ const N = ({
|
|
|
51
51
|
injectFilePath: "./src/injectInfo.json"
|
|
52
52
|
}, w = {
|
|
53
53
|
name: "@done-coding/cli-inject",
|
|
54
|
-
version: "0.5.8
|
|
54
|
+
version: "0.5.8",
|
|
55
55
|
description: "信息(JSON)注入命令行工具",
|
|
56
56
|
cliConfig: {
|
|
57
57
|
namespaceDir: ".done-coding",
|
|
@@ -86,21 +86,21 @@ const N = ({
|
|
|
86
86
|
return r.error("源文件必须是json"), process.exit(1);
|
|
87
87
|
if (!c.endsWith(".json"))
|
|
88
88
|
return r.error("注入文件必须是json"), process.exit(1);
|
|
89
|
-
const E =
|
|
89
|
+
const E = R.resolve(e, t), g = C.readFileSync(E, "utf-8"), d = JSON.parse(g), i = Object.entries(f).reduce(
|
|
90
90
|
(I, [T, P]) => {
|
|
91
|
-
const M = N({ sourceJson:
|
|
91
|
+
const M = N({ sourceJson: d, targetKey: T, keyConfig: P });
|
|
92
92
|
return H(I, T, M), I;
|
|
93
93
|
},
|
|
94
94
|
{}
|
|
95
|
-
),
|
|
96
|
-
if (C.existsSync(
|
|
97
|
-
const I = C.readFileSync(
|
|
95
|
+
), p = R.resolve(e, c), y = JSON.stringify(i, null, 2);
|
|
96
|
+
if (C.existsSync(p)) {
|
|
97
|
+
const I = C.readFileSync(p, "utf-8");
|
|
98
98
|
if (y === I)
|
|
99
99
|
return r.skip("注入文件已存在且内容相同,无需重复注入"), i;
|
|
100
100
|
r.stage("文件内容变化,开始覆盖注入文件");
|
|
101
101
|
} else
|
|
102
102
|
r.stage("开始注入文件");
|
|
103
|
-
C.writeFileSync(
|
|
103
|
+
C.writeFileSync(p, y), r.success(`文件注入成功: ${p}`), r.info(y);
|
|
104
104
|
}, Y = async (e) => {
|
|
105
105
|
const n = await v(e);
|
|
106
106
|
if (!n)
|
|
@@ -127,7 +127,7 @@ const N = ({
|
|
|
127
127
|
)
|
|
128
128
|
};
|
|
129
129
|
[ne, te].map(
|
|
130
|
-
|
|
130
|
+
h
|
|
131
131
|
);
|
|
132
132
|
const oe = {
|
|
133
133
|
name: "${name}",
|
|
@@ -179,7 +179,7 @@ const oe = {
|
|
|
179
179
|
}
|
|
180
180
|
}, S = {
|
|
181
181
|
name: "@done-coding/cli-extract",
|
|
182
|
-
version: "0.1.8
|
|
182
|
+
version: "0.1.8",
|
|
183
183
|
description: "信息提取命令行工具",
|
|
184
184
|
cliConfig: {
|
|
185
185
|
namespaceDir: ".done-coding",
|
|
@@ -193,13 +193,13 @@ const oe = {
|
|
|
193
193
|
onFileGenerated: () => {
|
|
194
194
|
r.info("文件生成成功");
|
|
195
195
|
}
|
|
196
|
-
}),
|
|
196
|
+
}), de = ({
|
|
197
197
|
input: e,
|
|
198
198
|
rootDir: n
|
|
199
199
|
}) => {
|
|
200
|
-
const o =
|
|
200
|
+
const o = R.resolve(n, e), t = C.readFileSync(o, "utf-8");
|
|
201
201
|
return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
|
|
202
|
-
},
|
|
202
|
+
}, pe = (e) => typeof e == "object" && !!e, me = ({
|
|
203
203
|
content: e,
|
|
204
204
|
targetKey: n,
|
|
205
205
|
keyConfig: o
|
|
@@ -222,7 +222,7 @@ const oe = {
|
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
224
|
case u.JSON_INJECT: {
|
|
225
|
-
if (!
|
|
225
|
+
if (!pe(e))
|
|
226
226
|
throw new Error(`${t} 类型的keyConfig需要content为json`);
|
|
227
227
|
return N({
|
|
228
228
|
sourceJson: e,
|
|
@@ -252,18 +252,18 @@ const oe = {
|
|
|
252
252
|
}) => {
|
|
253
253
|
const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
|
|
254
254
|
(c, [f, E]) => {
|
|
255
|
-
const g =
|
|
255
|
+
const g = de({
|
|
256
256
|
rootDir: e,
|
|
257
257
|
input: f
|
|
258
258
|
});
|
|
259
259
|
return Object.entries(E).reduce(
|
|
260
|
-
(
|
|
260
|
+
(d, [i, p]) => {
|
|
261
261
|
const y = me({
|
|
262
262
|
content: g,
|
|
263
263
|
targetKey: i,
|
|
264
|
-
keyConfig:
|
|
264
|
+
keyConfig: p
|
|
265
265
|
});
|
|
266
|
-
return
|
|
266
|
+
return d[i] = y, d;
|
|
267
267
|
},
|
|
268
268
|
c
|
|
269
269
|
);
|
|
@@ -305,7 +305,7 @@ const oe = {
|
|
|
305
305
|
describe: ye,
|
|
306
306
|
version: ge,
|
|
307
307
|
subcommands: [Ce, Ie].map(
|
|
308
|
-
|
|
308
|
+
h
|
|
309
309
|
),
|
|
310
310
|
demandCommandCount: 1
|
|
311
311
|
}, k = (e = !1) => {
|
|
@@ -314,7 +314,7 @@ const oe = {
|
|
|
314
314
|
}, Oe = async () => V({
|
|
315
315
|
..._,
|
|
316
316
|
...k()
|
|
317
|
-
}), Ae = () =>
|
|
317
|
+
}), Ae = () => h({
|
|
318
318
|
..._,
|
|
319
319
|
...k(!0)
|
|
320
320
|
});
|
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.8
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "信息提取命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"import": "./es/index.mjs"
|
|
14
|
+
"import": "./es/index.mjs",
|
|
15
|
+
"types": "./types/index.d.ts"
|
|
15
16
|
},
|
|
16
17
|
"./helpers": {
|
|
17
18
|
"import": "./es/helpers.mjs",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"license": "MIT",
|
|
52
53
|
"sideEffects": false,
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@done-coding/cli-inject": "^0.5.8
|
|
55
|
+
"@done-coding/cli-inject": "^0.5.8",
|
|
55
56
|
"@types/node": "^18.0.0",
|
|
56
57
|
"@types/yargs": "^17.0.28",
|
|
57
58
|
"rimraf": "^6.0.1",
|
|
@@ -63,8 +64,8 @@
|
|
|
63
64
|
"node": ">=18.0.0"
|
|
64
65
|
},
|
|
65
66
|
"dependencies": {
|
|
66
|
-
"@done-coding/cli-template": "0.7.8
|
|
67
|
-
"@done-coding/cli-utils": "^0.
|
|
67
|
+
"@done-coding/cli-template": "0.7.8",
|
|
68
|
+
"@done-coding/cli-utils": "^0.7.0"
|
|
68
69
|
},
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "b4fb4f2380a14f72597a1dbfd1bbce22287ef02f"
|
|
70
71
|
}
|