@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 +65 -40
- package/package.json +7 -3
- package/types/index.d.ts +1 -0
- package/types/log.d.ts +32 -0
- package/types/prompts.d.ts +4 -5
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
},
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
-
|
|
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:
|
|
28
|
-
secretKey:
|
|
45
|
+
text: r,
|
|
46
|
+
secretKey: n
|
|
29
47
|
}) {
|
|
30
48
|
try {
|
|
31
|
-
const
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
const a =
|
|
35
|
-
return `${a}${d}${
|
|
36
|
-
} catch (
|
|
37
|
-
return
|
|
38
|
-
`加密失败: ${
|
|
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:
|
|
44
|
-
secretKey:
|
|
61
|
+
encryptedText: r,
|
|
62
|
+
secretKey: n
|
|
45
63
|
}) {
|
|
46
64
|
try {
|
|
47
|
-
if (!
|
|
65
|
+
if (!r.includes(d))
|
|
48
66
|
return "";
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
67
|
+
const e = g(n), [t, o] = r.split(d);
|
|
68
|
+
if (t.length !== y * 2)
|
|
51
69
|
return "";
|
|
52
|
-
const
|
|
53
|
-
let
|
|
54
|
-
return
|
|
55
|
-
} catch (
|
|
56
|
-
return
|
|
57
|
-
`解密失败: ${
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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.
|
|
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": "
|
|
57
|
+
"gitHead": "2e59e86ee192e023138e7475f4abbb5e7c42b29e"
|
|
54
58
|
}
|
package/types/index.d.ts
CHANGED
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
|
+
};
|
package/types/prompts.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
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>>;
|