@done-coding/cli-extract 0.1.8 → 0.1.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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-2f3f403a.js";
2
+ import { c as m } from "./index-7899ce46.js";
3
+ import "./index-a1ee6691-8c73eb4d.js";
3
4
  import "@done-coding/cli-utils";
4
- import "./types-a1ee6691-9629699d.js";
5
5
  import "node:path";
6
6
  import "node:fs";
7
7
  import "@done-coding/cli-template";
package/es/helpers.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { E as e, a as n } from "./types-a1ee6691-9629699d.js";
2
+ import { E as e, a as n } from "./index-a1ee6691-8c73eb4d.js";
3
3
  import "@done-coding/cli-utils";
4
4
  import "node:path";
5
5
  import "node:fs";
@@ -0,0 +1,333 @@
1
+ #!/usr/bin/env node
2
+ import { a as r, e as T, E as u, S as h, G as $ } from "./index-a1ee6691-8c73eb4d.js";
3
+ import { log as s, _get as b, createSubcommand as N, getConfigFileCommonOptions as D, initHandlerCommon as v, readConfigFile as F, _set as L, createMainCommand as V } from "@done-coding/cli-utils";
4
+ import j from "node:path";
5
+ import y from "node:fs";
6
+ import { OutputModeEnum as U, batchCompileHandler as W } from "@done-coding/cli-template";
7
+ const O = {
8
+ name: "@done-coding/cli-extract",
9
+ version: "0.1.9-alpha.0",
10
+ description: "信息提取命令行工具",
11
+ cliConfig: {
12
+ namespaceDir: ".done-coding",
13
+ moduleName: "extract"
14
+ }
15
+ }, {
16
+ cliConfig: { namespaceDir: H, moduleName: X }
17
+ } = O, K = `./${H}/${X}`, J = `${K}.json5`, C = ({
18
+ sourceJson: e,
19
+ targetKey: n,
20
+ keyConfig: o
21
+ }) => {
22
+ let t;
23
+ typeof o == "string" ? t = {
24
+ type: r.FIXED,
25
+ value: o
26
+ } : t = o;
27
+ const { type: a = r.READ } = t;
28
+ switch (a) {
29
+ case r.REG: {
30
+ const { sourceKey: c, pattern: m, replaceValue: l, flags: f } = t, d = new RegExp(m, f ?? void 0), i = b(e, c);
31
+ return typeof i == "string" ? i.replace(d, l) : (s.warn(
32
+ `${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
33
+ ), i);
34
+ }
35
+ case r.FIXED: {
36
+ const { value: c } = t;
37
+ return c;
38
+ }
39
+ case r.READ: {
40
+ const { sourceKey: c = n } = t;
41
+ return b(e, c);
42
+ }
43
+ default: {
44
+ s.warn(`未知的配置类型${a}`);
45
+ return;
46
+ }
47
+ }
48
+ }, S = {
49
+ name: "@done-coding/cli-inject",
50
+ version: "0.5.9-alpha.0",
51
+ description: "信息(JSON)注入命令行工具",
52
+ cliConfig: {
53
+ namespaceDir: ".done-coding",
54
+ moduleName: "inject"
55
+ }
56
+ }, {
57
+ cliConfig: { namespaceDir: q, moduleName: z }
58
+ } = S, B = `./${q}/${z}`, A = `${B}.json`, x = {
59
+ sourceFilePath: "./package.json",
60
+ keyConfigMap: {
61
+ name: {
62
+ type: r.READ
63
+ },
64
+ version: {
65
+ type: r.READ
66
+ },
67
+ description: {
68
+ type: r.READ
69
+ }
70
+ },
71
+ injectFilePath: "./src/injectInfo.json"
72
+ }, Q = () => D({
73
+ configPathDefault: A
74
+ }), Y = async (e) => v(x, e, {
75
+ onFileGenerated: () => {
76
+ s.info("文件生成成功");
77
+ }
78
+ }), Z = {
79
+ command: T.INIT,
80
+ describe: "初始化配置文件",
81
+ options: Q(),
82
+ handler: Y
83
+ }, ee = () => ({
84
+ ...D({
85
+ configPathDefault: A
86
+ })
87
+ }), ne = async ({
88
+ rootDir: e = process.cwd(),
89
+ config: n = x,
90
+ keyConfigMap: o = {}
91
+ } = {}) => {
92
+ const {
93
+ sourceFilePath: t,
94
+ keyConfigMap: a,
95
+ injectFilePath: c
96
+ } = n, m = {
97
+ ...a,
98
+ ...o
99
+ };
100
+ if (!t.endsWith(".json"))
101
+ return s.error("源文件必须是json"), process.exit(1);
102
+ if (!c.endsWith(".json"))
103
+ return s.error("注入文件必须是json"), process.exit(1);
104
+ const l = j.resolve(e, t), f = y.readFileSync(l, "utf-8"), d = JSON.parse(f), i = Object.entries(m).reduce(
105
+ (g, [R, P]) => {
106
+ const M = C({ sourceJson: d, targetKey: R, keyConfig: P });
107
+ return L(g, R, M), g;
108
+ },
109
+ {}
110
+ ), p = j.resolve(e, c), E = JSON.stringify(i, null, 2);
111
+ if (y.existsSync(p)) {
112
+ const g = y.readFileSync(p, "utf-8");
113
+ if (E === g)
114
+ return s.skip("注入文件已存在且内容相同,无需重复注入"), i;
115
+ s.stage("文件内容变化,开始覆盖注入文件");
116
+ } else
117
+ s.stage("开始注入文件");
118
+ y.writeFileSync(p, E), s.success(`文件注入成功: ${p}`), s.info(E);
119
+ }, te = async (e) => {
120
+ const n = await F(e);
121
+ if (!n)
122
+ return s.error("配置文件为空"), process.exit(1);
123
+ const { rootDir: o } = e;
124
+ await ne({ rootDir: o, config: n });
125
+ }, oe = {
126
+ command: T.GENERATE,
127
+ describe: "生成文件",
128
+ options: ee(),
129
+ handler: te
130
+ }, { version: se, description: re } = S;
131
+ [Z, oe].map(
132
+ N
133
+ );
134
+ const ce = ({
135
+ input: e,
136
+ rootDir: n
137
+ }) => {
138
+ const o = j.resolve(n, e), t = y.readFileSync(o, "utf-8");
139
+ return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
140
+ }, ie = (e) => typeof e == "object" && !!e, ae = ({
141
+ content: e,
142
+ targetKey: n,
143
+ keyConfig: o
144
+ }) => {
145
+ const { type: t, ...a } = o;
146
+ switch (t) {
147
+ case u.REG: {
148
+ if (typeof e != "string")
149
+ throw new Error(`${t} 类型的keyConfig需要content为字符串`);
150
+ return C({
151
+ sourceJson: {
152
+ [n]: e
153
+ },
154
+ targetKey: n,
155
+ keyConfig: {
156
+ ...a,
157
+ type: r.REG,
158
+ sourceKey: n
159
+ }
160
+ });
161
+ }
162
+ case u.JSON_INJECT: {
163
+ if (!ie(e))
164
+ throw new Error(`${t} 类型的keyConfig需要content为json`);
165
+ return C({
166
+ sourceJson: e,
167
+ targetKey: n,
168
+ keyConfig: o.inject
169
+ });
170
+ }
171
+ case u.FIXED:
172
+ return C({
173
+ sourceJson: {},
174
+ targetKey: n,
175
+ keyConfig: {
176
+ ...a,
177
+ type: r.FIXED
178
+ }
179
+ });
180
+ default:
181
+ throw new Error(`不支持的类型${t}`);
182
+ }
183
+ }, ue = {
184
+ name: "${name}",
185
+ version: "${version}",
186
+ description: "${description}"
187
+ }, de = {
188
+ extractInput: {
189
+ "./package.json": {
190
+ name: {
191
+ type: u.JSON_INJECT,
192
+ inject: {
193
+ type: r.READ
194
+ }
195
+ },
196
+ description: {
197
+ type: u.JSON_INJECT,
198
+ inject: {
199
+ type: r.READ
200
+ }
201
+ },
202
+ version: {
203
+ type: u.JSON_INJECT,
204
+ inject: {
205
+ type: r.READ
206
+ }
207
+ }
208
+ },
209
+ "./README.md": {
210
+ docDescription: {
211
+ type: u.REG,
212
+ pattern: /#\s*([^`])+```([^`]+)```/.source,
213
+ replaceValue: ""
214
+ },
215
+ usage: {
216
+ type: u.REG,
217
+ pattern: /##\s*使用\s*```([^`]+)```/.source,
218
+ replaceValue: "$1"
219
+ }
220
+ }
221
+ },
222
+ extractOutput: {
223
+ list: [
224
+ {
225
+ mode: U.OVERWRITE,
226
+ inputData: JSON.stringify(ue, null, 2),
227
+ output: "./src/extractInfo.json"
228
+ }
229
+ ]
230
+ }
231
+ }, pe = () => D({
232
+ configPathDefault: J
233
+ }), G = async (e) => v(de, e, {
234
+ onFileGenerated: () => {
235
+ s.info("文件生成成功");
236
+ }
237
+ }), me = {
238
+ command: h.INIT,
239
+ describe: "初始化配置文件",
240
+ options: pe(),
241
+ handler: G
242
+ }, le = () => ({
243
+ ...D({
244
+ configPathDefault: J
245
+ }),
246
+ mode: {
247
+ type: "string",
248
+ alias: "m",
249
+ choices: Object.values($),
250
+ default: $.RESULT,
251
+ describe: "生成模式"
252
+ }
253
+ }), fe = async ({
254
+ rootDir: e = process.cwd(),
255
+ config: n
256
+ }) => {
257
+ const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
258
+ (c, [m, l]) => {
259
+ const f = ce({
260
+ rootDir: e,
261
+ input: m
262
+ });
263
+ return Object.entries(l).reduce(
264
+ (d, [i, p]) => {
265
+ const E = ae({
266
+ content: f,
267
+ targetKey: i,
268
+ keyConfig: p
269
+ });
270
+ return d[i] = E, d;
271
+ },
272
+ c
273
+ );
274
+ },
275
+ {}
276
+ );
277
+ await W(
278
+ {
279
+ rootDir: e,
280
+ extraEnvData: a
281
+ },
282
+ t
283
+ );
284
+ }, I = async (e) => {
285
+ const n = await F(e);
286
+ if (!n)
287
+ return s.error("配置文件为空"), process.exit(1);
288
+ const { rootDir: o } = e;
289
+ await fe({ rootDir: o, config: n });
290
+ }, Ee = {
291
+ command: h.GENERATE,
292
+ describe: "生成文件",
293
+ options: le(),
294
+ handler: I
295
+ }, Ne = async (e, n) => {
296
+ switch (e) {
297
+ case h.INIT:
298
+ return G(n);
299
+ case h.GENERATE:
300
+ return I(n);
301
+ default:
302
+ return I(n);
303
+ }
304
+ }, { version: ye, description: ge } = O, k = {
305
+ describe: ge,
306
+ version: ye,
307
+ subcommands: [me, Ee].map(
308
+ N
309
+ ),
310
+ demandCommandCount: 1
311
+ }, {
312
+ cliConfig: { moduleName: w }
313
+ } = O, _ = (e = !1) => {
314
+ const n = e ? w : void 0, o = `$0${e ? ` ${w}` : ""} <command> [options]`;
315
+ return { command: n, usage: o };
316
+ }, Oe = async () => V({
317
+ ...k,
318
+ ..._()
319
+ }), Re = () => N({
320
+ ...k,
321
+ ..._(!0)
322
+ });
323
+ export {
324
+ Re as a,
325
+ me as b,
326
+ Oe as c,
327
+ I as d,
328
+ Ee as e,
329
+ Ne as f,
330
+ fe as g,
331
+ G as h,
332
+ k as i
333
+ };
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ var r = /* @__PURE__ */ ((e) => (e.INIT = "init", e.GENERATE = "generate", e))(r || {}), E = /* @__PURE__ */ ((e) => (e.REG = "reg", e.JSON_INJECT = "json-inject", e.FIXED = "fixed", e))(E || {}), a = /* @__PURE__ */ ((e) => (e.RESULT = "result", e.TEMPLATE = "template", e))(a || {}), i = /* @__PURE__ */ ((e) => (e.INIT = "init", e.GENERATE = "generate", e))(i || {}), t = /* @__PURE__ */ ((e) => (e.REG = "reg", e.FIXED = "fixed", e.READ = "read", e))(t || {});
3
+ export {
4
+ E,
5
+ a as G,
6
+ r as S,
7
+ t as a,
8
+ i as e
9
+ };
package/es/index.mjs CHANGED
@@ -1,14 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import { a as n, g as p, h as s } from "./index-2f3f403a.js";
3
- import { E as u, S as c } from "./types-a1ee6691-9629699d.js";
2
+ import { i as t, a as i, e as s, g as d, d as l, f as p, b as f, h as u } from "./index-7899ce46.js";
3
+ import { E as C, G as E, S as b } from "./index-a1ee6691-8c73eb4d.js";
4
4
  import "@done-coding/cli-utils";
