done-coding-inject 0.5.10 → 0.5.11
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-e2ac179b.js → index-f6928e73.js} +27 -27
- package/es/index.mjs +1 -1
- package/package.json +3 -3
package/es/cli.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { I as r, S as d } from "./index-a1ee6691.js";
|
|
3
|
-
import { log as o, _get as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { log as o, _get as j, initHandlerCommon as b, getConfigFileCommonOptions as D, _set as w, readConfigFile as _, createSubcommand as N, createMainCommand as k } from "@done-coding/cli-utils";
|
|
4
|
+
import $ from "node:path";
|
|
5
|
+
import m from "node:fs";
|
|
6
6
|
const M = ({
|
|
7
7
|
sourceJson: e,
|
|
8
8
|
targetKey: n,
|
|
@@ -16,7 +16,7 @@ const M = ({
|
|
|
16
16
|
const { type: a = r.READ } = s;
|
|
17
17
|
switch (a) {
|
|
18
18
|
case r.REG: {
|
|
19
|
-
const { sourceKey: c, pattern: f, replaceValue: p, flags: g } = s, y = new RegExp(f, g ?? void 0), i =
|
|
19
|
+
const { sourceKey: c, pattern: f, replaceValue: p, flags: g } = s, y = new RegExp(f, g ?? void 0), i = j(e, c);
|
|
20
20
|
return typeof i == "string" ? i.replace(y, p) : (o.warn(
|
|
21
21
|
`${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
22
22
|
), i);
|
|
@@ -27,7 +27,7 @@ const M = ({
|
|
|
27
27
|
}
|
|
28
28
|
case r.READ: {
|
|
29
29
|
const { sourceKey: c = n } = s;
|
|
30
|
-
return
|
|
30
|
+
return j(e, c);
|
|
31
31
|
}
|
|
32
32
|
default: {
|
|
33
33
|
o.warn(`未知的配置类型${a}`);
|
|
@@ -36,7 +36,7 @@ const M = ({
|
|
|
36
36
|
}
|
|
37
37
|
}, h = {
|
|
38
38
|
name: "@done-coding/cli-inject",
|
|
39
|
-
version: "0.5.
|
|
39
|
+
version: "0.5.11",
|
|
40
40
|
description: "信息(JSON)注入命令行工具",
|
|
41
41
|
cliConfig: {
|
|
42
42
|
namespaceDir: ".done-coding",
|
|
@@ -44,7 +44,7 @@ const M = ({
|
|
|
44
44
|
}
|
|
45
45
|
}, {
|
|
46
46
|
cliConfig: { namespaceDir: x, moduleName: G }
|
|
47
|
-
} = h, L = `./${x}/${G}`,
|
|
47
|
+
} = h, L = `./${x}/${G}`, R = `${L}.json`, F = {
|
|
48
48
|
sourceFilePath: "./package.json",
|
|
49
49
|
keyConfigMap: {
|
|
50
50
|
name: {
|
|
@@ -58,9 +58,9 @@ const M = ({
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
injectFilePath: "./src/injectInfo.json"
|
|
61
|
-
}, J = () =>
|
|
62
|
-
configPathDefault:
|
|
63
|
-
}), O = async (e) => b(
|
|
61
|
+
}, J = () => D({
|
|
62
|
+
configPathDefault: R
|
|
63
|
+
}), O = async (e) => b(F, e, {
|
|
64
64
|
onFileGenerated: () => {
|
|
65
65
|
o.info("文件生成成功");
|
|
66
66
|
}
|
|
@@ -70,12 +70,12 @@ const M = ({
|
|
|
70
70
|
options: J(),
|
|
71
71
|
handler: O
|
|
72
72
|
}, V = () => ({
|
|
73
|
-
...
|
|
74
|
-
configPathDefault:
|
|
73
|
+
...D({
|
|
74
|
+
configPathDefault: R
|
|
75
75
|
})
|
|
76
76
|
}), H = async ({
|
|
77
77
|
rootDir: e = process.cwd(),
|
|
78
|
-
config: n =
|
|
78
|
+
config: n = F,
|
|
79
79
|
keyConfigMap: t = {}
|
|
80
80
|
} = {}) => {
|
|
81
81
|
const {
|
|
@@ -90,23 +90,23 @@ const M = ({
|
|
|
90
90
|
return o.error("源文件必须是json"), process.exit(1);
|
|
91
91
|
if (!c.endsWith(".json"))
|
|
92
92
|
return o.error("注入文件必须是json"), process.exit(1);
|
|
93
|
-
const p =
|
|
94
|
-
(
|
|
95
|
-
const T = M({ sourceJson: y, targetKey:
|
|
96
|
-
return w(
|
|
93
|
+
const p = $.resolve(e, s), g = m.readFileSync(p, "utf-8"), y = JSON.parse(g), i = Object.entries(f).reduce(
|
|
94
|
+
(u, [I, P]) => {
|
|
95
|
+
const T = M({ sourceJson: y, targetKey: I, keyConfig: P });
|
|
96
|
+
return w(u, I, T), u;
|
|
97
97
|
},
|
|
98
98
|
{}
|
|
99
|
-
), l =
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
if (E ===
|
|
99
|
+
), l = $.resolve(e, c), E = JSON.stringify(i, null, 2);
|
|
100
|
+
if (m.existsSync(l)) {
|
|
101
|
+
const u = m.readFileSync(l, "utf-8");
|
|
102
|
+
if (E === u)
|
|
103
103
|
return o.skip("注入文件已存在且内容相同,无需重复注入"), i;
|
|
104
104
|
o.stage("文件内容变化,开始覆盖注入文件");
|
|
105
105
|
} else
|
|
106
106
|
o.stage("开始注入文件");
|
|
107
|
-
|
|
107
|
+
m.writeFileSync(l, E), o.success(`文件注入成功: ${l}`), o.info(E);
|
|
108
108
|
}, C = async (e) => {
|
|
109
|
-
const n = await _(e);
|
|
109
|
+
const n = await _(e, () => (o.info("配置文件为空,使用默认配置"), F));
|
|
110
110
|
if (!n)
|
|
111
111
|
return o.error("配置文件为空"), process.exit(1);
|
|
112
112
|
const { rootDir: t } = e;
|
|
@@ -129,18 +129,18 @@ const M = ({
|
|
|
129
129
|
describe: X,
|
|
130
130
|
version: W,
|
|
131
131
|
subcommands: [U, K].map(
|
|
132
|
-
|
|
132
|
+
N
|
|
133
133
|
),
|
|
134
134
|
demandCommandCount: 1
|
|
135
135
|
}, {
|
|
136
|
-
cliConfig: { moduleName:
|
|
136
|
+
cliConfig: { moduleName: A }
|
|
137
137
|
} = h, v = (e = !1) => {
|
|
138
|
-
const n = e ?
|
|
138
|
+
const n = e ? A : void 0, t = `$0${e ? ` ${A}` : ""} <command> [options]`;
|
|
139
139
|
return { command: n, usage: t };
|
|
140
140
|
}, Z = async () => k({
|
|
141
141
|
...S,
|
|
142
142
|
...v()
|
|
143
|
-
}), ee = () =>
|
|
143
|
+
}), ee = () => N({
|
|
144
144
|
...S,
|
|
145
145
|
...v(!0)
|
|
146
146
|
});
|
package/es/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as r, a as i, e as s, g as t, d, f as l, b as f, h as p, k as C } from "./index-
|
|
2
|
+
import { i as r, a as i, e as s, g as t, d, f as l, b as f, h as p, k as C } from "./index-f6928e73.js";
|
|
3
3
|
import { I as g, S as u } from "./index-a1ee6691.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-inject",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"description": "信息(JSON)注入命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"node": ">=18.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@done-coding/cli-utils": "^0.7.
|
|
55
|
+
"@done-coding/cli-utils": "^0.7.2"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "ad322da7f5d0897ee91a399aff9a14b111d62825",
|
|
58
58
|
"scripts": {}
|
|
59
59
|
}
|