@done-coding/cli-utils 0.2.1-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/README.md +7 -0
- package/es/index.mjs +70 -0
- package/package.json +54 -0
- package/types/aes.d.ts +10 -0
- package/types/index.d.ts +3 -0
- package/types/look-for.d.ts +7 -0
- package/types/prompts.d.ts +5 -0
package/README.md
ADDED
package/es/index.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import i from "node:path";
|
|
3
|
+
import g from "node:fs";
|
|
4
|
+
import p from "crypto";
|
|
5
|
+
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;
|
|
12
|
+
}
|
|
13
|
+
}, l = "aes-256-cbc", m = 16, f = "hex", d = ":";
|
|
14
|
+
function y(t) {
|
|
15
|
+
return p.pbkdf2Sync(
|
|
16
|
+
t,
|
|
17
|
+
"done-coding-cli-salt",
|
|
18
|
+
// 使用固定的盐值
|
|
19
|
+
1e4,
|
|
20
|
+
// 迭代次数
|
|
21
|
+
32,
|
|
22
|
+
// AES-256 需要 32 字节密钥
|
|
23
|
+
"sha256"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function A({
|
|
27
|
+
text: t,
|
|
28
|
+
secretKey: c
|
|
29
|
+
}) {
|
|
30
|
+
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)}`
|
|
39
|
+
), "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function B({
|
|
43
|
+
encryptedText: t,
|
|
44
|
+
secretKey: c
|
|
45
|
+
}) {
|
|
46
|
+
try {
|
|
47
|
+
if (!t.includes(d))
|
|
48
|
+
return "";
|
|
49
|
+
const r = y(c), [e, n] = t.split(d);
|
|
50
|
+
if (e.length !== m * 2)
|
|
51
|
+
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)}`
|
|
58
|
+
), "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function $(t) {
|
|
62
|
+
if (t.aborted)
|
|
63
|
+
return console.log(h.red("退出输入")), process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
B as decryptAES,
|
|
67
|
+
A as encryptAES,
|
|
68
|
+
H as lookForParentTarget,
|
|
69
|
+
$ as onPromptFormStateForSigint
|
|
70
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@done-coding/cli-utils",
|
|
3
|
+
"version": "0.2.1-alpha.0",
|
|
4
|
+
"description": "cli utils",
|
|
5
|
+
"private": false,
|
|
6
|
+
"module": "es/index.mjs",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./es/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"es",
|
|
16
|
+
"lib",
|
|
17
|
+
"types",
|
|
18
|
+
"gif"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rimraf es lib types",
|
|
22
|
+
"predev": "pnpm run clean",
|
|
23
|
+
"dev": "vite build --watch",
|
|
24
|
+
"prebuild": "pnpm run clean",
|
|
25
|
+
"build": "vite build",
|
|
26
|
+
"prepack": "pnpm build"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://gitee.com/justsosu/done-coding-cli.git",
|
|
31
|
+
"directory": "packages/utils"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org/"
|
|
36
|
+
},
|
|
37
|
+
"author": "JustSoSu",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^18.0.0",
|
|
42
|
+
"rimraf": "^6.0.1",
|
|
43
|
+
"typescript": "^5.2.2",
|
|
44
|
+
"vite": "^4.4.11",
|
|
45
|
+
"vite-plugin-dts": "^3.6.0"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"chalk": "^5.3.0"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "21eb698f64179882cfec979bd8f19920b047dacb"
|
|
54
|
+
}
|
package/types/aes.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** AES 加密 */
|
|
2
|
+
export declare function encryptAES({ text, secretKey, }: {
|
|
3
|
+
text: string;
|
|
4
|
+
secretKey: string;
|
|
5
|
+
}): string;
|
|
6
|
+
/** AES 解密 */
|
|
7
|
+
export declare function decryptAES({ encryptedText, secretKey, }: {
|
|
8
|
+
encryptedText: string;
|
|
9
|
+
secretKey: string;
|
|
10
|
+
}): string;
|
package/types/index.d.ts
ADDED