@done-coding/cli-utils 0.2.1-alpha.0 → 0.2.2-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/index.mjs CHANGED
@@ -1,19 +1,37 @@
1
1
  #!/usr/bin/env node
2
- import i from "node:path";
3
- import g from "node:fs";
4
- import p from "crypto";
5
2
  import h from "chalk";
6
- const H = (t, c = process.cwd()) => {
7
- const r = i.resolve(c).split(i.sep).map((e, n, o) => n ? i.join(o.slice(0, n).join(i.sep), e) : e);
8
- for (; r.length; ) {
9
- const e = r.pop(), n = i.join(e, t);
10
- if (g.existsSync(n))
11
- return e;
3
+ import { default as O } from "chalk";
4
+ import i from "node:path";
5
+ import v from "node:fs";
6
+ import f from "crypto";
7
+ import S from "prompts";
8
+ const c = Object.assign(
9
+ (r, ...n) => console.log(...n.map((e) => h[r](e))),
10
+ {
11
+ /** 成功 */
12
+ success: (...r) => c("green", ...r),
13
+ /** /步骤 */
14
+ stage: (...r) => c("blue", ...r),
15
+ /** 提示信息 */
16
+ info: (...r) => c("cyan", ...r),
17
+ /** 警告 */
18
+ warn: (...r) => c("yellow", ...r),
19
+ /** 错误 */
20
+ error: (...r) => c("red", ...r),
21
+ /** 跳过 */
22
+ skip: (...r) => c("gray", ...r)
23
+ }
24
+ ), k = (r, n = process.cwd()) => {
25
+ const e = i.resolve(n).split(i.sep).map((t, o, s) => o ? i.join(s.slice(0, o).join(i.sep), t) : t);
26
+ for (; e.length; ) {
27
+ const t = e.pop(), o = i.join(t, r);
28
+ if (v.existsSync(o))
29
+ return t;
12
30
  }
13
- }, l = "aes-256-cbc", m = 16, f = "hex", d = ":";
14
- function y(t) {
15
- return p.pbkdf2Sync(
16
- t,
31
+ }, m = "aes-256-cbc", y = 16, u = "hex", d = ":";
32
+ function g(r) {
33
+ return f.pbkdf2Sync(
34
+ r,
17
35
  "done-coding-cli-salt",
18
36
  // 使用固定的盐值
19
37
  1e4,
@@ -24,47 +42,54 @@ function y(t) {
24
42
  );
25
43
  }
26
44
  function A({
27
- text: t,
28
- secretKey: c
45
+ text: r,
46
+ secretKey: n
29
47
  }) {
30
48
  try {
31
- const r = y(c), e = p.randomBytes(m), n = p.createCipheriv(l, r, e);
32
- let o = n.update(t);
33
- o = Buffer.concat([o, n.final()]);
34
- const a = e.toString(f), s = o.toString(f);
35
- return `${a}${d}${s}`;
36
- } catch (r) {
37
- return console.error(
38
- `加密失败: ${r instanceof Error ? r.message : String(r)}`
49
+ const e = g(n), t = f.randomBytes(y), o = f.createCipheriv(m, e, t);
50
+ let s = o.update(r);
51
+ s = Buffer.concat([s, o.final()]);
52
+ const a = t.toString(u), p = s.toString(u);
53
+ return `${a}${d}${p}`;
54
+ } catch (e) {
55
+ return c.error(
56
+ `加密失败: ${e instanceof Error ? e.message : String(e)}`
39
57
  ), "";
40
58
  }
41
59
  }
42
60
  function B({
43
- encryptedText: t,
44
- secretKey: c
61
+ encryptedText: r,
62
+ secretKey: n
45
63
  }) {
46
64
  try {
47
- if (!t.includes(d))
65
+ if (!r.includes(d))
48
66
  return "";
49
- const r = y(c), [e, n] = t.split(d);
50
- if (e.length !== m * 2)
67
+ const e = g(n), [t, o] = r.split(d);
68
+ if (t.length !== y * 2)
51
69
  return "";
52
- const o = Buffer.from(e, f), a = Buffer.from(n, f), s = p.createDecipheriv(l, r, o);
53
- let u = s.update(a);
54
- return u = Buffer.concat([u, s.final()]), u.toString();
55
- } catch (r) {
56
- return console.error(
57
- `解密失败: ${r instanceof Error ? r.message : String(r)}`
70
+ const s = Buffer.from(t, u), a = Buffer.from(o, u), p = f.createDecipheriv(m, e, s);
71
+ let l = p.update(a);
72
+ return l = Buffer.concat([l, p.final()]), l.toString();
73
+ } catch (e) {
74
+ return c.error(
75
+ `解密失败: ${e instanceof Error ? e.message : String(e)}`
58
76
  ), "";
59
77
  }
60
78
  }
61
- function $(t) {
62
- if (t.aborted)
63
- return console.log(h.red("退出输入")), process.exit(1);
64
- }
79
+ const j = (...r) => {
80
+ const [n, e = {}] = r;
81
+ return S(n, {
82
+ onCancel(t) {
83
+ return c.error(`退出${t == null ? void 0 : t.name}输入`), process.exit(1);
84
+ },
85
+ ...e
86
+ });
87
+ };
65
88
  export {
89
+ O as chalk,
66
90
  B as decryptAES,
67
91
  A as encryptAES,
68
- H as lookForParentTarget,
69
- $ as onPromptFormStateForSigint
92
+ c as log,
93
+ k as lookForParentTarget,
94
+ j as xPrompts
70
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.2.1-alpha.0",
3
+ "version": "0.2.2-alpha.0",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -39,6 +39,8 @@
39
39
  "sideEffects": false,
40
40
  "devDependencies": {
41
41
  "@types/node": "^18.0.0",
42
+ "@types/prompts": "^2.4.6",
43
+ "@types/yargs": "^17.0.28",
42
44
  "rimraf": "^6.0.1",
43
45
  "typescript": "^5.2.2",
44
46
  "vite": "^4.4.11",
@@ -48,7 +50,9 @@
48
50
  "node": ">=18.0.0"
49
51
  },
50
52
  "dependencies": {
51
- "chalk": "^5.3.0"
53
+ "chalk": "^5.3.0",
54
+ "prompts": "^2.4.2",
55
+ "yargs": "^17.7.2"
52
56
  },
53
- "gitHead": "21eb698f64179882cfec979bd8f19920b047dacb"
57
+ "gitHead": "2e59e86ee192e023138e7475f4abbb5e7c42b29e"
54
58
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./log";
1
2
  export * from "./look-for";
2
3
  export * from "./aes";
3
4
  export * from "./prompts";
package/types/log.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import chalk from "chalk";
2
+ export { chalk };
3
+ /** 日志类型 */
4
+ declare enum LogTypeEnum {
5
+ /** 成功 */
6
+ SUCCESS = "green",
7
+ /** 步骤 */
8
+ STAGE = "blue",
9
+ /** 提示信息 */
10
+ INFO = "cyan",
11
+ /** 警告 */
12
+ WARN = "yellow",
13
+ /** 错误 */
14
+ ERROR = "red",
15
+ /** 跳过 */
16
+ SKIP = "gray"
17
+ }
18
+ /** 日志 */
19
+ export declare const log: ((type: LogTypeEnum, ...messages: string[]) => void) & {
20
+ /** 成功 */
21
+ success: (...messages: string[]) => void;
22
+ /** /步骤 */
23
+ stage: (...messages: string[]) => void;
24
+ /** 提示信息 */
25
+ info: (...messages: string[]) => void;
26
+ /** 警告 */
27
+ warn: (...messages: string[]) => void;
28
+ /** 错误 */
29
+ error: (...messages: string[]) => void;
30
+ /** 跳过 */
31
+ skip: (...messages: string[]) => void;
32
+ };
@@ -1,5 +1,4 @@
1
- /** prompt表单-进程退出信号处理 */
2
- export declare function onPromptFormStateForSigint(params: {
3
- aborted: boolean;
4
- value: any;
5
- }): undefined;
1
+ import prompts from "prompts";
2
+ export type { Choice as PromptChoice, Options as PromptOptions, PromptObject, Answers as PromptAnswers, PrevCaller as PromptPrevCaller, Falsy as PromptFalsy, PromptType, ValueOrFunc as PromptValueOrFunc, InitialReturnValue as PromptInitialReturnValue, } from "prompts";
3
+ /** prompts 拓展 */
4
+ export declare const xPrompts: (questions: prompts.PromptObject<string> | prompts.PromptObject<string>[], options?: prompts.Options | undefined) => Promise<prompts.Answers<string>>;