done-coding-inject 0.5.8 → 0.5.9-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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-aa5aa929.js";
3
- import "./types-a1ee6691.js";
2
+ import { c as m } from "./index-334ebd43.js";
3
+ import "./index-a1ee6691.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
6
6
  import "node:fs";
package/es/helpers.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { I as e } from "./types-a1ee6691.js";
2
+ import { I as e } from "./index-a1ee6691.js";
3
3
  const o = {
4
4
  sourceFilePath: "./package.json",
5
5
  keyConfigMap: {
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
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 A, _set as w, readConfigFile as _, createSubcommand as D, createMainCommand as k } from "@done-coding/cli-utils";
4
+ import j from "node:path";
5
+ import u from "node:fs";
6
+ const M = ({
7
+ sourceJson: e,
8
+ targetKey: n,
9
+ keyConfig: t
10
+ }) => {
11
+ let s;
12
+ typeof t == "string" ? s = {
13
+ type: r.FIXED,
14
+ value: t
15
+ } : s = t;
16
+ const { type: i = r.READ } = s;
17
+ switch (i) {
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);
23
+ }
24
+ case r.FIXED: {
25
+ const { value: c } = s;
26
+ return c;
27
+ }
28
+ case r.READ: {
29
+ const { sourceKey: c = n } = s;
30
+ return I(e, c);
31
+ }
32
+ default: {
33
+ o.warn(`未知的配置类型${i}`);
34
+ return;
35
+ }
36
+ }
37
+ }, h = {
38
+ name: "@done-coding/cli-inject",
39
+ version: "0.5.9-alpha.0",
40
+ description: "信息(JSON)注入命令行工具",
41
+ cliConfig: {
42
+ namespaceDir: ".done-coding",
43
+ moduleName: "inject"
44
+ }
45
+ }, {
46
+ cliConfig: { namespaceDir: x, moduleName: G }
47
+ } = h, L = `./${x}/${G}`, N = `${L}.json`, R = {
48
+ sourceFilePath: "./package.json",
49
+ keyConfigMap: {
50
+ name: {
51
+ type: r.READ
52
+ },
53
+ version: {
54
+ type: r.READ
55
+ },
56
+ description: {
57
+ type: r.READ
58
+ }
59
+ },
60
+ injectFilePath: "./src/injectInfo.json"
61
+ }, J = () => A({
62
+ configPathDefault: N
63
+ }), O = async (e) => b(R, e, {
64
+ onFileGenerated: () => {
65
+ o.info("文件生成成功");
66
+ }
67
+ }), U = {
68
+ command: d.INIT,
69
+ describe: "初始化配置文件",
70
+ options: J(),
71
+ handler: O
72
+ }, V = () => ({
73
+ ...A({
74
+ configPathDefault: N
75
+ })
76
+ }), H = async ({
77
+ rootDir: e = process.cwd(),
78
+ config: n = R,
79
+ keyConfigMap: t = {}
80
+ } = {}) => {
81
+ const {
82
+ sourceFilePath: s,
83
+ keyConfigMap: i,
84
+ injectFilePath: c
85
+ } = n, f = {
86
+ ...i,
87
+ ...t
88
+ };
89
+ if (!s.endsWith(".json"))
90
+ return o.error("源文件必须是json"), process.exit(1);
91
+ if (!c.endsWith(".json"))
92
+ return o.error("注入文件必须是json"), process.exit(1);
93
+ const p = j.resolve(e, s), g = u.readFileSync(p, "utf-8"), y = JSON.parse(g), a = Object.entries(f).reduce(
94
+ (m, [F, P]) => {
95
+ const T = M({ sourceJson: y, targetKey: F, keyConfig: P });
96
+ return w(m, F, T), m;
97
+ },
98
+ {}
99
+ ), l = j.resolve(e, c), E = JSON.stringify(a, null, 2);
100
+ if (u.existsSync(l)) {
101
+ const m = u.readFileSync(l, "utf-8");
102
+ if (E === m)
103
+ return o.skip("注入文件已存在且内容相同,无需重复注入"), a;
104
+ o.stage("文件内容变化,开始覆盖注入文件");
105
+ } else
106
+ o.stage("开始注入文件");
107
+ u.writeFileSync(l, E), o.success(`文件注入成功: ${l}`), o.info(E);
108
+ }, C = async (e) => {
109
+ const n = await _(e);
110
+ if (!n)
111
+ return o.error("配置文件为空"), process.exit(1);
112
+ const { rootDir: t } = e;
113
+ await H({ rootDir: t, config: n });
114
+ }, K = {
115
+ command: d.GENERATE,
116
+ describe: "生成文件",
117
+ options: V(),
118
+ handler: C
119
+ }, Y = async (e, n) => {
120
+ switch (e) {
121
+ case d.INIT:
122
+ return O(n);
123
+ case d.GENERATE:
124
+ return C(n);
125
+ default:
126
+ return C(n);
127
+ }
128
+ }, { version: W, description: X } = h, S = {
129
+ describe: X,
130
+ version: W,
131
+ subcommands: [U, K].map(
132
+ D
133
+ ),
134
+ demandCommandCount: 1
135
+ }, {
136
+ cliConfig: { moduleName: $ }
137
+ } = h, v = (e = !1) => {
138
+ const n = e ? $ : void 0, t = `$0${e ? ` ${$}` : ""} <command> [options]`;
139
+ return { command: n, usage: t };
140
+ }, Z = async () => k({
141
+ ...S,
142
+ ...v()
143
+ }), ee = () => D({
144
+ ...S,
145
+ ...v(!0)
146
+ });
147
+ export {
148
+ ee as a,
149
+ U as b,
150
+ Z as c,
151
+ C as d,
152
+ K as e,
153
+ Y as f,
154
+ H as g,
155
+ O as h,
156
+ S as i,
157
+ M as k
158
+ };
package/es/index.mjs CHANGED
@@ -1,14 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import { a as r, g as s, h as t, k as i } from "./index-aa5aa929.js";
3
- import { I as u, S as c } from "./types-a1ee6691.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-334ebd43.js";
3
+ import { I as g, S as u } from "./index-a1ee6691.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
6
6
  import "node:fs";
