@done-coding/cli-inject 0.4.1 → 0.4.2
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/handler.mjs +21 -18
- package/es/injectInfo.json.mjs +1 -1
- package/es/use.mjs +6 -6
- package/package.json +2 -2
- package/types/injectInfo.json.d.ts +1 -1
- package/types/use.d.ts +1 -1
package/es/handler.mjs
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import a from "node:path";
|
|
3
3
|
import t from "node:fs";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import v from "lodash.get";
|
|
5
|
+
import I from "lodash.set";
|
|
6
6
|
import e from "chalk";
|
|
7
7
|
import { getKey as J, paramsResolve as P } from "./utils/resolve.mjs";
|
|
8
|
-
const O = async (
|
|
9
|
-
const { sourceJsonFilePath: c, injectKeyPath:
|
|
8
|
+
const O = async (g) => {
|
|
9
|
+
const { sourceJsonFilePath: c, injectKeyPath: m, injectInfoFilePath: l } = g, i = process.cwd();
|
|
10
10
|
if (!c.endsWith(".json"))
|
|
11
11
|
return console.log(e.red("源文件必须是json")), process.exit(1);
|
|
12
12
|
if (!l.endsWith(".json"))
|
|
13
13
|
return console.log(e.red("注入文件必须是json")), process.exit(1);
|
|
14
|
-
const
|
|
15
|
-
(
|
|
16
|
-
const { key:
|
|
14
|
+
const p = a.resolve(i, c), d = t.readFileSync(p, "utf-8"), h = JSON.parse(d), r = m.reduce(
|
|
15
|
+
(o, u) => {
|
|
16
|
+
const { key: f, targetKey: y, paramsList: j } = J(u);
|
|
17
|
+
if (!f)
|
|
18
|
+
return console.log(e.red(`注入key不能为空,请检查配置${u}是否正确`)), o;
|
|
19
|
+
const F = v(h, f), S = P({
|
|
17
20
|
valueInit: F,
|
|
18
21
|
paramsList: j
|
|
19
22
|
});
|
|
20
|
-
return
|
|
23
|
+
return I(o, y, S), o;
|
|
21
24
|
},
|
|
22
25
|
{}
|
|
23
|
-
),
|
|
24
|
-
if (t.existsSync(
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
return console.log(e.gray("注入文件已存在且内容相同,无需重复注入")),
|
|
26
|
+
), n = a.resolve(i, l), s = JSON.stringify(r, null, 2);
|
|
27
|
+
if (t.existsSync(n)) {
|
|
28
|
+
const o = t.readFileSync(n, "utf-8");
|
|
29
|
+
if (s === o)
|
|
30
|
+
return console.log(e.gray("注入文件已存在且内容相同,无需重复注入")), r;
|
|
28
31
|
console.log(e.blue("文件内容变化,开始覆盖注入文件"));
|
|
29
32
|
} else
|
|
30
33
|
console.log(e.green("开始注入文件"));
|
|
31
|
-
return t.writeFileSync(
|
|
32
|
-
e.green(`文件注入成功: ${
|
|
33
|
-
e.blue(
|
|
34
|
-
),
|
|
34
|
+
return t.writeFileSync(n, s), console.log(
|
|
35
|
+
e.green(`文件注入成功: ${n}`),
|
|
36
|
+
e.blue(s)
|
|
37
|
+
), r;
|
|
35
38
|
};
|
|
36
39
|
export {
|
|
37
40
|
O as handler
|
package/es/injectInfo.json.mjs
CHANGED
package/es/use.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { handler as
|
|
3
|
-
const
|
|
2
|
+
import { handler as e } from "./handler.mjs";
|
|
3
|
+
const s = (n = `name:cliConfig.moduleName:REG:${/@done-coding\/cli-([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)/.source}:$1`, o = [
|
|
4
4
|
"version",
|
|
5
5
|
"name",
|
|
6
6
|
"description",
|
|
7
7
|
"name:cliConfig.namespaceDir:VALUE:.done-coding",
|
|
8
|
-
|
|
8
|
+
n
|
|
9
9
|
]) => {
|
|
10
|
-
|
|
10
|
+
e({
|
|
11
11
|
sourceJsonFilePath: "./package.json",
|
|
12
|
-
injectKeyPath:
|
|
12
|
+
injectKeyPath: o,
|
|
13
13
|
injectInfoFilePath: "./src/injectInfo.json"
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
export {
|
|
17
|
-
|
|
17
|
+
s as injectDoneCodingCliInfo
|
|
18
18
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-inject",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "信息注入命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"prompts": "^2.4.2",
|
|
73
73
|
"yargs": "^17.7.2"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "5a8844aa8d54b3f84ab8aa287479bda2da13467a"
|
|
76
76
|
}
|
package/types/use.d.ts
CHANGED