@done-coding/cli-inject 0.4.1 → 0.4.3

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,3 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { createCli as e } from "./main.mjs";
3
- e();
2
+ import { c as r } from "./index-b1ea9d6a.js";
3
+ import "./handler-1283dc4a.js";
4
+ import "node:path";
5
+ import "node:fs";
6
+ import "lodash.get";
7
+ import "lodash.set";
8
+ import "chalk";
9
+ import "yargs";
10
+ import "yargs/helpers";
11
+ r();
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ import m from "node:path";
3
+ import i from "node:fs";
4
+ import S from "lodash.get";
5
+ import J from "lodash.set";
6
+ import o from "chalk";
7
+ const w = /(?<!\/):/, x = (e) => {
8
+ const [t, r = t, ...s] = e.split(w);
9
+ return {
10
+ key: t,
11
+ /** 目标key */
12
+ targetKey: r,
13
+ /** 参数列表 */
14
+ paramsList: s
15
+ };
16
+ }, v = ({
17
+ valueInit: e,
18
+ paramsList: t
19
+ }) => {
20
+ const [r, ...s] = t;
21
+ switch (r) {
22
+ case "REG": {
23
+ const [n, a, u] = s, f = new RegExp(n, u ?? void 0);
24
+ return typeof e == "string" ? e.replace(f, a) : (console.log(
25
+ o.yellow(
26
+ `${e}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
27
+ )
28
+ ), e);
29
+ }
30
+ case "VALUE": {
31
+ const [n] = s;
32
+ return n;
33
+ }
34
+ default:
35
+ return e;
36
+ }
37
+ }, L = async (e) => {
38
+ const { sourceJsonFilePath: t, injectKeyPath: r, injectInfoFilePath: s } = e, n = process.cwd();
39
+ if (!t.endsWith(".json"))
40
+ return console.log(o.red("源文件必须是json")), process.exit(1);
41
+ if (!s.endsWith(".json"))
42
+ return console.log(o.red("注入文件必须是json")), process.exit(1);
43
+ const a = m.resolve(n, t), u = i.readFileSync(a, "utf-8"), f = JSON.parse(u), p = r.reduce(
44
+ (c, y) => {
45
+ const { key: h, targetKey: d, paramsList: j } = x(y);
46
+ if (!h)
47
+ return console.log(o.red(`注入key不能为空,请检查配置${y}是否正确`)), c;
48
+ const F = S(f, h), P = v({
49
+ valueInit: F,
50
+ paramsList: j
51
+ });
52
+ return J(c, d, P), c;
53
+ },
54
+ {}
55
+ ), l = m.resolve(n, s), g = JSON.stringify(p, null, 2);
56
+ if (i.existsSync(l)) {
57
+ const c = i.readFileSync(l, "utf-8");
58
+ if (g === c)
59
+ return console.log(o.gray("注入文件已存在且内容相同,无需重复注入")), p;
60
+ console.log(o.blue("文件内容变化,开始覆盖注入文件"));
61
+ } else
62
+ console.log(o.green("开始注入文件"));
63
+ return i.writeFileSync(l, g), console.log(
64
+ o.green(`文件注入成功: ${l}`),
65
+ o.blue(g)
66
+ ), p;
67
+ };
68
+ export {
69
+ L as h
70
+ };
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import { h as i } from "./handler-1283dc4a.js";
3
+ import r from "yargs";
4
+ import { hideBin as l } from "yargs/helpers";
5
+ import s from "chalk";
6
+ const o = {
7
+ version: "0.4.3",
8
+ name: "@done-coding/cli-inject",
9
+ description: "信息注入命令行工具",
10
+ cliConfig: {
11
+ namespaceDir: ".done-coding",
12
+ moduleName: "inject"
13
+ }
14
+ }, d = () => ({
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, m = (e, n) => {
34
+ console.log(e ? s.red(e) : s.red(n.message)), process.exit(1);
35
+ }, p = o.description, g = `Usage: $0 ${a} [options]`, f = "Usage: $0 [options]", t = (e, n) => {
36
+ const c = d();
37
+ return e.strict().usage(n).help("help").version(o.version).alias("v", "version").alias("h", "help").options(c).fail(m).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 = r(l(process.argv)), n = await t(e, f);
45
+ return i(n);
46
+ };
47
+ export {
48
+ b as a,
49
+ C as c
50
+ };
package/es/index.mjs CHANGED
@@ -1,7 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { handler as e } from "./handler.mjs";
3
- import { command as m } from "./main.mjs";
2
+ import { h as d } from "./handler-1283dc4a.js";
3
+ import { a as f } from "./index-b1ea9d6a.js";
4
+ import "node:path";
5
+ import "node:fs";
6
+ import "lodash.get";
7
+ import "lodash.set";
8
+ import "chalk";
9
+ import "yargs";
10
+ import "yargs/helpers";
4
11
  export {
5
- m as command,
6
- e as handler
12
+ f as command,
13
+ d as handler
7
14
  };
package/es/use.mjs CHANGED
@@ -1,18 +1,23 @@
1
1
  #!/usr/bin/env node
2
- import { handler as o } from "./handler.mjs";
3
- const c = (n = [
2
+ import { h as i } from "./handler-1283dc4a.js";
3
+ import "node:path";
4
+ import "node:fs";
5
+ import "lodash.get";
6
+ import "lodash.set";
7
+ import "chalk";
8
+ const p = (n = `name:cliConfig.moduleName:REG:${/@done-coding\/cli-([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)/.source}:$1`, o = [
4
9
  "version",
5
10
  "name",
6
11
  "description",
7
12
  "name:cliConfig.namespaceDir:VALUE:.done-coding",
8
- `name:cliConfig.moduleName:REG:${/@done-coding\/cli-([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)/.source}:$1`
13
+ n
9
14
  ]) => {
10
- o({
15
+ i({
11
16
  sourceJsonFilePath: "./package.json",
12
- injectKeyPath: n,
17
+ injectKeyPath: o,
13
18
  injectInfoFilePath: "./src/injectInfo.json"
14
19
  });
15
20
  };
16
21
  export {
17
- c as injectDoneCodingCliInfo
22
+ p as injectDoneCodingCliInfo
18
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-inject",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "信息注入命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -72,5 +72,5 @@
72
72
  "prompts": "^2.4.2",
73
73
  "yargs": "^17.7.2"
74
74
  },
75
- "gitHead": "1778df27cf625b5588b1de38d260cfed75e123f2"
75
+ "gitHead": "516ef8bb086ae7be558c68bd7392501ef3ed6052"
76
76
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.4.1",
2
+ "version": "0.4.3",
3
3
  "name": "@done-coding/cli-inject",
4
4
  "description": "信息注入命令行工具",
5
5
  "cliConfig": {
package/types/use.d.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * ---
4
4
  * 从 package.json 中注入 done-coding-cli 信息
5
5
  */
6
- export declare const injectDoneCodingCliInfo: (injectKeyPath?: string[]) => void;
6
+ export declare const injectDoneCodingCliInfo: (moduleNameConfig?: string, injectKeyPath?: string[]) => void;
package/es/handler.mjs DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
- import u from "node:path";
3
- import t from "node:fs";
4
- import S from "lodash.get";
5
- import v from "lodash.set";
6
- import e from "chalk";
7
- import { getKey as J, paramsResolve as P } from "./utils/resolve.mjs";
8
- const O = async (a) => {
9
- const { sourceJsonFilePath: c, injectKeyPath: f, injectInfoFilePath: l } = a, i = process.cwd();
10
- if (!c.endsWith(".json"))
11
- return console.log(e.red("源文件必须是json")), process.exit(1);
12
- if (!l.endsWith(".json"))
13
- return console.log(e.red("注入文件必须是json")), process.exit(1);
14
- const m = u.resolve(i, c), p = t.readFileSync(m, "utf-8"), g = JSON.parse(p), s = f.reduce(
15
- (n, h) => {
16
- const { key: y, targetKey: d, paramsList: j } = J(h), F = S(g, y), I = P({
17
- valueInit: F,
18
- paramsList: j
19
- });
20
- return v(n, d, I), n;
21
- },
22
- {}
23
- ), o = u.resolve(i, l), r = JSON.stringify(s, null, 2);
24
- if (t.existsSync(o)) {
25
- const n = t.readFileSync(o, "utf-8");
26
- if (r === n)
27
- return console.log(e.gray("注入文件已存在且内容相同,无需重复注入")), s;
28
- console.log(e.blue("文件内容变化,开始覆盖注入文件"));
29
- } else
30
- console.log(e.green("开始注入文件"));
31
- return t.writeFileSync(o, r), console.log(
32
- e.green(`文件注入成功: ${o}`),
33
- e.blue(r)
34
- ), s;
35
- };
36
- export {
37
- O as handler
38
- };
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- const n = {
3
- version: "0.4.1",
4
- name: "@done-coding/cli-inject",
5
- description: "信息注入命令行工具",
6
- cliConfig: {
7
- namespaceDir: ".done-coding",
8
- moduleName: "inject"
9
- }
10
- };
11
- export {
12
- n as default
13
- };
package/es/main.mjs DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
- import c from "yargs";
3
- import { hideBin as l } from "yargs/helpers";
4
- import { handler as i } from "./handler.mjs";
5
- import n from "chalk";
6
- import s from "./injectInfo.json.mjs";
7
- const m = () => ({
8
- sourceJsonFilePath: {
9
- type: "string",
10
- alias: "s",
11
- describe: "信息源json文件相对路径",
12
- default: "./package.json"
13
- },
14
- injectKeyPath: {
15
- type: "array",
16
- alias: "k",
17
- describe: "需要注入的key路径",
18
- default: ["name", "version", "description"]
19
- },
20
- injectInfoFilePath: {
21
- type: "string",
22
- alias: "i",
23
- describe: "注入信息文件路径",
24
- default: "./src/injectInfo.json"
25
- }
26
- }), t = s.cliConfig.moduleName, d = (e, o) => {
27
- console.log(e ? n.red(e) : n.red(o.message)), process.exit(1);
28
- }, p = s.description, g = `Usage: $0 ${t} [options]`, f = "Usage: $0 [options]", r = (e, o) => {
29
- const a = m();
30
- return e.strict().usage(o).help("help").version(s.version).alias("v", "version").alias("h", "help").options(a).fail(d).argv;
31
- }, u = (e) => r(e, g), C = {
32
- command: t,
33
- describe: p,
34
- builder: u,
35
- handler: i
36
- }, k = async () => {
37
- const e = c(l(process.argv)), o = await r(e, f);
38
- return i(o);
39
- };
40
- export {
41
- C as command,
42
- k as createCli
43
- };
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- import p from "chalk";
3
- const l = /(?<!\/):/, y = (e) => {
4
- const [t, s = t, ...r] = e.split(l);
5
- return {
6
- key: t,
7
- /** 目标key */
8
- targetKey: s,
9
- /** 参数列表 */
10
- paramsList: r
11
- };
12
- }, f = ({
13
- valueInit: e,
14
- paramsList: t
15
- }) => {
16
- const [s, ...r] = t;
17
- switch (s) {
18
- case "REG": {
19
- const [o, n, c] = r, a = new RegExp(o, c ?? void 0);
20
- return typeof e == "string" ? e.replace(a, n) : (console.log(
21
- p.yellow(
22
- `${e}不是字符串类型,无法使用正则表达式进行替换,此处将直接返回原值`
23
- )
24
- ), e);
25
- }
26
- case "VALUE": {
27
- const [o] = r;
28
- return o;
29
- }
30
- default:
31
- return e;
32
- }
33
- };
34
- export {
35
- y as getKey,
36
- f as paramsResolve
37
- };