7
7
  export {
8
- u as InjectTypeEnum,
9
- c as SubcommandEnum,
10
- r as crateAsSubcommand,
11
- s as generateFile,
12
- t as handler,
13
- i as keyConfigResolve
8
+ g as InjectTypeEnum,
9
+ u as SubcommandEnum,
10
+ r as commandCliInfo,
11
+ i as crateAsSubcommand,
12
+ s as generateCommandCliInfo,
13
+ t as generateFile,
14
+ d as generateHandler,
15
+ l as handler,
16
+ f as initCommandCliInfo,
17
+ p as initHandler,
18
+ C as keyConfigResolve
14
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "done-coding-inject",
3
- "version": "0.5.8",
3
+ "version": "0.5.9-alpha.0",
4
4
  "description": "信息(JSON)注入命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -54,6 +54,6 @@
54
54
  "dependencies": {
55
55
  "@done-coding/cli-utils": "^0.7.0"
56
56
  },
57
- "gitHead": "b4fb4f2380a14f72597a1dbfd1bbce22287ef02f",
57
+ "gitHead": "62a4c9df2bf8690e52753e0734ebb09010bb2e88",
58
58
  "scripts": {}
59
59
  }
@@ -1,6 +1,6 @@
1
1
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
2
2
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
3
3
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
4
- import type { InjectConfig } from "../utils";
4
+ import type { InjectConfig } from "../types";
5
5
  declare const config: InjectConfig;
6
6
  export default config;
@@ -1,15 +1,17 @@
1
1
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
2
2
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
3
3
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
4
+ import type { SubCliInfo } from "@done-coding/cli-utils";
4
5
  import { type CliHandlerArgv, type CliInfo } from "@done-coding/cli-utils";
5
- import type { InjectConfig, GenerateOptions } from "./types";
6
+ import type { GenerateOptions, InjectConfig } from "../types";
6
7
  /** 获取生成命令选项 */
7
- export declare const getGenerateOptions: () => CliInfo["options"];
8
+ export declare const getOptions: () => CliInfo["options"];
8
9
  /** 生成注入信息文件 */
9
10
  export declare const generateFile: ({ rootDir, config, keyConfigMap: extractKeyConfigMap, }?: {
10
11
  rootDir?: string | undefined;
11
12
  config?: InjectConfig | undefined;
12
- keyConfigMap?: Record<string, import("./types").InjectKeyConfig> | undefined;
13
+ keyConfigMap?: Record<string, import("../types").InjectKeyConfig> | undefined;
13
14
  }) => Promise<{} | undefined>;
14
15
  /** 提取文件命令处理器 */
