@done-coding/cli-extract 0.1.2-alpha.0 → 0.1.3
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-a46b5548.js → index-7d4db538.js} +56 -56
- 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,7 +1,7 @@
|
|
|
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 h, getConfigFileCommonOptions as
|
|
4
|
-
import
|
|
3
|
+
import { log as r, _get as O, _curry as I, createSubcommand as h, getConfigFileCommonOptions as D, initHandlerCommon as v, readConfigFile as $, _set as H, createMainCommand as V } from "@done-coding/cli-utils";
|
|
4
|
+
import j 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 R = ({
|
|
@@ -33,7 +33,7 @@ const R = ({
|
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
},
|
|
36
|
+
}, w = {
|
|
37
37
|
sourceFilePath: "./package.json",
|
|
38
38
|
keyConfigMap: {
|
|
39
39
|
name: {
|
|
@@ -47,27 +47,27 @@ const R = ({
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
injectFilePath: "./src/injectInfo.json"
|
|
50
|
-
},
|
|
50
|
+
}, x = {
|
|
51
51
|
name: "@done-coding/cli-inject",
|
|
52
|
-
version: "0.5.
|
|
52
|
+
version: "0.5.3",
|
|
53
53
|
description: "信息(JSON)注入命令行工具",
|
|
54
54
|
cliConfig: {
|
|
55
55
|
namespaceDir: ".done-coding",
|
|
56
56
|
moduleName: "inject"
|
|
57
57
|
}
|
|
58
58
|
}, {
|
|
59
|
-
cliConfig: { namespaceDir:
|
|
60
|
-
} = x,
|
|
59
|
+
cliConfig: { namespaceDir: U, moduleName: X }
|
|
60
|
+
} = x, K = `./${U}/${X}`, F = `${K}.json`, q = () => D({
|
|
61
61
|
configPathDefault: F
|
|
62
|
-
}),
|
|
62
|
+
}), z = async (e) => v(w, e, {
|
|
63
63
|
onFileGenerated: () => {
|
|
64
64
|
r.info("文件生成成功");
|
|
65
65
|
}
|
|
66
|
-
}),
|
|
67
|
-
...
|
|
66
|
+
}), B = () => ({
|
|
67
|
+
...D({
|
|
68
68
|
configPathDefault: F
|
|
69
69
|
})
|
|
70
|
-
}),
|
|
70
|
+
}), Q = async ({
|
|
71
71
|
rootDir: e = process.cwd(),
|
|
72
72
|
config: n = w,
|
|
73
73
|
keyConfigMap: t = {}
|
|
@@ -84,13 +84,13 @@ 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 =
|
|
87
|
+
const E = j.resolve(e, o), g = C.readFileSync(E, "utf-8"), d = JSON.parse(g), c = Object.entries(f).reduce(
|
|
88
88
|
(N, [T, P]) => {
|
|
89
89
|
const M = R({ sourceJson: d, targetKey: T, keyConfig: P });
|
|
90
90
|
return H(N, T, M), N;
|
|
91
91
|
},
|
|
92
92
|
{}
|
|
93
|
-
), p =
|
|
93
|
+
), p = j.resolve(e, a), y = JSON.stringify(c, null, 2);
|
|
94
94
|
if (C.existsSync(p)) {
|
|
95
95
|
const N = C.readFileSync(p, "utf-8");
|
|
96
96
|
if (y === N)
|
|
@@ -99,39 +99,39 @@ const R = ({
|
|
|
99
99
|
} else
|
|
100
100
|
r.stage("开始注入文件");
|
|
101
101
|
C.writeFileSync(p, y), r.success(`文件注入成功: ${p}`), r.info(y);
|
|
102
|
-
},
|
|
102
|
+
}, Y = async (e) => {
|
|
103
103
|
const n = await $(e);
|
|
104
104
|
if (!n)
|
|
105
105
|
return r.error("配置文件为空"), process.exit(1);
|
|
106
106
|
const { rootDir: t } = e;
|
|
107
|
-
await
|
|
108
|
-
}, J = async (e, n) => e === m.INIT ?
|
|
109
|
-
version:
|
|
110
|
-
description:
|
|
111
|
-
cliConfig: { moduleName:
|
|
112
|
-
} = x,
|
|
107
|
+
await Q({ rootDir: t, config: n });
|
|
108
|
+
}, J = async (e, n) => e === m.INIT ? z(n) : e === m.GENERATE ? Y(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
|
|
109
|
+
version: Z,
|
|
110
|
+
description: ee,
|
|
111
|
+
cliConfig: { moduleName: Te }
|
|
112
|
+
} = x, ne = {
|
|
113
113
|
command: m.INIT,
|
|
114
114
|
describe: "初始化提取配置文件",
|
|
115
|
-
options:
|
|
115
|
+
options: q(),
|
|
116
116
|
handler: I(J)(
|
|
117
117
|
m.INIT
|
|
118
118
|
)
|
|
119
|
-
},
|
|
119
|
+
}, te = {
|
|
120
120
|
command: m.GENERATE,
|
|
121
121
|
describe: "提取信息",
|
|
122
|
-
options:
|
|
122
|
+
options: B(),
|
|
123
123
|
handler: I(J)(
|
|
124
124
|
m.GENERATE
|
|
125
125
|
)
|
|
126
126
|
};
|
|
127
|
-
[
|
|
127
|
+
[ne, te].map(
|
|
128
128
|
h
|
|
129
129
|
);
|
|
130
|
-
const
|
|
130
|
+
const oe = {
|
|
131
131
|
name: "${name}",
|
|
132
132
|
version: "${version}",
|
|
133
133
|
description: "${description}"
|
|
134
|
-
},
|
|
134
|
+
}, re = {
|
|
135
135
|
extractInput: {
|
|
136
136
|
"./package.json": {
|
|
137
137
|
name: {
|
|
@@ -170,34 +170,34 @@ const re = {
|
|
|
170
170
|
list: [
|
|
171
171
|
{
|
|
172
172
|
mode: L.OVERWRITE,
|
|
173
|
-
inputData: JSON.stringify(
|
|
173
|
+
inputData: JSON.stringify(oe, null, 2),
|
|
174
174
|
output: "./src/extractInfo.json"
|
|
175
175
|
}
|
|
176
176
|
]
|
|
177
177
|
}
|
|
178
178
|
}, S = {
|
|
179
179
|
name: "@done-coding/cli-extract",
|
|
180
|
-
version: "0.1.
|
|
180
|
+
version: "0.1.3",
|
|
181
181
|
description: "信息提取命令行工具",
|
|
182
182
|
cliConfig: {
|
|
183
183
|
namespaceDir: ".done-coding",
|
|
184
184
|
moduleName: "extract"
|
|
185
185
|
}
|
|
186
186
|
}, {
|
|
187
|
-
cliConfig: { namespaceDir:
|
|
188
|
-
} = S,
|
|
187
|
+
cliConfig: { namespaceDir: se, moduleName: ce }
|
|
188
|
+
} = S, ie = `./${se}/${ce}`, b = `${ie}.json5`, ae = () => D({
|
|
189
189
|
configPathDefault: b
|
|
190
|
-
}),
|
|
190
|
+
}), ue = async (e) => v(re, e, {
|
|
191
191
|
onFileGenerated: () => {
|
|
192
192
|
r.info("文件生成成功");
|
|
193
193
|
}
|
|
194
|
-
}),
|
|
194
|
+
}), de = ({
|
|
195
195
|
input: e,
|
|
196
196
|
rootDir: n
|
|
197
197
|
}) => {
|
|
198
|
-
const t =
|
|
198
|
+
const t = j.resolve(n, e), o = C.readFileSync(t, "utf-8");
|
|
199
199
|
return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(o) : o;
|
|
200
|
-
},
|
|
200
|
+
}, pe = (e) => typeof e == "object" && !!e, me = ({
|
|
201
201
|
content: e,
|
|
202
202
|
targetKey: n,
|
|
203
203
|
keyConfig: t
|
|
@@ -220,7 +220,7 @@ const re = {
|
|
|
220
220
|
});
|
|
221
221
|
}
|
|
222
222
|
case u.JSON_INJECT: {
|
|
223
|
-
if (!
|
|
223
|
+
if (!pe(e))
|
|
224
224
|
throw new Error(`${o} 类型的keyConfig需要content为json`);
|
|
225
225
|
return R({
|
|
226
226
|
sourceJson: e,
|
|
@@ -231,23 +231,23 @@ const re = {
|
|
|
231
231
|
default:
|
|
232
232
|
throw new Error(`不支持的类型${o}`);
|
|
233
233
|
}
|
|
234
|
-
},
|
|
235
|
-
...
|
|
234
|
+
}, le = () => ({
|
|
235
|
+
...D({
|
|
236
236
|
configPathDefault: b
|
|
237
237
|
})
|
|
238
|
-
}),
|
|
238
|
+
}), fe = async ({
|
|
239
239
|
rootDir: e = process.cwd(),
|
|
240
240
|
config: n
|
|
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
|
(d, [c, p]) => {
|
|
250
|
-
const y =
|
|
250
|
+
const y = me({
|
|
251
251
|
content: g,
|
|
252
252
|
targetKey: c,
|
|
253
253
|
keyConfig: p
|
|
@@ -266,49 +266,49 @@ const re = {
|
|
|
266
266
|
},
|
|
267
267
|
o
|
|
268
268
|
);
|
|
269
|
-
},
|
|
269
|
+
}, Ee = async (e) => {
|
|
270
270
|
const n = await $(e);
|
|
271
271
|
if (!n)
|
|
272
272
|
return r.error("配置文件为空"), process.exit(1);
|
|
273
273
|
const { rootDir: t } = e;
|
|
274
|
-
await
|
|
275
|
-
}, G = async (e, n) => e === l.INIT ?
|
|
276
|
-
version:
|
|
277
|
-
description:
|
|
274
|
+
await fe({ rootDir: t, config: n });
|
|
275
|
+
}, G = async (e, n) => e === l.INIT ? ue(n) : e === l.GENERATE ? Ee(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
|
|
276
|
+
version: ge,
|
|
277
|
+
description: ye,
|
|
278
278
|
cliConfig: { moduleName: A }
|
|
279
|
-
} = S,
|
|
279
|
+
} = S, Ce = {
|
|
280
280
|
command: l.INIT,
|
|
281
281
|
describe: "初始化提取配置文件",
|
|
282
|
-
options:
|
|
282
|
+
options: ae(),
|
|
283
283
|
handler: I(G)(
|
|
284
284
|
l.INIT
|
|
285
285
|
)
|
|
286
|
-
},
|
|
286
|
+
}, Ne = {
|
|
287
287
|
command: l.GENERATE,
|
|
288
288
|
describe: "提取信息",
|
|
289
|
-
options:
|
|
289
|
+
options: le(),
|
|
290
290
|
handler: I(G)(
|
|
291
291
|
l.GENERATE
|
|
292
292
|
)
|
|
293
293
|
}, _ = {
|
|
294
|
-
describe:
|
|
295
|
-
version:
|
|
296
|
-
subcommands: [
|
|
294
|
+
describe: ye,
|
|
295
|
+
version: ge,
|
|
296
|
+
subcommands: [Ce, Ne].map(
|
|
297
297
|
h
|
|
298
298
|
),
|
|
299
299
|
demandCommandCount: 1
|
|
300
300
|
}, k = (e = !1) => {
|
|
301
301
|
const n = e ? A : void 0, t = `$0${e ? ` ${A}` : ""} <command> [options]`;
|
|
302
302
|
return { command: n, usage: t };
|
|
303
|
-
},
|
|
303
|
+
}, Oe = async () => V({
|
|
304
304
|
..._,
|
|
305
305
|
...k()
|
|
306
|
-
}),
|
|
306
|
+
}), Ae = () => h({
|
|
307
307
|
..._,
|
|
308
308
|
...k(!0)
|
|
309
309
|
});
|
|
310
310
|
export {
|
|
311
|
-
|
|
312
|
-
|
|
311
|
+
Ae as a,
|
|
312
|
+
Oe as c,
|
|
313
313
|
G as h
|
|
314
314
|
};
|
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.3",
|
|
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.3",
|
|
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.3.
|
|
66
|
+
"@done-coding/cli-template": "0.7.4",
|
|
67
|
+
"@done-coding/cli-utils": "^0.3.3"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "3caf888c1978970b95d95219ac63d0a3ed2b2912"
|
|
70
70
|
}
|