@simon_he/pi 0.0.0 → 0.0.2
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 +20 -0
- package/dist/index.cjs +92 -24
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +90 -26
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
## PI
|
|
4
4
|
一个带有loading样式的包安装器,让你安装依赖时更加美观:)
|
|
5
5
|
|
|
6
|
+
https://user-images.githubusercontent.com/57086651/200901242-34bc9576-b21c-4e2e-8e9c-9d858c9ffb12.mov
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
```
|
|
10
|
+
npm i -g @simon_he/pi
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
```
|
|
15
|
+
# 安装依赖
|
|
16
|
+
pi xxx
|
|
17
|
+
# 卸载依赖
|
|
18
|
+
pui xxx
|
|
19
|
+
# 执行命令
|
|
20
|
+
prun
|
|
21
|
+
```
|
|
22
|
+
|
|
6
23
|
## 自定义配置
|
|
7
24
|
可以在.zshrc配置loading样式,如下:
|
|
8
25
|
```
|
|
@@ -15,3 +32,6 @@ export PI_SPINNER=star # loading样式
|
|
|
15
32
|
## 依赖
|
|
16
33
|
- [@antfu/ni](https://github.com/antfu/ni)
|
|
17
34
|
- [ora](https://github.com/sindresorhus/ora)
|
|
35
|
+
- [ccommand](https://github.com/Simon-He95/ccommand)
|
|
36
|
+
|
|
37
|
+
|
package/dist/index.cjs
CHANGED
|
@@ -2,31 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const process$1 = require('process');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const url$1 = require('url');
|
|
6
8
|
const simonJsTool = require('simon-js-tool');
|
|
7
9
|
const ora = require('ora');
|
|
8
10
|
|
|
9
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
10
12
|
|
|
13
|
+
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
11
14
|
const ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
|
|
12
15
|
|
|
13
|
-
const version = "0.0.
|
|
16
|
+
const version = "0.0.2";
|
|
14
17
|
|
|
18
|
+
const __filename$1 = url$1.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
19
|
+
const __dirname$1 = path__default.dirname(__filename$1);
|
|
20
|
+
const url = path__default.resolve(__dirname$1, "./seprateThread.js");
|
|
15
21
|
async function pi() {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
if (hasNi === 1)
|
|
23
|
-
await simonJsTool.jsShell("npm i -g @antfu/ni", "pipe");
|
|
24
|
-
const { result: _color = "yellow" } = await simonJsTool.jsShell("echo $PI_COLOR", "pipe");
|
|
25
|
-
const color = _color;
|
|
26
|
-
const { result: _spinner = "star" } = await simonJsTool.jsShell("echo $PI_SPINNER", "pipe");
|
|
27
|
-
const spinner = _spinner;
|
|
28
|
-
const params = argv.join(" ");
|
|
29
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
22
|
+
const argv2 = process.argv.slice(2);
|
|
23
|
+
await installDeps();
|
|
24
|
+
returnVersion(argv2);
|
|
25
|
+
const { color, spinner } = await getStyle();
|
|
26
|
+
const params = argv2.join(" ");
|
|
27
|
+
const pkg = argv2.filter((v) => !v.startsWith("-")).join(" ");
|
|
30
28
|
const text = pkg ? `Installing ${pkg} ...
|
|
31
29
|
` : "\u6B63\u5728\u66F4\u65B0\u4F9D\u8D56...\n";
|
|
32
30
|
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "\u66F4\u65B0\u4F9D\u8D56\u6210\u529F! \u{1F60A}";
|
|
@@ -36,20 +34,90 @@ async function pi() {
|
|
|
36
34
|
spinner,
|
|
37
35
|
color
|
|
38
36
|
}).start();
|
|
39
|
-
const status = await
|
|
37
|
+
const { status } = await simonJsTool.useNodeWorker(url, { params, operate: "install" });
|
|
40
38
|
if (status === 0)
|
|
41
39
|
loading.succeed(successMsg);
|
|
42
40
|
else
|
|
43
41
|
loading.fail(failMsg);
|
|
44
42
|
process.exit();
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
async function pui() {
|
|
45
|
+
const argv2 = process.argv.slice(2);
|
|
46
|
+
await installDeps();
|
|
47
|
+
returnVersion(argv2);
|
|
48
|
+
const { color, spinner } = await getStyle();
|
|
49
|
+
const params = argv2.join(" ");
|
|
50
|
+
const pkg = argv2.filter((v) => !v.startsWith("-")).join(" ");
|
|
51
|
+
const text = `Uninstalling ${pkg} ...
|
|
52
|
+
`;
|
|
53
|
+
const successMsg = `unInstalled ${pkg} successfully! \u{1F60A}`;
|
|
54
|
+
const failMsg = `Failed to uninstall ${pkg} \u{1F62D}`;
|
|
55
|
+
if (!pkg) {
|
|
56
|
+
console.log("\u8BF7\u8F93\u5165\u8981\u5378\u8F7D\u7684\u5305\u540D");
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
const loading = ora__default({
|
|
60
|
+
text,
|
|
61
|
+
spinner,
|
|
62
|
+
color
|
|
63
|
+
}).start();
|
|
64
|
+
const { status } = await simonJsTool.useNodeWorker(url, { params, operate: "uninstall" });
|
|
65
|
+
if (status === 0)
|
|
66
|
+
loading.succeed(successMsg);
|
|
67
|
+
else
|
|
68
|
+
loading.fail(failMsg);
|
|
69
|
+
process.exit();
|
|
70
|
+
}
|
|
71
|
+
async function prun() {
|
|
72
|
+
const argv2 = process.argv.slice(2);
|
|
73
|
+
await installDeps();
|
|
74
|
+
returnVersion(argv2);
|
|
75
|
+
const params = argv2.join(" ");
|
|
76
|
+
simonJsTool.jsShell(`ccommand ${params}`);
|
|
77
|
+
}
|
|
78
|
+
async function getStyle() {
|
|
79
|
+
const { result: _color = "yellow" } = await simonJsTool.jsShell("echo $PI_COLOR", "pipe");
|
|
80
|
+
const color = _color;
|
|
81
|
+
const { result: _spinner = "star" } = await simonJsTool.jsShell("echo $PI_SPINNER", "pipe");
|
|
82
|
+
const spinner = _spinner;
|
|
83
|
+
return { color, spinner };
|
|
84
|
+
}
|
|
85
|
+
async function installDeps() {
|
|
86
|
+
const { status: hasGum } = simonJsTool.jsShell("gum -v", "pipe");
|
|
87
|
+
if (hasGum === 1)
|
|
88
|
+
await simonJsTool.jsShell("brew install gum", "pipe");
|
|
89
|
+
const { status: hasNi } = simonJsTool.jsShell("ni -v", "pipe");
|
|
90
|
+
if (hasNi === 1)
|
|
91
|
+
await simonJsTool.jsShell("npm i -g @antfu/ni", "pipe");
|
|
92
|
+
const { status: hasCcommand } = simonJsTool.jsShell("ccommand -v", "pipe");
|
|
93
|
+
if (hasCcommand === 1)
|
|
94
|
+
await simonJsTool.jsShell("npm i -g ccommand", "pipe");
|
|
53
95
|
}
|
|
96
|
+
function returnVersion(argv2) {
|
|
97
|
+
const arg = argv2[0];
|
|
98
|
+
if (arg === "-v" || arg === "--version") {
|
|
99
|
+
simonJsTool.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${version}' '\u8BF7\u4E3A\u6211\u7684\u52AA\u529B\u70B9\u4E2Astar\u{1F31F}'`);
|
|
100
|
+
process.exit(0);
|
|
101
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
102
|
+
simonJsTool.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' 'pi: install package' 'pui: uninstall package' 'prun: run package script'`);
|
|
103
|
+
process.exit(0);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const runMap = {
|
|
107
|
+
pi,
|
|
108
|
+
pui,
|
|
109
|
+
prun
|
|
110
|
+
};
|
|
111
|
+
function runner() {
|
|
112
|
+
const cmd = process$1.argv[1];
|
|
113
|
+
const last = cmd.lastIndexOf("/") + 1;
|
|
114
|
+
const exec = cmd.slice(last, cmd.length);
|
|
115
|
+
runMap[exec]?.();
|
|
116
|
+
}
|
|
117
|
+
pi();
|
|
118
|
+
runner();
|
|
54
119
|
|
|
55
120
|
exports.pi = pi;
|
|
121
|
+
exports.prun = prun;
|
|
122
|
+
exports.pui = pui;
|
|
123
|
+
exports.runner = runner;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { argv } from 'process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { useNodeWorker, jsShell } from 'simon-js-tool';
|
|
3
5
|
import ora from 'ora';
|
|
4
6
|
|
|
5
|
-
const version = "0.0.
|
|
7
|
+
const version = "0.0.2";
|
|
6
8
|
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const url = path.resolve(__dirname, "./seprateThread.js");
|
|
7
12
|
async function pi() {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
if (hasNi === 1)
|
|
15
|
-
await jsShell("npm i -g @antfu/ni", "pipe");
|
|
16
|
-
const { result: _color = "yellow" } = await jsShell("echo $PI_COLOR", "pipe");
|
|
17
|
-
const color = _color;
|
|
18
|
-
const { result: _spinner = "star" } = await jsShell("echo $PI_SPINNER", "pipe");
|
|
19
|
-
const spinner = _spinner;
|
|
20
|
-
const params = argv.join(" ");
|
|
21
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
13
|
+
const argv2 = process.argv.slice(2);
|
|
14
|
+
await installDeps();
|
|
15
|
+
returnVersion(argv2);
|
|
16
|
+
const { color, spinner } = await getStyle();
|
|
17
|
+
const params = argv2.join(" ");
|
|
18
|
+
const pkg = argv2.filter((v) => !v.startsWith("-")).join(" ");
|
|
22
19
|
const text = pkg ? `Installing ${pkg} ...
|
|
23
20
|
` : "\u6B63\u5728\u66F4\u65B0\u4F9D\u8D56...\n";
|
|
24
21
|
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "\u66F4\u65B0\u4F9D\u8D56\u6210\u529F! \u{1F60A}";
|
|
@@ -28,20 +25,87 @@ async function pi() {
|
|
|
28
25
|
spinner,
|
|
29
26
|
color
|
|
30
27
|
}).start();
|
|
31
|
-
const status = await
|
|
28
|
+
const { status } = await useNodeWorker(url, { params, operate: "install" });
|
|
32
29
|
if (status === 0)
|
|
33
30
|
loading.succeed(successMsg);
|
|
34
31
|
else
|
|
35
32
|
loading.fail(failMsg);
|
|
36
33
|
process.exit();
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
async function pui() {
|
|
36
|
+
const argv2 = process.argv.slice(2);
|
|
37
|
+
await installDeps();
|
|
38
|
+
returnVersion(argv2);
|
|
39
|
+
const { color, spinner } = await getStyle();
|
|
40
|
+
const params = argv2.join(" ");
|
|
41
|
+
const pkg = argv2.filter((v) => !v.startsWith("-")).join(" ");
|
|
42
|
+
const text = `Uninstalling ${pkg} ...
|
|
43
|
+
`;
|
|
44
|
+
const successMsg = `unInstalled ${pkg} successfully! \u{1F60A}`;
|
|
45
|
+
const failMsg = `Failed to uninstall ${pkg} \u{1F62D}`;
|
|
46
|
+
if (!pkg) {
|
|
47
|
+
console.log("\u8BF7\u8F93\u5165\u8981\u5378\u8F7D\u7684\u5305\u540D");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
const loading = ora({
|
|
51
|
+
text,
|
|
52
|
+
spinner,
|
|
53
|
+
color
|
|
54
|
+
}).start();
|
|
55
|
+
const { status } = await useNodeWorker(url, { params, operate: "uninstall" });
|
|
56
|
+
if (status === 0)
|
|
57
|
+
loading.succeed(successMsg);
|
|
58
|
+
else
|
|
59
|
+
loading.fail(failMsg);
|
|
60
|
+
process.exit();
|
|
61
|
+
}
|
|
62
|
+
async function prun() {
|
|
63
|
+
const argv2 = process.argv.slice(2);
|
|
64
|
+
await installDeps();
|
|
65
|
+
returnVersion(argv2);
|
|
66
|
+
const params = argv2.join(" ");
|
|
67
|
+
jsShell(`ccommand ${params}`);
|
|
68
|
+
}
|
|
69
|
+
async function getStyle() {
|
|
70
|
+
const { result: _color = "yellow" } = await jsShell("echo $PI_COLOR", "pipe");
|
|
71
|
+
const color = _color;
|
|
72
|
+
const { result: _spinner = "star" } = await jsShell("echo $PI_SPINNER", "pipe");
|
|
73
|
+
const spinner = _spinner;
|
|
74
|
+
return { color, spinner };
|
|
75
|
+
}
|
|
76
|
+
async function installDeps() {
|
|
77
|
+
const { status: hasGum } = jsShell("gum -v", "pipe");
|
|
78
|
+
if (hasGum === 1)
|
|
79
|
+
await jsShell("brew install gum", "pipe");
|
|
80
|
+
const { status: hasNi } = jsShell("ni -v", "pipe");
|
|
81
|
+
if (hasNi === 1)
|
|
82
|
+
await jsShell("npm i -g @antfu/ni", "pipe");
|
|
83
|
+
const { status: hasCcommand } = jsShell("ccommand -v", "pipe");
|
|
84
|
+
if (hasCcommand === 1)
|
|
85
|
+
await jsShell("npm i -g ccommand", "pipe");
|
|
45
86
|
}
|
|
87
|
+
function returnVersion(argv2) {
|
|
88
|
+
const arg = argv2[0];
|
|
89
|
+
if (arg === "-v" || arg === "--version") {
|
|
90
|
+
jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${version}' '\u8BF7\u4E3A\u6211\u7684\u52AA\u529B\u70B9\u4E2Astar\u{1F31F}'`);
|
|
91
|
+
process.exit(0);
|
|
92
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
93
|
+
jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' 'pi: install package' 'pui: uninstall package' 'prun: run package script'`);
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const runMap = {
|
|
98
|
+
pi,
|
|
99
|
+
pui,
|
|
100
|
+
prun
|
|
101
|
+
};
|
|
102
|
+
function runner() {
|
|
103
|
+
const cmd = argv[1];
|
|
104
|
+
const last = cmd.lastIndexOf("/") + 1;
|
|
105
|
+
const exec = cmd.slice(last, cmd.length);
|
|
106
|
+
runMap[exec]?.();
|
|
107
|
+
}
|
|
108
|
+
pi();
|
|
109
|
+
runner();
|
|
46
110
|
|
|
47
|
-
export { pi };
|
|
111
|
+
export { pi, prun, pui, runner };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simon_he/pi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"packageManager": "pnpm@7.2.1",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "Simon He",
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"bin": {
|
|
37
|
-
"pi": "./cli.mjs"
|
|
37
|
+
"pi": "./cli.mjs",
|
|
38
|
+
"pui": "./cli.mjs",
|
|
39
|
+
"prun": "./cli.mjs"
|
|
38
40
|
},
|
|
39
41
|
"files": [
|
|
40
42
|
"dist"
|
|
@@ -57,8 +59,10 @@
|
|
|
57
59
|
"dot-text": "^1.0.7",
|
|
58
60
|
"libnpmsearch": "^6.0.0",
|
|
59
61
|
"ora": "^6.1.2",
|
|
60
|
-
"simon-js-tool": "^4.1.
|
|
62
|
+
"simon-js-tool": "^4.1.24",
|
|
61
63
|
"terminal-kit": "^3.0.0",
|
|
64
|
+
"terminal-link": "^3.0.0",
|
|
65
|
+
"vitest": "^0.25.1",
|
|
62
66
|
"vivid-typing": "^1.1.26"
|
|
63
67
|
},
|
|
64
68
|
"devDependencies": {
|
|
@@ -72,8 +76,6 @@
|
|
|
72
76
|
"pnpm": "^7.2.1",
|
|
73
77
|
"rimraf": "^3.0.2",
|
|
74
78
|
"typescript": "^4.7.4",
|
|
75
|
-
"unbuild": "^0.7.4"
|
|
76
|
-
"vite": "^2.9.12",
|
|
77
|
-
"vitest": "^0.15.1"
|
|
79
|
+
"unbuild": "^0.7.4"
|
|
78
80
|
}
|
|
79
81
|
}
|