15
- export declare const generateHandler: (argv: CliHandlerArgv<GenerateOptions>) => Promise<undefined>;
16
+ export declare const handler: (argv: CliHandlerArgv<GenerateOptions>) => Promise<undefined>;
17
+ export declare const commandCliInfo: SubCliInfo;
@@ -0,0 +1,7 @@
1
+ import { handler as initHandler, commandCliInfo as initCommandCliInfo } from "./init";
2
+ import { handler as generateHandler, commandCliInfo as generateCommandCliInfo, generateFile } from "./generate";
3
+ import { SubcommandEnum } from '../types';
4
+ import { type CliHandlerArgv, type CliInfo } from "@done-coding/cli-utils";
5
+ export { initHandler, initCommandCliInfo, generateHandler, generateCommandCliInfo, generateFile, };
6
+ export declare const handler: (command: SubcommandEnum, argv: CliHandlerArgv<any>) => Promise<void>;
7
+ export declare const commandCliInfo: Omit<CliInfo, "usage">;
@@ -0,0 +1,8 @@
1
+ /// <reference types="yargs" />
2
+ import type { CliHandlerArgv, SubCliInfo } from "@done-coding/cli-utils";
3
+ import { type InitOptions } from '../types';
4
+ /** 获取初始化选项 */
5
+ export declare const getOptions: () => Record<keyof import("@done-coding/cli-utils").ConfigFileCommonOptions, import("yargs").Options>;
6
+ /** 初始化命令处理器 */
7
+ export declare const handler: (argv: CliHandlerArgv<InitOptions>) => Promise<void>;
8
+ export declare const commandCliInfo: SubCliInfo;
@@ -1,6 +1,6 @@
1
1
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
2
2
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
3
3
  /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
4
- import type { InjectConfig } from "../utils";
4
+ import type { InjectConfig } from "../types";
5
5
  /** done-coding-cli 注入配置 */
6
6
  export declare const doneCodingCliConfig: InjectConfig;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { handler } from "./handler";
1
+ export * from './handlers';
2
2
  export { crateAsSubcommand } from "./main";
3
- export { generateFile, keyConfigResolve } from './utils';
4
- export * from './utils/types';
3
+ export * from './types';
4
+ export { keyConfigResolve } from './utils';
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "@done-coding/cli-inject",
3
- "version": "0.5.8",
3
+ "version": "0.5.9-alpha.0",
4
4
  "description": "信息(JSON)注入命令行工具",
