@done-coding/cli-inject 0.5.7-alpha.0 → 0.5.8-alpha.1

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-80e9c302.js";
2
+ import { c as m } from "./index-3bb4131e.js";
3
3
  import "./types-a1ee6691.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { I as r, 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 D, createMainCommand as w } from "@done-coding/cli-utils";
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: r.FIXED,
13
+ type: c.FIXED,
14
14
  value: t
15
15
  } : s = t;
16
- const { type: l = r.READ } = s;
16
+ const { type: l = c.READ } = s;
17
17
  switch (l) {
18
- case r.REG: {
19
- const { sourceKey: i, pattern: d, replaceValue: p, flags: g } = s, E = new RegExp(d, g ?? void 0), c = I(e, i);
20
- return typeof c == "string" ? c.replace(E, p) : (n.warn(
21
- `${c}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
22
- ), c);
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 r.FIXED: {
25
- const { value: i } = s;
26
- return i;
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
- }, M = {
37
+ }, D = {
36
38
  sourceFilePath: "./package.json",
37
39
  keyConfigMap: {
38
40
  name: {
39
- type: r.READ
41
+ type: c.READ
40
42
  },
41
43
  version: {
42
- type: r.READ
44
+ type: c.READ
43
45
  },
44
46
  description: {
45
- type: r.READ
47
+ type: c.READ
46
48
  }
47
49
  },
48
50
  injectFilePath: "./src/injectInfo.json"
49
- }, N = M, R = {
51
+ }, R = {
50
52
  name: "@done-coding/cli-inject",
51
- version: "0.5.7-alpha.0",
53
+ version: "0.5.8-alpha.1",
52
54
  description: "信息(JSON)注入命令行工具",
53
55
  cliConfig: {
54
56
  namespaceDir: ".done-coding",
55
57
  moduleName: "inject"
56
58
  }
57
59
  }, {
58
- cliConfig: { namespaceDir: x, moduleName: H }
59
- } = R, L = `./${x}/${H}`, T = `${L}.json`, J = () => h({
60
+ cliConfig: { namespaceDir: M, moduleName: x }
61
+ } = R, H = `./${M}/${x}`, T = `${H}.json`, L = () => h({
60
62
  configPathDefault: T
61
- }), U = async (e) => _(N, e, {
63
+ }), J = async (e) => _(D, e, {
62
64
  onFileGenerated: () => {
63
65
  n.info("文件生成成功");
64
66
  }
65
- }), V = () => ({
67
+ }), U = () => ({
66
68
  ...h({
67
69
  configPathDefault: T
68
70
  })
69
- }), W = async ({
71
+ }), V = async ({
70
72
  rootDir: e = process.cwd(),
71
- config: o = N,
73
+ config: o = D,
72
74
  keyConfigMap: t = {}
73
75
  } = {}) => {
74
76
  const {
75
77
  sourceFilePath: s,
76
78
  keyConfigMap: l,
77
- injectFilePath: i
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 (!i.endsWith(".json"))
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), c = Object.entries(d).reduce(
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, i), y = JSON.stringify(c, null, 2);
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("注入文件已存在且内容相同,无需重复注入"), c;
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
- }, X = async (e) => {
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 W({ rootDir: t, config: o });
107
- }, v = async (e, o) => e === a.INIT ? U(o) : e === a.GENERATE ? X(o) : (n.error(`无效的命令: ${e}`), process.exit(1)), {
108
- version: K,
109
- description: q,
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, z = {
113
+ } = R, q = {
112
114
  command: a.INIT,
113
115
  describe: "初始化提取配置文件",
114
- options: J(),
116
+ options: L(),
115
117
  handler: A(v)(
116
118
  a.INIT
117
119
  )
118
- }, B = {
120
+ }, z = {
119
121
  command: a.GENERATE,
120
122
  describe: "提取信息",
121
- options: V(),
123
+ options: U(),
122
124
  handler: A(v)(
123
125
  a.GENERATE
124
126
  )
125
127
  }, O = {
126
- describe: q,
127
- version: K,
128
- subcommands: [z, B].map(
129
- D
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
- }, ne = async () => w({
137
+ }, ee = async () => w({
136
138
  ...O,
137
139
  ...S()
138
- }), oe = () => D({
140
+ }), ne = () => N({
139
141
  ...O,
140
142
  ...S(!0)
141
143
  });
142
144
  export {
143
- oe as a,
144
- ne as c,
145
- W as g,
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-80e9c302.js";
2
+ import { a as r, g as s, h as t, k as i } from "./index-3bb4131e.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.7-alpha.0",
3
+ "version": "0.5.8-alpha.1",
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.5.0-alpha.0"
65
+ "@done-coding/cli-utils": "^0.7.0-alpha.0"
66
66
  },
67
- "gitHead": "86cdd3eaf8cc8be3e48a812b93fd7c2110fcc879"
67
+ "gitHead": "ff1616738586a268b50f46dce762774fa5fa6d52"
68
68
  }
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "@done-coding/cli-inject",
3
- "version": "0.5.7-alpha.0",
3
+ "version": "0.5.8-alpha.1",
4
4
  "description": "信息(JSON)注入命令行工具",
5
5
  "cliConfig": {
6
6
  "namespaceDir": ".done-coding",
@@ -55,13 +55,16 @@ export interface InjectKeyConfigFixed extends InjectKeyConfigBase<InjectTypeEnum
55
55
  value: string;
56
56
  }
57
57
  /** 注入配置-读取类型 */
58
- export type InjectKeyConfigRead = InjectKeyConfigBase<InjectTypeEnum.READ>;
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文件相对路径 */