done-coding-inject 0.5.10 → 0.5.12-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/helpers.mjs +3 -0
- package/es/index-3f8216c3.js +165 -0
- package/es/index.mjs +1 -1
- package/package.json +3 -3
- package/es/index-e2ac179b.js +0 -158
package/es/cli.mjs
CHANGED
package/es/helpers.mjs
CHANGED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { I as c, S as E } from "./index-a1ee6691.js";
|
|
3
|
+
import { log as o, _get as I, initHandlerCommon as k, getConfigFileCommonOptions as A, _set as w, readConfigFile as T, createSubcommand as N, getRootScriptName as _, createMainCommand as M } from "@done-coding/cli-utils";
|
|
4
|
+
import D from "node:path";
|
|
5
|
+
import u from "node:fs";
|
|
6
|
+
const x = ({
|
|
7
|
+
sourceJson: e,
|
|
8
|
+
targetKey: n,
|
|
9
|
+
keyConfig: t
|
|
10
|
+
}) => {
|
|
11
|
+
let s;
|
|
12
|
+
typeof t == "string" ? s = {
|
|
13
|
+
type: c.FIXED,
|
|
14
|
+
value: t
|
|
15
|
+
} : s = t;
|
|
16
|
+
const { type: a = c.READ } = s;
|
|
17
|
+
switch (a) {
|
|
18
|
+
case c.REG: {
|
|
19
|
+
const { sourceKey: r, pattern: f, replaceValue: p, flags: g } = s, y = new RegExp(f, g ?? void 0), i = I(e, r);
|
|
20
|
+
return typeof i == "string" ? i.replace(y, p) : (o.warn(
|
|
21
|
+
`${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
22
|
+
), i);
|
|
23
|
+
}
|
|
24
|
+
case c.FIXED: {
|
|
25
|
+
const { value: r } = s;
|
|
26
|
+
return r;
|
|
27
|
+
}
|
|
28
|
+
case c.READ: {
|
|
29
|
+
const { sourceKey: r = n } = s;
|
|
30
|
+
return I(e, r);
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
o.warn(`未知的配置类型${a}`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, d = {
|
|
38
|
+
name: "@done-coding/cli-inject",
|
|
39
|
+
version: "0.5.12-alpha.0",
|
|
40
|
+
description: "信息(JSON)注入命令行工具",
|
|
41
|
+
bin: {
|
|
42
|
+
"dc-inject": "es/cli.mjs"
|
|
43
|
+
},
|
|
44
|
+
cliConfig: {
|
|
45
|
+
namespaceDir: ".done-coding",
|
|
46
|
+
moduleName: "inject"
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
cliConfig: { namespaceDir: G, moduleName: J }
|
|
50
|
+
} = d, L = `./${G}/${J}`, R = `${L}.json`, U = {
|
|
51
|
+
sourceFilePath: "./package.json",
|
|
52
|
+
keyConfigMap: {
|
|
53
|
+
name: {
|
|
54
|
+
type: c.READ
|
|
55
|
+
},
|
|
56
|
+
version: {
|
|
57
|
+
type: c.READ
|
|
58
|
+
},
|
|
59
|
+
description: {
|
|
60
|
+
type: c.READ
|
|
61
|
+
},
|
|
62
|
+
bin: {
|
|
63
|
+
type: c.READ
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
injectFilePath: "./src/injectInfo.json"
|
|
67
|
+
}, j = U, V = () => A({
|
|
68
|
+
configPathDefault: R
|
|
69
|
+
}), S = async (e) => k(j, e, {
|
|
70
|
+
onFileGenerated: () => {
|
|
71
|
+
o.info("文件生成成功");
|
|
72
|
+
}
|
|
73
|
+
}), H = {
|
|
74
|
+
command: E.INIT,
|
|
75
|
+
describe: "初始化配置文件",
|
|
76
|
+
options: V(),
|
|
77
|
+
handler: S
|
|
78
|
+
}, K = () => ({
|
|
79
|
+
...A({
|
|
80
|
+
configPathDefault: R
|
|
81
|
+
})
|
|
82
|
+
}), W = async ({
|
|
83
|
+
rootDir: e = process.cwd(),
|
|
84
|
+
config: n = j,
|
|
85
|
+
keyConfigMap: t = {}
|
|
86
|
+
} = {}) => {
|
|
87
|
+
const {
|
|
88
|
+
sourceFilePath: s,
|
|
89
|
+
keyConfigMap: a,
|
|
90
|
+
injectFilePath: r
|
|
91
|
+
} = n, f = {
|
|
92
|
+
...a,
|
|
93
|
+
...t
|
|
94
|
+
};
|
|
95
|
+
if (!s.endsWith(".json"))
|
|
96
|
+
return o.error("源文件必须是json"), process.exit(1);
|
|
97
|
+
if (!r.endsWith(".json"))
|
|
98
|
+
return o.error("注入文件必须是json"), process.exit(1);
|
|
99
|
+
const p = D.resolve(e, s), g = u.readFileSync(p, "utf-8"), y = JSON.parse(g), i = Object.entries(f).reduce(
|
|
100
|
+
(m, [F, v]) => {
|
|
101
|
+
const P = x({ sourceJson: y, targetKey: F, keyConfig: v });
|
|
102
|
+
return w(m, F, P), m;
|
|
103
|
+
},
|
|
104
|
+
{}
|
|
105
|
+
), l = D.resolve(e, r), C = JSON.stringify(i, null, 2);
|
|
106
|
+
if (u.existsSync(l)) {
|
|
107
|
+
const m = u.readFileSync(l, "utf-8");
|
|
108
|
+
if (C === m)
|
|
109
|
+
return o.skip("注入文件已存在且内容相同,无需重复注入"), i;
|
|
110
|
+
o.stage("文件内容变化,开始覆盖注入文件");
|
|
111
|
+
} else
|
|
112
|
+
o.stage("开始注入文件");
|
|
113
|
+
u.writeFileSync(l, C), o.success(`文件注入成功: ${l}`), o.info(C);
|
|
114
|
+
}, h = async (e) => {
|
|
115
|
+
const n = await T(e, () => (o.info("配置文件为空,使用默认配置"), j));
|
|
116
|
+
if (!n)
|
|
117
|
+
return o.error("配置文件为空"), process.exit(1);
|
|
118
|
+
const { rootDir: t } = e;
|
|
119
|
+
await W({ rootDir: t, config: n });
|
|
120
|
+
}, X = {
|
|
121
|
+
command: "$0",
|
|
122
|
+
describe: "生成文件",
|
|
123
|
+
options: K(),
|
|
124
|
+
handler: h
|
|
125
|
+
}, ee = async (e, n) => {
|
|
126
|
+
switch (e) {
|
|
127
|
+
case E.INIT:
|
|
128
|
+
return S(n);
|
|
129
|
+
case E.GENERATE:
|
|
130
|
+
return h(n);
|
|
131
|
+
default:
|
|
132
|
+
return h(n);
|
|
133
|
+
}
|
|
134
|
+
}, { version: q, description: z } = d, b = {
|
|
135
|
+
describe: z,
|
|
136
|
+
version: q,
|
|
137
|
+
subcommands: [H, X].map(
|
|
138
|
+
N
|
|
139
|
+
),
|
|
140
|
+
demandCommandCount: 1,
|
|
141
|
+
rootScriptName: _({ packageJson: d })
|
|
142
|
+
}, {
|
|
143
|
+
cliConfig: { moduleName: $ }
|
|
144
|
+
} = d, O = (e = !1) => {
|
|
145
|
+
const n = e ? $ : void 0, t = `$0${e ? ` ${$}` : ""} <command> [options]`;
|
|
146
|
+
return { command: n, usage: t };
|
|
147
|
+
}, ne = async () => M({
|
|
148
|
+
...b,
|
|
149
|
+
...O()
|
|
150
|
+
}), oe = () => N({
|
|
151
|
+
...b,
|
|
152
|
+
...O(!0)
|
|
153
|
+
});
|
|
154
|
+
export {
|
|
155
|
+
oe as a,
|
|
156
|
+
H as b,
|
|
157
|
+
ne as c,
|
|
158
|
+
h as d,
|
|
159
|
+
X as e,
|
|
160
|
+
ee as f,
|
|
161
|
+
W as g,
|
|
162
|
+
S as h,
|
|
163
|
+
b as i,
|
|
164
|
+
x as k
|
|
165
|
+
};
|
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-3f8216c3.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.12-alpha.0",
|
|
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.3-alpha.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae",
|
|
58
58
|
"scripts": {}
|
|
59
59
|
}
|
package/es/index-e2ac179b.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { I as r, S as d } from "./index-a1ee6691.js";
|
|
3
|
-
import { log as o, _get as I, initHandlerCommon as b, getConfigFileCommonOptions as A, _set as w, readConfigFile as _, createSubcommand as D, createMainCommand as k } from "@done-coding/cli-utils";
|
|
4
|
-
import j from "node:path";
|
|
5
|
-
import u from "node:fs";
|
|
6
|
-
const M = ({
|
|
7
|
-
sourceJson: e,
|
|
8
|
-
targetKey: n,
|
|
9
|
-
keyConfig: t
|
|
10
|
-
}) => {
|
|
11
|
-
let s;
|
|
12
|
-
typeof t == "string" ? s = {
|
|
13
|
-
type: r.FIXED,
|
|
14
|
-
value: t
|
|
15
|
-
} : s = t;
|
|
16
|
-
const { type: a = r.READ } = s;
|
|
17
|
-
switch (a) {
|
|
18
|
-
case r.REG: {
|
|
19
|
-
const { sourceKey: c, pattern: f, replaceValue: p, flags: g } = s, y = new RegExp(f, g ?? void 0), i = I(e, c);
|
|
20
|
-
return typeof i == "string" ? i.replace(y, p) : (o.warn(
|
|
21
|
-
`${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
22
|
-
), i);
|
|
23
|
-
}
|
|
24
|
-
case r.FIXED: {
|
|
25
|
-
const { value: c } = s;
|
|
26
|
-
return c;
|
|
27
|
-
}
|
|
28
|
-
case r.READ: {
|
|
29
|
-
const { sourceKey: c = n } = s;
|
|
30
|
-
return I(e, c);
|
|
31
|
-
}
|
|
32
|
-
default: {
|
|
33
|
-
o.warn(`未知的配置类型${a}`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}, h = {
|
|
38
|
-
name: "@done-coding/cli-inject",
|
|
39
|
-
version: "0.5.10",
|
|
40
|
-
description: "信息(JSON)注入命令行工具",
|
|
41
|
-
cliConfig: {
|
|
42
|
-
namespaceDir: ".done-coding",
|
|
43
|
-
moduleName: "inject"
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
cliConfig: { namespaceDir: x, moduleName: G }
|
|
47
|
-
} = h, L = `./${x}/${G}`, N = `${L}.json`, R = {
|
|
48
|
-
sourceFilePath: "./package.json",
|
|
49
|
-
keyConfigMap: {
|
|
50
|
-
name: {
|
|
51
|
-
type: r.READ
|
|
52
|
-
},
|
|
53
|
-
version: {
|
|
54
|
-
type: r.READ
|
|
55
|
-
},
|
|
56
|
-
description: {
|
|
57
|
-
type: r.READ
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
injectFilePath: "./src/injectInfo.json"
|
|
61
|
-
}, J = () => A({
|
|
62
|
-
configPathDefault: N
|
|
63
|
-
}), O = async (e) => b(R, e, {
|
|
64
|
-
onFileGenerated: () => {
|
|
65
|
-
o.info("文件生成成功");
|
|
66
|
-
}
|
|
67
|
-
}), U = {
|
|
68
|
-
command: d.INIT,
|
|
69
|
-
describe: "初始化配置文件",
|
|
70
|
-
options: J(),
|
|
71
|
-
handler: O
|
|
72
|
-
}, V = () => ({
|
|
73
|
-
...A({
|
|
74
|
-
configPathDefault: N
|
|
75
|
-
})
|
|
76
|
-
}), H = async ({
|
|
77
|
-
rootDir: e = process.cwd(),
|
|
78
|
-
config: n = R,
|
|
79
|
-
keyConfigMap: t = {}
|
|
80
|
-
} = {}) => {
|
|
81
|
-
const {
|
|
82
|
-
sourceFilePath: s,
|
|
83
|
-
keyConfigMap: a,
|
|
84
|
-
injectFilePath: c
|
|
85
|
-
} = n, f = {
|
|
86
|
-
...a,
|
|
87
|
-
...t
|
|
88
|
-
};
|
|
89
|
-
if (!s.endsWith(".json"))
|
|
90
|
-
return o.error("源文件必须是json"), process.exit(1);
|
|
91
|
-
if (!c.endsWith(".json"))
|
|
92
|
-
return o.error("注入文件必须是json"), process.exit(1);
|
|
93
|
-
const p = j.resolve(e, s), g = u.readFileSync(p, "utf-8"), y = JSON.parse(g), i = Object.entries(f).reduce(
|
|
94
|
-
(m, [F, P]) => {
|
|
95
|
-
const T = M({ sourceJson: y, targetKey: F, keyConfig: P });
|
|
96
|
-
return w(m, F, T), m;
|
|
97
|
-
},
|
|
98
|
-
{}
|
|
99
|
-
), l = j.resolve(e, c), E = JSON.stringify(i, null, 2);
|
|
100
|
-
if (u.existsSync(l)) {
|
|
101
|
-
const m = u.readFileSync(l, "utf-8");
|
|
102
|
-
if (E === m)
|
|
103
|
-
return o.skip("注入文件已存在且内容相同,无需重复注入"), i;
|
|
104
|
-
o.stage("文件内容变化,开始覆盖注入文件");
|
|
105
|
-
} else
|
|
106
|
-
o.stage("开始注入文件");
|
|
107
|
-
u.writeFileSync(l, E), o.success(`文件注入成功: ${l}`), o.info(E);
|
|
108
|
-
}, C = async (e) => {
|
|
109
|
-
const n = await _(e);
|
|
110
|
-
if (!n)
|
|
111
|
-
return o.error("配置文件为空"), process.exit(1);
|
|
112
|
-
const { rootDir: t } = e;
|
|
113
|
-
await H({ rootDir: t, config: n });
|
|
114
|
-
}, K = {
|
|
115
|
-
command: d.GENERATE,
|
|
116
|
-
describe: "生成文件",
|
|
117
|
-
options: V(),
|
|
118
|
-
handler: C
|
|
119
|
-
}, Y = async (e, n) => {
|
|
120
|
-
switch (e) {
|
|
121
|
-
case d.INIT:
|
|
122
|
-
return O(n);
|
|
123
|
-
case d.GENERATE:
|
|
124
|
-
return C(n);
|
|
125
|
-
default:
|
|
126
|
-
return C(n);
|
|
127
|
-
}
|
|
128
|
-
}, { version: W, description: X } = h, S = {
|
|
129
|
-
describe: X,
|
|
130
|
-
version: W,
|
|
131
|
-
subcommands: [U, K].map(
|
|
132
|
-
D
|
|
133
|
-
),
|
|
134
|
-
demandCommandCount: 1
|
|
135
|
-
}, {
|
|
136
|
-
cliConfig: { moduleName: $ }
|
|
137
|
-
} = h, v = (e = !1) => {
|
|
138
|
-
const n = e ? $ : void 0, t = `$0${e ? ` ${$}` : ""} <command> [options]`;
|
|
139
|
-
return { command: n, usage: t };
|
|
140
|
-
}, Z = async () => k({
|
|
141
|
-
...S,
|
|
142
|
-
...v()
|
|
143
|
-
}), ee = () => D({
|
|
144
|
-
...S,
|
|
145
|
-
...v(!0)
|
|
146
|
-
});
|
|
147
|
-
export {
|
|
148
|
-
ee as a,
|
|
149
|
-
U as b,
|
|
150
|
-
Z as c,
|
|
151
|
-
C as d,
|
|
152
|
-
K as e,
|
|
153
|
-
Y as f,
|
|
154
|
-
H as g,
|
|
155
|
-
O as h,
|
|
156
|
-
S as i,
|
|
157
|
-
M as k
|
|
158
|
-
};
|