5
5
  "cliConfig": {
6
6
  "namespaceDir": ".done-coding",
@@ -1,5 +1,2 @@
1
- export * from "./types";
2
1
  export * from "./resolve";
3
- export * from "./init";
4
- export * from "./generate";
5
2
  export * from "./path";
@@ -1,3 +1,6 @@
1
+ /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
2
+ /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
3
+ /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
1
4
  /** 模块配置相对路径 */
2
5
  export declare const MODULE_CONFIG_RELATIVE_PATH: string;
3
6
  /** 模块默认配置文件相对路径 */
@@ -1,4 +1,7 @@
1
- import type { InjectKeyConfig } from "./types";
1
+ /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
2
+ /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
3
+ /** 考虑本包会使用当前文件源码 避免不识别@ 此处用相对路径 */
4
+ import type { InjectKeyConfig } from "../types";
2
5
  /** key配置解析-获取最终值 */
3
6
  export declare const keyConfigResolve: ({ sourceJson, targetKey, keyConfig: keyConfigInit, }: {
4
7
  sourceJson: Record<string, any>;
@@ -1,150 +0,0 @@
1
- #!/usr/bin/env node
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
- import F from "node:path";
5
- import m from "node:fs";
6
- const G = ({
7
- sourceJson: e,
8
- targetKey: o,
9
- keyConfig: t
10
- }) => {
11
- let s;
12
- typeof t == "string" ? s = {
13
- type: c.FIXED,
14
- value: t
15
- } : s = t;
16
- const { type: l = c.READ } = s;
17
- switch (l) {
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
- }
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);
31
- }
32
- default: {
33
- n.warn(`未知的配置类型${l}`);
34
- return;
35
- }
36
- }
37
- }, D = {
38
- sourceFilePath: "./package.json",
39
- keyConfigMap: {
40
- name: {
41
- type: c.READ
42
- },
43
- version: {
44
- type: c.READ
45
- },
46
- description: {
47
- type: c.READ
48
- }
49
- },
50
- injectFilePath: "./src/injectInfo.json"
51
- }, R = {
52
- name: "@done-coding/cli-inject",
53
- version: "0.5.8",
54
- description: "信息(JSON)注入命令行工具",
55
- cliConfig: {
56
- namespaceDir: ".done-coding",
57
- moduleName: "inject"
58
- }
59
- }, {
60
- cliConfig: { namespaceDir: M, moduleName: x }
61
- } = R, H = `./${M}/${x}`, T = `${H}.json`, L = () => h({
62
- configPathDefault: T
63
- }), J = async (e) => _(D, e, {
64
- onFileGenerated: () => {
65
- n.info("文件生成成功");
66
- }
67
- }), U = () => ({
68
- ...h({
69
- configPathDefault: T
70
- })
71
- }), V = async ({
72
- rootDir: e = process.cwd(),
73
- config: o = D,
74
- keyConfigMap: t = {}
75
- } = {}) => {
76
- const {
77
- sourceFilePath: s,
78
- keyConfigMap: l,
79
- injectFilePath: r
80
- } = o, d = {
81
- ...l,
82
- ...t
83
- };
84
- if (!s.endsWith(".json"))
85
- return n.error("源文件必须是json"), process.exit(1);
86
- if (!r.endsWith(".json"))
87
- return n.error("注入文件必须是json"), process.exit(1);
88
- const p = F.resolve(e, s), g = m.readFileSync(p, "utf-8"), E = JSON.parse(g), i = Object.entries(d).reduce(
89
- (f, [C, $]) => {
90
- const P = G({ sourceJson: E, targetKey: C, keyConfig: $ });
91
- return b(f, C, P), f;
92
- },
93
- {}
94
- ), u = F.resolve(e, r), y = JSON.stringify(i, null, 2);
95
- if (m.existsSync(u)) {
96
- const f = m.readFileSync(u, "utf-8");
97
- if (y === f)
98
- return n.skip("注入文件已存在且内容相同,无需重复注入"), i;
99
- n.stage("文件内容变化,开始覆盖注入文件");
100
- } else
101
- n.stage("开始注入文件");
102
- m.writeFileSync(u, y), n.success(`文件注入成功: ${u}`), n.info(y);
103
- }, K = async (e) => {
104
- const o = await k(e);
105
- if (!o)
106
- return n.error("配置文件为空"), process.exit(1);
107
- const { rootDir: t } = e;
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,
112
- cliConfig: { moduleName: j }
113
- } = R, q = {
114
- command: a.INIT,
115
- describe: "初始化提取配置文件",
116
- options: L(),
117
- handler: A(v)(
118
- a.INIT
119
- )
120
- }, z = {
121
- command: a.GENERATE,
122
- describe: "提取信息",
123
- options: U(),
124
- handler: A(v)(
125
- a.GENERATE
126
- )
127
- }, O = {
128
- describe: X,
129
- version: W,
130
- subcommands: [q, z].map(
131
- N
132
- ),
133
- demandCommandCount: 1
134
- }, S = (e = !1) => {
135
- const o = e ? j : void 0, t = `$0${e ? ` ${j}` : ""} <command> [options]`;
136
- return { command: o, usage: t };
137
- }, ee = async () => w({
138
- ...O,
139
- ...S()
140
- }), ne = () => N({
141
- ...O,
142
- ...S(!0)
143
- });
144
- export {
145
- ne as a,
146
- ee as c,
147
- V as g,
148
- v as h,
149
- G as k
150
- };
@@ -1,5 +0,0 @@
1
- import type { GenerateOptions, InitOptions } from './utils';
2
- import { SubcommandEnum } from './utils';
3
- import type { CliHandlerArgv } from "@done-coding/cli-utils";
4
- /** 命令处理函数 */
5
- export declare const handler: (command: SubcommandEnum, argv: CliHandlerArgv<InitOptions | GenerateOptions>) => Promise<void>;
@@ -1,7 +0,0 @@
1
- /// <reference types="yargs" />
2
- import type { CliHandlerArgv } from "@done-coding/cli-utils";
3
- import type { InitOptions } from "./types";
4
- /** 获取初始化选项 */
5
- export declare const getInitOptions: () => Record<keyof import("@done-coding/cli-utils").ConfigFileCommonOptions, import("yargs").Options>;
6
- /** 初始化命令处理器 */
7
- export declare const initHandler: (argv: CliHandlerArgv<InitOptions>) => Promise<void>;
File without changes
File without changes