5
5
  import "node:path";
6
6
  import "node:fs";
7
7
  import "@done-coding/cli-template";
8
8
  export {
9
- u as ExtractTypeEnum,
10
- c as SubcommandEnum,
11
- n as crateAsSubcommand,
12
- p as generateFile,
13
- s as handler
9
+ C as ExtractTypeEnum,
10
+ E as GenerateModeEnum,
11
+ b as SubcommandEnum,
12
+ t as commandCliInfo,
13
+ i as crateAsSubcommand,
14
+ s as generateCommandCliInfo,
15
+ d as generateFile,
16
+ l as generateHandler,
17
+ p as handler,
18
+ f as initCommandCliInfo,
19
+ u as initHandler
14
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-extract",
3
- "version": "0.1.8",
3
+ "version": "0.1.9-alpha.0",
4
4
  "description": "信息提取命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -52,7 +52,7 @@
52
52
  "license": "MIT",
53
53
  "sideEffects": false,
54
54
  "devDependencies": {
55
- "@done-coding/cli-inject": "^0.5.8",
55
+ "@done-coding/cli-inject": "^0.5.9-alpha.0",
56
56
  "@types/node": "^18.0.0",
57
57
  "@types/yargs": "^17.0.28",
58
58
  "rimraf": "^6.0.1",
@@ -64,8 +64,8 @@
64
64
  "node": ">=18.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@done-coding/cli-template": "0.7.8",
67
+ "@done-coding/cli-template": "0.7.9-alpha.0",
68
68
  "@done-coding/cli-utils": "^0.7.0"
69
69
  },
70
- "gitHead": "b4fb4f2380a14f72597a1dbfd1bbce22287ef02f"
70
+ "gitHead": "62a4c9df2bf8690e52753e0734ebb09010bb2e88"
71
71
  }
