@done-coding/cli-inject 0.4.6-alpha.0 → 0.5.0-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 +4 -6
- package/es/handler-29b2ae8a.js +68 -0
- package/es/index-1197d11d.js +53 -0
- package/es/index.mjs +5 -7
- package/es/use.mjs +2 -2
- package/package.json +4 -7
- package/types/handler.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/injectInfo.json.d.ts +1 -1
- package/types/main.d.ts +9 -4
- package/es/handler-1283dc4a.js +0 -70
- package/es/index-b640e6b2.js +0 -50
package/es/cli.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as
|
|
3
|
-
import "./handler-
|
|
2
|
+
import { c as m } from "./index-1197d11d.js";
|
|
3
|
+
import "./handler-29b2ae8a.js";
|
|
4
4
|
import "node:path";
|
|
5
5
|
import "node:fs";
|
|
6
6
|
import "lodash.get";
|
|
7
7
|
import "lodash.set";
|
|
8
|
-
import "
|
|
9
|
-
|
|
10
|
-
import "yargs/helpers";
|
|
11
|
-
r();
|
|
8
|
+
import "@done-coding/cli-utils";
|
|
9
|
+
m();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import h from "node:path";
|
|
3
|
+
import a from "node:fs";
|
|
4
|
+
import S from "lodash.get";
|
|
5
|
+
import J from "lodash.set";
|
|
6
|
+
import { log as t } from "@done-coding/cli-utils";
|
|
7
|
+
const w = /(?<!\/):/, x = (e) => {
|
|
8
|
+
const [s, o = s, ...r] = e.split(w);
|
|
9
|
+
return {
|
|
10
|
+
key: s,
|
|
11
|
+
/** 目标key */
|
|
12
|
+
targetKey: o,
|
|
13
|
+
/** 参数列表 */
|
|
14
|
+
paramsList: r
|
|
15
|
+
};
|
|
16
|
+
}, v = ({
|
|
17
|
+
valueInit: e,
|
|
18
|
+
paramsList: s
|
|
19
|
+
}) => {
|
|
20
|
+
const [o, ...r] = s;
|
|
21
|
+
switch (o) {
|
|
22
|
+
case "REG": {
|
|
23
|
+
const [n, l, u] = r, f = new RegExp(n, u ?? void 0);
|
|
24
|
+
return typeof e == "string" ? e.replace(f, l) : (t.warn(
|
|
25
|
+
`${e}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
26
|
+
), e);
|
|
27
|
+
}
|
|
28
|
+
case "VALUE": {
|
|
29
|
+
const [n] = r;
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
return e;
|
|
34
|
+
}
|
|
35
|
+
}, $ = async (e) => {
|
|
36
|
+
const { sourceJsonFilePath: s, injectKeyPath: o, injectInfoFilePath: r } = e, n = process.cwd();
|
|
37
|
+
if (!s.endsWith(".json"))
|
|
38
|
+
return t.error("源文件必须是json"), process.exit(1);
|
|
39
|
+
if (!r.endsWith(".json"))
|
|
40
|
+
return t.error("注入文件必须是json"), process.exit(1);
|
|
41
|
+
const l = h.resolve(n, s), u = a.readFileSync(l, "utf-8"), f = JSON.parse(u), g = o.reduce(
|
|
42
|
+
(c, m) => {
|
|
43
|
+
const { key: y, targetKey: d, paramsList: j } = x(m);
|
|
44
|
+
if (!y)
|
|
45
|
+
return t.error(`注入key不能为空,请检查配置${m}是否正确`), c;
|
|
46
|
+
const F = S(f, y), P = v({
|
|
47
|
+
valueInit: F,
|
|
48
|
+
paramsList: j
|
|
49
|
+
});
|
|
50
|
+
return J(c, d, P), c;
|
|
51
|
+
},
|
|
52
|
+
{}
|
|
53
|
+
), i = h.resolve(n, r), p = JSON.stringify(g, null, 2);
|
|
54
|
+
if (a.existsSync(i)) {
|
|
55
|
+
const c = a.readFileSync(i, "utf-8");
|
|
56
|
+
if (p === c)
|
|
57
|
+
return t.skip("注入文件已存在且内容相同,无需重复注入"), g;
|
|
58
|
+
t.stage("文件内容变化,开始覆盖注入文件");
|
|
59
|
+
} else
|
|
60
|
+
t.stage("开始注入文件");
|
|
61
|
+
a.writeFileSync(i, p), console.log(
|
|
62
|
+
t.success(`文件注入成功: ${i}`),
|
|
63
|
+
t.info(p)
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
$ as h
|
|
68
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { h as s } from "./handler-29b2ae8a.js";
|
|
3
|
+
import { createMainCommand as c, createSubcommand as r } from "@done-coding/cli-utils";
|
|
4
|
+
const d = {
|
|
5
|
+
version: "0.5.0-alpha.0",
|
|
6
|
+
name: "@done-coding/cli-inject",
|
|
7
|
+
description: "信息注入命令行工具",
|
|
8
|
+
cliConfig: {
|
|
9
|
+
namespaceDir: ".done-coding",
|
|
10
|
+
moduleName: "inject"
|
|
11
|
+
}
|
|
12
|
+
}, {
|
|
13
|
+
version: m,
|
|
14
|
+
description: l,
|
|
15
|
+
cliConfig: { moduleName: n }
|
|
16
|
+
} = d, p = () => ({
|
|
17
|
+
sourceJsonFilePath: {
|
|
18
|
+
type: "string",
|
|
19
|
+
alias: "s",
|
|
20
|
+
describe: "信息源json文件相对路径",
|
|
21
|
+
default: "./package.json"
|
|
22
|
+
},
|
|
23
|
+
injectKeyPath: {
|
|
24
|
+
type: "array",
|
|
25
|
+
alias: "k",
|
|
26
|
+
describe: "需要注入的key路径",
|
|
27
|
+
default: ["name", "version", "description"]
|
|
28
|
+
},
|
|
29
|
+
injectInfoFilePath: {
|
|
30
|
+
type: "string",
|
|
31
|
+
alias: "i",
|
|
32
|
+
describe: "注入信息文件路径",
|
|
33
|
+
default: "./src/injectInfo.json"
|
|
34
|
+
}
|
|
35
|
+
}), o = {
|
|
36
|
+
describe: l,
|
|
37
|
+
version: m,
|
|
38
|
+
options: p(),
|
|
39
|
+
handler: s
|
|
40
|
+
}, t = (e = !1) => {
|
|
41
|
+
const i = e ? n : void 0, a = `$0${e ? ` ${n}` : ""} [options]`;
|
|
42
|
+
return { command: i, usage: a };
|
|
43
|
+
}, g = async () => c({
|
|
44
|
+
...o,
|
|
45
|
+
...t()
|
|
46
|
+
}), j = () => r({
|
|
47
|
+
...o,
|
|
48
|
+
...t(!0)
|
|
49
|
+
});
|
|
50
|
+
export {
|
|
51
|
+
j as a,
|
|
52
|
+
g as c
|
|
53
|
+
};
|
package/es/index.mjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { h as
|
|
3
|
-
import { a as
|
|
2
|
+
import { h as i } from "./handler-29b2ae8a.js";
|
|
3
|
+
import { a as s } from "./index-1197d11d.js";
|
|
4
4
|
import "node:path";
|
|
5
5
|
import "node:fs";
|
|
6
6
|
import "lodash.get";
|
|
7
7
|
import "lodash.set";
|
|
8
|
-
import "
|
|
9
|
-
import "yargs";
|
|
10
|
-
import "yargs/helpers";
|
|
8
|
+
import "@done-coding/cli-utils";
|
|
11
9
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
s as crateAsSubcommand,
|
|
11
|
+
i as handler
|
|
14
12
|
};
|
package/es/use.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { h as e } from "./handler-
|
|
2
|
+
import { h as e } from "./handler-29b2ae8a.js";
|
|
3
3
|
import "node:path";
|
|
4
4
|
import "node:fs";
|
|
5
5
|
import "lodash.get";
|
|
6
6
|
import "lodash.set";
|
|
7
|
-
import "
|
|
7
|
+
import "@done-coding/cli-utils";
|
|
8
8
|
const d = (n = `name:cliConfig.moduleName:REG:${/@done-coding\/cli-([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)/.source}:$1`, o = [], i = [
|
|
9
9
|
"version",
|
|
10
10
|
"name",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-inject",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
4
|
"description": "信息注入命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"@types/lodash.get": "^4.4.9",
|
|
55
55
|
"@types/lodash.set": "^4.3.9",
|
|
56
56
|
"@types/node": "^18.0.0",
|
|
57
|
-
"@types/prompts": "^2.4.6",
|
|
58
57
|
"@types/yargs": "^17.0.28",
|
|
59
58
|
"rimraf": "^6.0.1",
|
|
60
59
|
"typescript": "^5.2.2",
|
|
@@ -65,11 +64,9 @@
|
|
|
65
64
|
"node": ">=18.0.0"
|
|
66
65
|
},
|
|
67
66
|
"dependencies": {
|
|
68
|
-
"
|
|
67
|
+
"@done-coding/cli-utils": "^0.3.0-alpha.0",
|
|
69
68
|
"lodash.get": "^4.4.2",
|
|
70
|
-
"lodash.set": "^4.3.2"
|
|
71
|
-
"prompts": "^2.4.2",
|
|
72
|
-
"yargs": "^17.7.2"
|
|
69
|
+
"lodash.set": "^4.3.2"
|
|
73
70
|
},
|
|
74
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c5a54bdf08759425701a2024442a923883065189"
|
|
75
72
|
}
|
package/types/handler.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Options } from "./utils";
|
|
2
|
-
import type {
|
|
3
|
-
export declare const handler: (argv:
|
|
2
|
+
import type { CliHandlerArgv } from "@done-coding/cli-utils";
|
|
3
|
+
export declare const handler: (argv: CliHandlerArgv<Options>) => Promise<Record<string, any> | undefined>;
|
package/types/index.d.ts
CHANGED
package/types/main.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
/** 作为主命令创建 */
|
|
3
|
+
export declare const createCommand: () => Promise<void | {
|
|
4
|
+
[x: string]: unknown;
|
|
5
|
+
_: (string | number)[];
|
|
6
|
+
$0: string;
|
|
7
|
+
}>;
|
|
8
|
+
/** 作为子命令创建 */
|
|
9
|
+
export declare const crateAsSubcommand: () => import("yargs").CommandModule<{}, {}>;
|
package/es/handler-1283dc4a.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import m from "node:path";
|
|
3
|
-
import i from "node:fs";
|
|
4
|
-
import S from "lodash.get";
|
|
5
|
-
import J from "lodash.set";
|
|
6
|
-
import o from "chalk";
|
|
7
|
-
const w = /(?<!\/):/, x = (e) => {
|
|
8
|
-
const [t, r = t, ...s] = e.split(w);
|
|
9
|
-
return {
|
|
10
|
-
key: t,
|
|
11
|
-
/** 目标key */
|
|
12
|
-
targetKey: r,
|
|
13
|
-
/** 参数列表 */
|
|
14
|
-
paramsList: s
|
|
15
|
-
};
|
|
16
|
-
}, v = ({
|
|
17
|
-
valueInit: e,
|
|
18
|
-
paramsList: t
|
|
19
|
-
}) => {
|
|
20
|
-
const [r, ...s] = t;
|
|
21
|
-
switch (r) {
|
|
22
|
-
case "REG": {
|
|
23
|
-
const [n, a, u] = s, f = new RegExp(n, u ?? void 0);
|
|
24
|
-
return typeof e == "string" ? e.replace(f, a) : (console.log(
|
|
25
|
-
o.yellow(
|
|
26
|
-
`${e}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
|
|
27
|
-
)
|
|
28
|
-
), e);
|
|
29
|
-
}
|
|
30
|
-
case "VALUE": {
|
|
31
|
-
const [n] = s;
|
|
32
|
-
return n;
|
|
33
|
-
}
|
|
34
|
-
default:
|
|
35
|
-
return e;
|
|
36
|
-
}
|
|
37
|
-
}, L = async (e) => {
|
|
38
|
-
const { sourceJsonFilePath: t, injectKeyPath: r, injectInfoFilePath: s } = e, n = process.cwd();
|
|
39
|
-
if (!t.endsWith(".json"))
|
|
40
|
-
return console.log(o.red("源文件必须是json")), process.exit(1);
|
|
41
|
-
if (!s.endsWith(".json"))
|
|
42
|
-
return console.log(o.red("注入文件必须是json")), process.exit(1);
|
|
43
|
-
const a = m.resolve(n, t), u = i.readFileSync(a, "utf-8"), f = JSON.parse(u), p = r.reduce(
|
|
44
|
-
(c, y) => {
|
|
45
|
-
const { key: h, targetKey: d, paramsList: j } = x(y);
|
|
46
|
-
if (!h)
|
|
47
|
-
return console.log(o.red(`注入key不能为空,请检查配置${y}是否正确`)), c;
|
|
48
|
-
const F = S(f, h), P = v({
|
|
49
|
-
valueInit: F,
|
|
50
|
-
paramsList: j
|
|
51
|
-
});
|
|
52
|
-
return J(c, d, P), c;
|
|
53
|
-
},
|
|
54
|
-
{}
|
|
55
|
-
), l = m.resolve(n, s), g = JSON.stringify(p, null, 2);
|
|
56
|
-
if (i.existsSync(l)) {
|
|
57
|
-
const c = i.readFileSync(l, "utf-8");
|
|
58
|
-
if (g === c)
|
|
59
|
-
return console.log(o.gray("注入文件已存在且内容相同,无需重复注入")), p;
|
|
60
|
-
console.log(o.blue("文件内容变化,开始覆盖注入文件"));
|
|
61
|
-
} else
|
|
62
|
-
console.log(o.green("开始注入文件"));
|
|
63
|
-
return i.writeFileSync(l, g), console.log(
|
|
64
|
-
o.green(`文件注入成功: ${l}`),
|
|
65
|
-
o.blue(g)
|
|
66
|
-
), p;
|
|
67
|
-
};
|
|
68
|
-
export {
|
|
69
|
-
L as h
|
|
70
|
-
};
|
package/es/index-b640e6b2.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { h as i } from "./handler-1283dc4a.js";
|
|
3
|
-
import r from "yargs";
|
|
4
|
-
import { hideBin as l } from "yargs/helpers";
|
|
5
|
-
import s from "chalk";
|
|
6
|
-
const o = {
|
|
7
|
-
version: "0.4.6-alpha.0",
|
|
8
|
-
name: "@done-coding/cli-inject",
|
|
9
|
-
description: "信息注入命令行工具",
|
|
10
|
-
cliConfig: {
|
|
11
|
-
namespaceDir: ".done-coding",
|
|
12
|
-
moduleName: "inject"
|
|
13
|
-
}
|
|
14
|
-
}, d = () => ({
|
|
15
|
-
sourceJsonFilePath: {
|
|
16
|
-
type: "string",
|
|
17
|
-
alias: "s",
|
|
18
|
-
describe: "信息源json文件相对路径",
|
|
19
|
-
default: "./package.json"
|
|
20
|
-
},
|
|
21
|
-
injectKeyPath: {
|
|
22
|
-
type: "array",
|
|
23
|
-
alias: "k",
|
|
24
|
-
describe: "需要注入的key路径",
|
|
25
|
-
default: ["name", "version", "description"]
|
|
26
|
-
},
|
|
27
|
-
injectInfoFilePath: {
|
|
28
|
-
type: "string",
|
|
29
|
-
alias: "i",
|
|
30
|
-
describe: "注入信息文件路径",
|
|
31
|
-
default: "./src/injectInfo.json"
|
|
32
|
-
}
|
|
33
|
-
}), a = o.cliConfig.moduleName, m = (e, n) => {
|
|
34
|
-
console.log(e ? s.red(e) : s.red(n.message)), process.exit(1);
|
|
35
|
-
}, p = o.description, g = `Usage: $0 ${a} [options]`, f = "Usage: $0 [options]", t = (e, n) => {
|
|
36
|
-
const c = d();
|
|
37
|
-
return e.strict().usage(n).help("help").version(o.version).alias("v", "version").alias("h", "help").options(c).fail(m).argv;
|
|
38
|
-
}, h = (e) => t(e, g), b = {
|
|
39
|
-
command: a,
|
|
40
|
-
describe: p,
|
|
41
|
-
builder: h,
|
|
42
|
-
handler: i
|
|
43
|
-
}, C = async () => {
|
|
44
|
-
const e = r(l(process.argv)), n = await t(e, f);
|
|
45
|
-
return i(n);
|
|
46
|
-
};
|
|
47
|
-
export {
|
|
48
|
-
b as a,
|
|
49
|
-
C as c
|
|
50
|
-
};
|