done-coding-inject 0.5.10-alpha.0 → 0.5.10

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