@done-coding/cli-inject 0.4.7-alpha.0 → 0.5.0-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,9 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-292f0fc5.js";
3
- import "./handler-995d55e6.js";
2
+ import { c as m } from "./index-1197d11d.js";
3
+ import "./handler-29b2ae8a.js";
4
4
  import "node:path";
5
5
  import "node:fs";
6
6
  import "lodash.get";
7
7
  import "lodash.set";
8
8
  import "@done-coding/cli-utils";
9
- import "yargs";
10
- import "yargs/helpers";
11
- r();
9
+ m();
@@ -5,40 +5,40 @@ import S from "lodash.get";
5
5
  import J from "lodash.set";
6
6
  import { log as t } from "@done-coding/cli-utils";
7
7
  const w = /(?<!\/):/, x = (e) => {
8
- const [r, o = r, ...s] = e.split(w);
8
+ const [s, o = s, ...r] = e.split(w);
9
9
  return {
10
- key: r,
10
+ key: s,
11
11
  /** 目标key */
12
12
  targetKey: o,
13
13
  /** 参数列表 */
14
- paramsList: s
14
+ paramsList: r
15
15
  };
16
16
  }, v = ({
17
17
  valueInit: e,
18
- paramsList: r
18
+ paramsList: s
19
19
  }) => {
20
- const [o, ...s] = r;
20
+ const [o, ...r] = s;
21
21
  switch (o) {
22
22
  case "REG": {
23
- const [n, l, u] = s, f = new RegExp(n, u ?? void 0);
23
+ const [n, l, u] = r, f = new RegExp(n, u ?? void 0);
24
24
  return typeof e == "string" ? e.replace(f, l) : (t.warn(
25
25
  `${e}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
26
26
  ), e);
27
27
  }
28
28
  case "VALUE": {
29
- const [n] = s;
29
+ const [n] = r;
30
30
  return n;
31
31
  }
32
32
  default:
33
33
  return e;
34
34
  }
35
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);
36
+ const { sourceJsonFilePath: s, injectKeyPath: o, injectInfoFilePath: r } = e, n = process.cwd();
39
37
  if (!s.endsWith(".json"))
38
+ return t.error("源文件必须是json"), process.exit(1);
39
+ if (!r.endsWith(".json"))
40
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(
41
+ const l = h.resolve(n, s), u = a.readFileSync(l, "utf-8"), f = JSON.parse(u), g = o.reduce(
42
42
  (c, m) => {
43
43
  const { key: y, targetKey: d, paramsList: j } = x(m);
44
44
  if (!y)
@@ -50,18 +50,18 @@ const w = /(?<!\/):/, x = (e) => {
50
50
  return J(c, d, P), c;
51
51
  },
52
52
  {}
53
- ), i = h.resolve(n, s), g = JSON.stringify(p, null, 2);
53
+ ), i = h.resolve(n, r), p = JSON.stringify(g, null, 2);
54
54
  if (a.existsSync(i)) {
55
55
  const c = a.readFileSync(i, "utf-8");
56
- if (g === c)
57
- return t.skip("注入文件已存在且内容相同,无需重复注入"), p;
56
+ if (p === c)
57
+ return t.skip("注入文件已存在且内容相同,无需重复注入"), g;
58
58
  t.stage("文件内容变化,开始覆盖注入文件");
59
59
  } else
60
60
  t.stage("开始注入文件");
61
- return a.writeFileSync(i, g), console.log(
61
+ a.writeFileSync(i, p), console.log(
62
62
  t.success(`文件注入成功: ${i}`),
63
- t.info(g)
64
- ), p;
63
+ t.info(p)
64
+ );
65
65
  };
66
66
  export {
67
67
  $ as h
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import { h as s } from "./handler-29b2ae8a.js";
3
+ import { createMainCommand as c, createSubcommand as r } from "@done-coding/cli-utils";
4
+ const d = {
5
+ version: "0.5.0-alpha.0",
6
+ name: "@done-coding/cli-inject",
7
+ description: "信息注入命令行工具",
8
+ cliConfig: {
9
+ namespaceDir: ".done-coding",
10
+ moduleName: "inject"
11
+ }
12
+ }, {
13
+ version: m,
14
+ description: l,
15
+ cliConfig: { moduleName: n }
16
+ } = d, p = () => ({
17
+ sourceJsonFilePath: {
18
+ type: "string",
19
+ alias: "s",
20
+ describe: "信息源json文件相对路径",
21
+ default: "./package.json"
22
+ },
23
+ injectKeyPath: {
24
+ type: "array",
25
+ alias: "k",
26
+ describe: "需要注入的key路径",
27
+ default: ["name", "version", "description"]
28
+ },
29
+ injectInfoFilePath: {
30
+ type: "string",
31
+ alias: "i",
32
+ describe: "注入信息文件路径",
33
+ default: "./src/injectInfo.json"
34
+ }
35
+ }), o = {
36
+ describe: l,
37
+ version: m,
38
+ options: p(),
39
+ handler: s
40
+ }, t = (e = !1) => {
41
+ const i = e ? n : void 0, a = `$0${e ? ` ${n}` : ""} [options]`;
42
+ return { command: i, usage: a };
43
+ }, g = async () => c({
44
+ ...o,
45
+ ...t()
46
+ }), j = () => r({
47
+ ...o,
48
+ ...t(!0)
49
+ });
50
+ export {
51
+ j as a,
52
+ g as c
53
+ };
package/es/index.mjs CHANGED
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { h as d } from "./handler-995d55e6.js";
3
- import { a as f } from "./index-292f0fc5.js";
2
+ import { h as i } from "./handler-29b2ae8a.js";
3
+ import { a as s } from "./index-1197d11d.js";
4
4
  import "node:path";
5
5
  import "node:fs";
6
6
  import "lodash.get";
7
7
  import "lodash.set";
8
8
  import "@done-coding/cli-utils";
9
- import "yargs";
10
- import "yargs/helpers";
11
9
  export {
12
- f as command,
13
- d as handler
10
+ s as crateAsSubcommand,
11
+ i as handler
14
12
  };
package/es/use.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { h as e } from "./handler-995d55e6.js";
2
+ import { h as e } from "./handler-29b2ae8a.js";
3
3
  import "node:path";
4
4
  import "node:fs";
5
5
  import "lodash.get";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-inject",
3
- "version": "0.4.7-alpha.0",
3
+ "version": "0.5.0-alpha.0",
4
4
  "description": "信息注入命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -64,10 +64,9 @@
64
64
  "node": ">=18.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@done-coding/cli-utils": "^0.2.2-alpha.0",
67
+ "@done-coding/cli-utils": "^0.3.0-alpha.0",
68
68
  "lodash.get": "^4.4.2",
69
- "lodash.set": "^4.3.2",
70
- "yargs": "^17.7.2"
69
+ "lodash.set": "^4.3.2"
71
70
  },
72
- "gitHead": "2e59e86ee192e023138e7475f4abbb5e7c42b29e"
71
+ "gitHead": "c5a54bdf08759425701a2024442a923883065189"
73
72
  }
@@ -1,3 +1,3 @@
1
1
  import { type Options } from "./utils";
2
- import type { ArgumentsCamelCase } from "yargs";
3
- export declare const handler: (argv: ArgumentsCamelCase<Options> | Options) => Promise<Record<string, any>>;
2
+ import type { CliHandlerArgv } from "@done-coding/cli-utils";
3
+ export declare const handler: (argv: CliHandlerArgv<Options>) => Promise<Record<string, any> | undefined>;
package/types/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { handler } from "./handler";
2
- export { command } from "./main";
2
+ export { crateAsSubcommand } from "./main";
3
3
  export * from './utils/types';
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.4.7-alpha.0",
2
+ "version": "0.5.0-alpha.0",
3
3
  "name": "@done-coding/cli-inject",
4
4
  "description": "信息注入命令行工具",
5
5
  "cliConfig": {
package/types/main.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- import type { CommandModule } from "yargs";
2
- import type { Options } from './utils';
3
- export declare const command: CommandModule<Options, Options>;
4
- export declare const createCli: () => Promise<Record<string, any>>;
1
+ /// <reference types="yargs" />
2
+ /** 作为主命令创建 */
3
+ export declare const createCommand: () => Promise<void | {
4
+ [x: string]: unknown;
5
+ _: (string | number)[];
6
+ $0: string;
7
+ }>;
8
+ /** 作为子命令创建 */
9
+ export declare const crateAsSubcommand: () => import("yargs").CommandModule<{}, {}>;
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env node
2
- import { h as i } from "./handler-995d55e6.js";
3
- import c from "yargs";
4
- import { hideBin as l } from "yargs/helpers";
5
- import { log as s } from "@done-coding/cli-utils";
6
- const o = {
7
- version: "0.4.7-alpha.0",
8
- name: "@done-coding/cli-inject",
9
- description: "信息注入命令行工具",
10
- cliConfig: {
11
- namespaceDir: ".done-coding",
12
- moduleName: "inject"
13
- }
14
- }, m = () => ({
15
- sourceJsonFilePath: {
16
- type: "string",
17
- alias: "s",
18
- describe: "信息源json文件相对路径",
19
- default: "./package.json"
20
- },
21
- injectKeyPath: {
22
- type: "array",
23
- alias: "k",
24
- describe: "需要注入的key路径",
25
- default: ["name", "version", "description"]
26
- },
27
- injectInfoFilePath: {
28
- type: "string",
29
- alias: "i",
30
- describe: "注入信息文件路径",
31
- default: "./src/injectInfo.json"
32
- }
33
- }), a = o.cliConfig.moduleName, d = (e, n) => {
34
- e ? s.error(e) : s.error(n.message), process.exit(1);
35
- }, p = o.description, g = `Usage: $0 ${a} [options]`, f = "Usage: $0 [options]", t = (e, n) => {
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
- }, u = (e) => t(e, g), b = {
39
- command: a,
40
- describe: p,
41
- builder: u,
42
- handler: i
43
- }, C = async () => {
44
- const e = c(l(process.argv)), n = await t(e, f);
45
- return i(n);
46
- };
47
- export {
48
- b as a,
49
- C as c
50
- };