@simon_he/pi 0.0.0 → 0.0.1

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 CHANGED
@@ -3,6 +3,18 @@
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
+ pi xxx
16
+ ```
17
+
6
18
  ## 自定义配置
7
19
  可以在.zshrc配置loading样式,如下:
8
20
  ```
@@ -15,3 +27,6 @@ export PI_SPINNER=star # loading样式
15
27
  ## 依赖
16
28
  - [@antfu/ni](https://github.com/antfu/ni)
17
29
  - [ora](https://github.com/sindresorhus/ora)
30
+
31
+
32
+
package/dist/index.cjs CHANGED
@@ -2,31 +2,29 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const worker_threads = require('worker_threads');
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.0";
16
+ const version = "0.0.1";
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 argv = process.argv.slice(2);
17
- if (argv[0] === "-v" || argv[0] === "--version") {
18
- console.log(`pi version:${version}`);
19
- process.exit(0);
20
- }
21
- const { status: hasNi } = simonJsTool.jsShell("ni -v", "pipe");
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,87 @@ async function pi() {
36
34
  spinner,
37
35
  color
38
36
  }).start();
39
- const status = await runWorker(params);
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
- pi();
47
- function runWorker(params) {
48
- return new Promise((resolve) => {
49
- const seprateThread = new worker_threads.Worker("./src/seprateThread.js");
50
- seprateThread.on("message", resolve);
51
- seprateThread.postMessage(params);
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");
53
92
  }
93
+ function returnVersion(argv2) {
94
+ const arg = argv2[0];
95
+ if (arg === "-v" || arg === "--version") {
96
+ 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}'`);
97
+ process.exit(0);
98
+ } else if (arg === "-h" || arg === "--help") {
99
+ 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'`);
100
+ process.exit(0);
101
+ }
102
+ }
103
+ const runMap = {
104
+ pi,
105
+ pui,
106
+ prun
107
+ };
108
+ function runner() {
109
+ const cmd = process$1.argv[1];
110
+ const last = cmd.lastIndexOf("/") + 1;
111
+ const exec = cmd.slice(last, cmd.length);
112
+ runMap[exec]?.();
113
+ }
114
+ pi();
115
+ runner();
54
116
 
55
117
  exports.pi = pi;
118
+ exports.prun = prun;
119
+ exports.pui = pui;
120
+ exports.runner = runner;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  declare function pi(): Promise<void>;
2
+ declare function pui(): Promise<void>;
3
+ declare function prun(): Promise<void>;
4
+ declare function runner(): void;
2
5
 
3
- export { pi };
6
+ export { pi, prun, pui, runner };
package/dist/index.mjs CHANGED
@@ -1,24 +1,21 @@
1
- import { Worker } from 'worker_threads';
2
- import { jsShell } from 'simon-js-tool';
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.0";
7
+ const version = "0.0.1";
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 argv = process.argv.slice(2);
9
- if (argv[0] === "-v" || argv[0] === "--version") {
10
- console.log(`pi version:${version}`);
11
- process.exit(0);
12
- }
13
- const { status: hasNi } = jsShell("ni -v", "pipe");
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,84 @@ async function pi() {
28
25
  spinner,
29
26
  color
30
27
  }).start();
31
- const status = await runWorker(params);
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
- pi();
39
- function runWorker(params) {
40
- return new Promise((resolve) => {
41
- const seprateThread = new Worker("./src/seprateThread.js");
42
- seprateThread.on("message", resolve);
43
- seprateThread.postMessage(params);
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");
45
83
  }
84
+ function returnVersion(argv2) {
85
+ const arg = argv2[0];
86
+ if (arg === "-v" || arg === "--version") {
87
+ 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}'`);
88
+ process.exit(0);
89
+ } else if (arg === "-h" || arg === "--help") {
90
+ 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'`);
91
+ process.exit(0);
92
+ }
93
+ }
94
+ const runMap = {
95
+ pi,
96
+ pui,
97
+ prun
98
+ };
99
+ function runner() {
100
+ const cmd = argv[1];
101
+ const last = cmd.lastIndexOf("/") + 1;
102
+ const exec = cmd.slice(last, cmd.length);
103
+ runMap[exec]?.();
104
+ }
105
+ pi();
106
+ runner();
46
107
 
47
- export { pi };
108
+ 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.0",
4
+ "version": "0.0.1",
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.21",
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
  }