@@ -0,0 +1,3 @@
1
+ import { type ExtractConfig } from '../types';
2
+ declare const config: ExtractConfig;
3
+ export default config;
@@ -0,0 +1,13 @@
1
+ import type { SubCliInfo } from "@done-coding/cli-utils";
2
+ import { type CliHandlerArgv, type CliInfo } from "@done-coding/cli-utils";
3
+ import { type ExtractConfig, type GenerateOptions } from '../types';
4
+ /** 获取生成命令选项 */
5
+ export declare const getOptions: () => CliInfo["options"];
6
+ /** 将提取的信息生成文件 */
7
+ export declare const generateFile: ({ rootDir, config, }: {
8
+ rootDir?: string | undefined;
9
+ config: ExtractConfig;
10
+ }) => Promise<void>;
11
+ /** 提取文件命令处理器 */
12
+ export declare const handler: (argv: CliHandlerArgv<GenerateOptions>) => Promise<undefined>;
13
+ 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,4 +1,4 @@
1
- import { type ExtractConfig } from "../utils";
1
+ import { type ExtractConfig } from "../types";
2
2
  /** done-coding 系列cli 注入信息 */
3
3
  export declare const doneCodingSeriesCliInjectInfo: ExtractConfig;
4
4
  /** done-coding 系列cli 别名发布信息 */
