@done-coding/cli-inject 0.4.5 → 0.4.7-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 CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-eee4d71e.js";
3
- import "./handler-1283dc4a.js";
2
+ import { c as r } from "./index-292f0fc5.js";
3
+ import "./handler-995d55e6.js";
4
4
  import "node:path";
5
5
  import "node:fs";
6
6
  import "lodash.get";
7
7
  import "lodash.set";
8
- import "chalk";
8
+ import "@done-coding/cli-utils";
9
9
  import "yargs";
10
10
  import "yargs/helpers";
11
11
  r();
@@ -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 [r, o = r, ...s] = e.split(w);
9
+ return {
10
+ key: r,
11
+ /** 目标key */
12
+ targetKey: o,
13
+ /** 参数列表 */
14
+ paramsList: s
15
+ };
16
+ }, v = ({
17
+ valueInit: e,
18
+ paramsList: r
19
+ }) => {
20
+ const [o, ...s] = r;
21
+ switch (o) {
22
+ case "REG": {
23
+ const [n, l, u] = s, 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] = s;
30
+ return n;
31
+ }
32
+ default:
33
+ return e;
34
+ }
35
+ }, $ = async (e) => {
36
+ const { sourceJsonFilePath: r, injectKeyPath: o, injectInfoFilePath: s } = e, n = process.cwd();
37
+ if (!r.endsWith(".json"))
38
+ return t.error("源文件必须是json"), process.exit(1);
39
+ if (!s.endsWith(".json"))
40
+ return t.error("注入文件必须是json"), process.exit(1);
41
+ const l = h.resolve(n, r), u = a.readFileSync(l, "utf-8"), f = JSON.parse(u), p = 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, s), g = JSON.stringify(p, null, 2);
54
+ if (a.existsSync(i)) {
55
+ const c = a.readFileSync(i, "utf-8");
56
+ if (g === c)
57
+ return t.skip("注入文件已存在且内容相同,无需重复注入"), p;
58
+ t.stage("文件内容变化,开始覆盖注入文件");
59
+ } else
60
+ t.stage("开始注入文件");
61
+ return a.writeFileSync(i, g), console.log(
62
+ t.success(`文件注入成功: ${i}`),
63
+ t.info(g)
64
+ ), p;
65
+ };
66
+ export {
67
+ $ as h
68
+ };
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { h as i } from "./handler-1283dc4a.js";
3
- import r from "yargs";
2
+ import { h as i } from "./handler-995d55e6.js";
3
+ import c from "yargs";
4
4
  import { hideBin as l } from "yargs/helpers";
5
- import s from "chalk";
5
+ import { log as s } from "@done-coding/cli-utils";
6
6
  const o = {
7
- version: "0.4.5",
7
+ version: "0.4.7-alpha.0",
8
8
  name: "@done-coding/cli-inject",
9
9
  description: "信息注入命令行工具",
10
10
  cliConfig: {
11
11
  namespaceDir: ".done-coding",
12
12
  moduleName: "inject"
13
13
  }
14
- }, d = () => ({
14
+ }, m = () => ({
15
15
  sourceJsonFilePath: {
16
16
  type: "string",
17
17
  alias: "s",
@@ -30,18 +30,18 @@ const o = {
30
30
  describe: "注入信息文件路径",
31
31
  default: "./src/injectInfo.json"
32
32
  }
33
- }), a = o.cliConfig.moduleName, m = (e, n) => {
34
- console.log(e ? s.red(e) : s.red(n.message)), process.exit(1);
33
+ }), a = o.cliConfig.moduleName, d = (e, n) => {
34
+ e ? s.error(e) : s.error(n.message), process.exit(1);
35
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;
36
+ const r = m();
37
+ return e.strict().usage(n).help("help").version(o.version).alias("v", "version").alias("h", "help").options(r).fail(d).argv;
38
38
  }, u = (e) => t(e, g), b = {
39
39
  command: a,
40
40
  describe: p,
41
41
  builder: u,
42
42
  handler: i
43
43
  }, C = async () => {
44
- const e = r(l(process.argv)), n = await t(e, f);
44
+ const e = c(l(process.argv)), n = await t(e, f);
45
45
  return i(n);
46
46
  };
47
47
  export {
package/es/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { h as d } from "./handler-1283dc4a.js";
3
- import { a as f } from "./index-eee4d71e.js";
2
+ import { h as d } from "./handler-995d55e6.js";
3
+ import { a as f } from "./index-292f0fc5.js";
4
4
  import "node:path";
5
5
  import "node:fs";
6
6
  import "lodash.get";
7
7
  import "lodash.set";
8
- import "chalk";
8
+ import "@done-coding/cli-utils";
9
9
  import "yargs";
10
10
  import "yargs/helpers";
11
11
  export {
package/es/use.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { h as e } from "./handler-1283dc4a.js";
2
+ import { h as e } from "./handler-995d55e6.js";
3
3
  import "node:path";
4
4
  import "node:fs";
5
5
  import "lodash.get";
6
6
  import "lodash.set";
7
- import "chalk";
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.4.5",
3
+ "version": "0.4.7-alpha.0",
4
4
  "description": "信息注入命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -28,8 +28,7 @@
28
28
  "files": [
29
29
  "es",
30
30
  "lib",
31
- "types",
32
- "gif"
31
+ "types"
33
32
  ],
34
33
  "scripts": {
35
34
  "clean": "rimraf es lib types",
@@ -55,7 +54,6 @@
55
54
  "@types/lodash.get": "^4.4.9",
56
55
  "@types/lodash.set": "^4.3.9",
57
56
  "@types/node": "^18.0.0",
58
- "@types/prompts": "^2.4.6",
59
57
  "@types/yargs": "^17.0.28",
60
58
  "rimraf": "^6.0.1",
61
59
  "typescript": "^5.2.2",
@@ -66,11 +64,10 @@
66
64
  "node": ">=18.0.0"
67
65
  },
68
66
  "dependencies": {
69
- "chalk": "^5.3.0",
67
+ "@done-coding/cli-utils": "^0.2.2-alpha.0",
70
68
  "lodash.get": "^4.4.2",
71
69
  "lodash.set": "^4.3.2",
72
- "prompts": "^2.4.2",
73
70
  "yargs": "^17.7.2"
74
71
  },
75
- "gitHead": "465ac238437ab8bd3803c5e6fe8ac5a30bc445f3"
72
+ "gitHead": "2e59e86ee192e023138e7475f4abbb5e7c42b29e"
76
73
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.4.5",
2
+ "version": "0.4.7-alpha.0",
3
3
  "name": "@done-coding/cli-inject",
4
4
  "description": "信息注入命令行工具",
5
5
  "cliConfig": {
@@ -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
- };