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