package/types/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { handler } from "./handler";
2
- export { generateFile } from "./utils";
1
+ export * from './handlers';
3
2
  export { crateAsSubcommand } from "./main";
4
- export * from './utils/types';
3
+ export * from './types';
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "@done-coding/cli-extract",
3
- "version": "0.1.8",
3
+ "version": "0.1.9-alpha.0",
4
4
  "description": "信息提取命令行工具",
5
5
  "cliConfig": {
6
6
  "namespaceDir": ".done-coding",
@@ -60,5 +60,15 @@ export interface ExtractConfig {
60
60
  /** 输出配置 */
61
61
  extractOutput: CompileTemplateConfig;
62
62
  }
63
+ /** 生成模式枚举 */
64
+ export declare enum GenerateModeEnum {
65
+ /** 提取出结果 */
66
+ RESULT = "result",
67
+ /** 提取出模板 */
68
+ TEMPLATE = "template"
69
+ }
63
70
  /** 生成选项 */
64
- export type GenerateOptions = ReadConfigFileOptions;
71
+ export interface GenerateOptions extends ReadConfigFileOptions {
72
+ /** 生成模式 */
73
+ mode?: GenerateModeEnum;
74
+ }
@@ -1,4 +1,2 @@
1
- export * from "./types";
2
- export * from "./init";
3
- export * from "./generate";
4
1
  export * from "./path";
2
+ export * from "./resolve";
@@ -1,4 +1,4 @@
1
- import { type ExtractInputKeyConfig } from "./types";
1
+ import { type ExtractInputKeyConfig } from '../types';
2
2
  /** 内容解析 */
3
3
  export declare const contentResolve: ({ input, rootDir, }: {
4
4
  input: string;
@@ -1,326 +0,0 @@
1
- #!/usr/bin/env node
2
- import { log as r, _get as O, _curry as D, createSubcommand as h, getConfigFileCommonOptions as j, initHandlerCommon as F, readConfigFile as v, _set as H, createMainCommand as V } from "@done-coding/cli-utils";
3
- import { a as s, e as m, E as u, S as l } from "./types-a1ee6691-9629699d.js";
4
- import R from "node:path";
5
- import C from "node:fs";
6
- import { OutputModeEnum as L, batchCompileHandler as W } from "@done-coding/cli-template";
7
- const N = ({
8
- sourceJson: e,
9
- targetKey: n,
10
- keyConfig: o
11
- }) => {
12
- let t;
13
- typeof o == "string" ? t = {
14
- type: s.FIXED,
15
- value: o
16
- } : t = o;
17
- const { type: a = s.READ } = t;
18
- switch (a) {
19
- case s.REG: {
20
- const { sourceKey: c, pattern: f, replaceValue: E, flags: g } = t, d = new RegExp(f, g ?? void 0), i = O(e, c);
21
- return typeof i == "string" ? i.replace(d, E) : (r.warn(
22
- `${i}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
23
- ), i);
24
- }
25
- case s.FIXED: {
26
- const { value: c } = t;
27
- return c;
28
- }
29
- case s.READ: {
30
- const { sourceKey: c = n } = t;
31
- return O(e, c);
32
- }
33
- default: {
34
- r.warn(`未知的配置类型${a}`);
35
- return;
36
- }
37
- }
38
- }, $ = {
39
- sourceFilePath: "./package.json",
40
- keyConfigMap: {
41
- name: {
42
- type: s.READ
43
- },
44
- version: {
45
- type: s.READ
46
- },
47
- description: {
48
- type: s.READ
49
- }
50
- },
51
- injectFilePath: "./src/injectInfo.json"
52
- }, w = {
53
- name: "@done-coding/cli-inject",
54
- version: "0.5.8",
55
- description: "信息(JSON)注入命令行工具",
56
- cliConfig: {
57
- namespaceDir: ".done-coding",
58
- moduleName: "inject"
59
- }
60
- }, {
61
- cliConfig: { namespaceDir: U, moduleName: X }
62
- } = w, K = `./${U}/${X}`, x = `${K}.json`, q = () => j({
63
- configPathDefault: x
64
- }), z = async (e) => F($, e, {
65
- onFileGenerated: () => {
66
- r.info("文件生成成功");
67
- }
68
- }), B = () => ({
69
- ...j({
70
- configPathDefault: x
71
- })
72
- }), Q = async ({
73
- rootDir: e = process.cwd(),
74
- config: n = $,
75
- keyConfigMap: o = {}
76
- } = {}) => {
77
- const {
78
- sourceFilePath: t,
79
- keyConfigMap: a,
80
- injectFilePath: c
81
- } = n, f = {
82
- ...a,
83
- ...o
84
- };
85
- if (!t.endsWith(".json"))
86
- return r.error("源文件必须是json"), process.exit(1);
87
- if (!c.endsWith(".json"))
88
- return r.error("注入文件必须是json"), process.exit(1);
89
- const E = R.resolve(e, t), g = C.readFileSync(E, "utf-8"), d = JSON.parse(g), i = Object.entries(f).reduce(
90
- (I, [T, P]) => {
91
- const M = N({ sourceJson: d, targetKey: T, keyConfig: P });
92
- return H(I, T, M), I;
93
- },
94
- {}
95
- ), p = R.resolve(e, c), y = JSON.stringify(i, null, 2);
96
- if (C.existsSync(p)) {
97
- const I = C.readFileSync(p, "utf-8");
98
- if (y === I)
99
- return r.skip("注入文件已存在且内容相同,无需重复注入"), i;
100
- r.stage("文件内容变化,开始覆盖注入文件");
101
- } else
102
- r.stage("开始注入文件");
103
- C.writeFileSync(p, y), r.success(`文件注入成功: ${p}`), r.info(y);
104
- }, Y = async (e) => {
105
- const n = await v(e);
106
- if (!n)
107
- return r.error("配置文件为空"), process.exit(1);
108
- const { rootDir: o } = e;
109
- await Q({ rootDir: o, config: n });
110
- }, J = async (e, n) => e === m.INIT ? z(n) : e === m.GENERATE ? Y(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
111
- version: Z,
112
- description: ee,
113
- cliConfig: { moduleName: Te }
114
- } = w, ne = {
115
- command: m.INIT,
116
- describe: "初始化提取配置文件",
117
- options: q(),
118
- handler: D(J)(
119
- m.INIT
120
- )
121
- }, te = {
122
- command: m.GENERATE,
123
- describe: "提取信息",
124
- options: B(),
125
- handler: D(J)(
126
- m.GENERATE
127
- )
128
- };
129
- [ne, te].map(
130
- h
131
- );
132
- const oe = {
133
- name: "${name}",
134
- version: "${version}",
135
- description: "${description}"
136
- }, re = {
137
- extractInput: {
138
- "./package.json": {
139
- name: {
140
- type: u.JSON_INJECT,
141
- inject: {
142
- type: s.READ
143
- }
144
- },
145
- description: {
146
- type: u.JSON_INJECT,
147
- inject: {
148
- type: s.READ
149
- }
150
- },
151
- version: {
152
- type: u.JSON_INJECT,
153
- inject: {
154
- type: s.READ
155
- }
156
- }
157
- },
158
- "./README.md": {
159
- docDescription: {
160
- type: u.REG,
161
- pattern: /#\s*([^`])+```([^`]+)```/.source,
162
- replaceValue: ""
163
- },
164
- usage: {
165
- type: u.REG,
166
- pattern: /##\s*使用\s*```([^`]+)```/.source,
167
- replaceValue: "$1"
168
- }
169
- }
170
- },
171
- extractOutput: {
172
- list: [
173
- {
174
- mode: L.OVERWRITE,
175
- inputData: JSON.stringify(oe, null, 2),
176
- output: "./src/extractInfo.json"
177
- }
178
- ]
179
- }
180
- }, S = {
181
- name: "@done-coding/cli-extract",
182
- version: "0.1.8",
183
- description: "信息提取命令行工具",
184
- cliConfig: {
185
- namespaceDir: ".done-coding",
186
- moduleName: "extract"
187
- }
188
- }, {
189
- cliConfig: { namespaceDir: se, moduleName: ce }
190
- } = S, ie = `./${se}/${ce}`, b = `${ie}.json5`, ae = () => j({
191
- configPathDefault: b
192
- }), ue = async (e) => F(re, e, {
193
- onFileGenerated: () => {
194
- r.info("文件生成成功");
195
- }
196
- }), de = ({
197
- input: e,
198
- rootDir: n
199
- }) => {
200
- const o = R.resolve(n, e), t = C.readFileSync(o, "utf-8");
201
- return e.endsWith(".json") || e.endsWith(".json5") ? JSON.parse(t) : t;
202
- }, pe = (e) => typeof e == "object" && !!e, me = ({
203
- content: e,
204
- targetKey: n,
205
- keyConfig: o
206
- }) => {
207
- const { type: t, ...a } = o;
208
- switch (t) {
209
- case u.REG: {
210
- if (typeof e != "string")
211
- throw new Error(`${t} 类型的keyConfig需要content为字符串`);
212
- return N({
213
- sourceJson: {
214
- [n]: e
215
- },
216
- targetKey: n,
217
- keyConfig: {
218
- ...a,
219
- type: s.REG,
220
- sourceKey: n
221
- }
222
- });
223
- }
224
- case u.JSON_INJECT: {
225
- if (!pe(e))
226
- throw new Error(`${t} 类型的keyConfig需要content为json`);
227
- return N({
228
- sourceJson: e,
229
- targetKey: n,
230
- keyConfig: o.inject
231
- });
232
- }
233
- case u.FIXED:
234
- return N({
235
- sourceJson: {},
236
- targetKey: n,
237
- keyConfig: {
238
- ...a,
239
- type: s.FIXED
240
- }
241
- });
242
- default:
243
- throw new Error(`不支持的类型${t}`);
244
- }
245
- }, le = () => ({
246
- ...j({
247
- configPathDefault: b
248
- })
249
- }), fe = async ({
250
- rootDir: e = process.cwd(),
251
- config: n
252
- }) => {
253
- const { extractInput: o, extractOutput: t } = n, a = Object.entries(o).reduce(
254
- (c, [f, E]) => {
255
- const g = de({
256
- rootDir: e,
257
- input: f
258
- });
259
- return Object.entries(E).reduce(
260
- (d, [i, p]) => {
261
- const y = me({
262
- content: g,
263
- targetKey: i,
264
- keyConfig: p
265
- });
266
- return d[i] = y, d;
267
- },
268
- c
269
- );
270
- },
271
- {}
272
- );
273
- await W(
274
- {
275
- rootDir: e,
276
- extraEnvData: a
277
- },
278
- t
279
- );
280
- }, Ee = async (e) => {
281
- const n = await v(e);
282
- if (!n)
283
- return r.error("配置文件为空"), process.exit(1);
284
- const { rootDir: o } = e;
285
- await fe({ rootDir: o, config: n });
286
- }, G = async (e, n) => e === l.INIT ? ue(n) : e === l.GENERATE ? Ee(n) : (r.error(`无效的命令: ${e}`), process.exit(1)), {
287
- version: ge,
288
- description: ye,
289
- cliConfig: { moduleName: A }
290
- } = S, Ce = {
291
- command: l.INIT,
292
- describe: "初始化提取配置文件",
293
- options: ae(),
294
- handler: D(G)(
295
- l.INIT
296
- )
297
- }, Ie = {
298
- command: l.GENERATE,
299
- describe: "提取信息",
300
- options: le(),
301
- handler: D(G)(
302
- l.GENERATE
303
- )
304
- }, _ = {
305
- describe: ye,
306
- version: ge,
307
- subcommands: [Ce, Ie].map(
308
- h
309
- ),
310
- demandCommandCount: 1
311
- }, k = (e = !1) => {
312
- const n = e ? A : void 0, o = `$0${e ? ` ${A}` : ""} <command> [options]`;
313
- return { command: n, usage: o };
314
- }, Oe = async () => V({
315
- ..._,
316
- ...k()
317
- }), Ae = () => h({
318
- ..._,
319
- ...k(!0)
320
- });
321
- export {
322
- Ae as a,
323
- Oe as c,
324
- fe as g,
325
- G as h
326
- };
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- var i = /* @__PURE__ */ ((e) => (e.INIT = "init", e.GENERATE = "generate", e))(i || {}), E = /* @__PURE__ */ ((e) => (e.REG = "reg", e.JSON_INJECT = "json-inject", e.FIXED = "fixed", e))(E || {}), n = /* @__PURE__ */ ((e) => (e.INIT = "init", e.GENERATE = "generate", e))(n || {}), r = /* @__PURE__ */ ((e) => (e.REG = "reg", e.FIXED = "fixed", e.READ = "read", e))(r || {});
3
- export {
4
- E,
5
- i as S,
6
- r as a,
7
- n as e
8
- };
@@ -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,2 +0,0 @@
1
- import { type ExtractConfig } from '../utils';
2
- export declare const config: ExtractConfig;
@@ -1,11 +0,0 @@
1
- import { type CliHandlerArgv, type CliInfo } from "@done-coding/cli-utils";
2
- import type { ExtractConfig, GenerateOptions } from "./types";
3
- /** 获取生成命令选项 */
4
- export declare const getGenerateOptions: () => CliInfo["options"];
5
- /** 将提取的信息生成文件 */
6
- export declare const generateFile: ({ rootDir, config, }: {
7
- rootDir?: string | undefined;
8
- config: ExtractConfig;
9
- }) => Promise<void>;
10
- /** 提取文件命令处理器 */
11
- export declare const generateHandler: (argv: CliHandlerArgv<GenerateOptions>) => Promise<undefined>;
@@ -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>;