@simon_he/pi 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ <span ><p align="center">![kv](/assets/pi.png)</p></span>
2
+
3
+ ## PI
4
+ 一个带有loading样式的包安装器,让你安装依赖时更加美观:)
5
+
6
+ ## 自定义配置
7
+ 可以在.zshrc配置loading样式,如下:
8
+ ```
9
+ export PI_COLOR=red # loading样式颜色
10
+ export PI_SPINNER=star # loading样式
11
+ ```
12
+ - 样式的种类70+,来源于[cli-spinners](https://jsfiddle.net/sindresorhus/2eLtsbey/embedded/result/),可自行选择将名字填入PI_SPINNER中。
13
+ - 颜色可选值:'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray', 填入PI_COLOR中
14
+
15
+ ## 依赖
16
+ - [@antfu/ni](https://github.com/antfu/ni)
17
+ - [ora](https://github.com/sindresorhus/ora)
package/cli.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node --no-warnings
2
+ import('./dist/index.mjs')
package/dist/index.cjs ADDED
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const worker_threads = require('worker_threads');
6
+ const simonJsTool = require('simon-js-tool');
7
+ const ora = require('ora');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
10
+
11
+ const ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
12
+
13
+ const version = "0.0.0";
14
+
15
+ 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(" ");
30
+ const text = pkg ? `Installing ${pkg} ...
31
+ ` : "\u6B63\u5728\u66F4\u65B0\u4F9D\u8D56...\n";
32
+ const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "\u66F4\u65B0\u4F9D\u8D56\u6210\u529F! \u{1F60A}";
33
+ const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25! \u{1F62D}";
34
+ const loading = ora__default({
35
+ text,
36
+ spinner,
37
+ color
38
+ }).start();
39
+ const status = await runWorker(params);
40
+ if (status === 0)
41
+ loading.succeed(successMsg);
42
+ else
43
+ loading.fail(failMsg);
44
+ process.exit();
45
+ }
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
+ });
53
+ }
54
+
55
+ exports.pi = pi;
@@ -0,0 +1,3 @@
1
+ declare function pi(): Promise<void>;
2
+
3
+ export { pi };
package/dist/index.mjs ADDED
@@ -0,0 +1,47 @@
1
+ import { Worker } from 'worker_threads';
2
+ import { jsShell } from 'simon-js-tool';
3
+ import ora from 'ora';
4
+
5
+ const version = "0.0.0";
6
+
7
+ 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(" ");
22
+ const text = pkg ? `Installing ${pkg} ...
23
+ ` : "\u6B63\u5728\u66F4\u65B0\u4F9D\u8D56...\n";
24
+ const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "\u66F4\u65B0\u4F9D\u8D56\u6210\u529F! \u{1F60A}";
25
+ const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25! \u{1F62D}";
26
+ const loading = ora({
27
+ text,
28
+ spinner,
29
+ color
30
+ }).start();
31
+ const status = await runWorker(params);
32
+ if (status === 0)
33
+ loading.succeed(successMsg);
34
+ else
35
+ loading.fail(failMsg);
36
+ process.exit();
37
+ }
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
+ });
45
+ }
46
+
47
+ export { pi };
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@simon_he/pi",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "packageManager": "pnpm@7.2.1",
6
+ "description": "",
7
+ "author": "Simon He",
8
+ "license": "MIT",
9
+ "funding": "https://github.com/sponsors/Simon-He95",
10
+ "homepage": "https://github.com/Simon-He95/pi#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/Simon-He95/pi.git"
14
+ },
15
+ "bugs": "https://github.com/Simon-He95/pi/issues",
16
+ "keywords": [],
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "require": "./dist/index.cjs",
22
+ "import": "./dist/index.mjs"
23
+ }
24
+ },
25
+ "main": "./dist/index.mjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts",
28
+ "typesVersions": {
29
+ "*": {
30
+ "*": [
31
+ "./dist/*",
32
+ "./dist/index.d.ts"
33
+ ]
34
+ }
35
+ },
36
+ "bin": {
37
+ "pi": "./cli.mjs"
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "scripts": {
43
+ "build": "unbuild",
44
+ "dev": "unbuild --stub",
45
+ "lint": "eslint .",
46
+ "lint:fix": "eslint . --fix",
47
+ "prepublishOnly": "nr build",
48
+ "release": "bumpp && npm publish",
49
+ "start": "esno src/index.ts",
50
+ "test": "vitest",
51
+ "typecheck": "tsc --noEmit"
52
+ },
53
+ "dependencies": {
54
+ "axios": "^1.1.3",
55
+ "chalk": "^5.1.2",
56
+ "clipboardy": "^3.0.0",
57
+ "dot-text": "^1.0.7",
58
+ "libnpmsearch": "^6.0.0",
59
+ "ora": "^6.1.2",
60
+ "simon-js-tool": "^4.1.21",
61
+ "terminal-kit": "^3.0.0",
62
+ "vivid-typing": "^1.1.26"
63
+ },
64
+ "devDependencies": {
65
+ "@antfu/eslint-config": "^0.25.1",
66
+ "@antfu/ni": "^0.16.2",
67
+ "@antfu/utils": "^0.5.2",
68
+ "@types/node": "^18.0.0",
69
+ "bumpp": "^8.2.1",
70
+ "eslint": "^8.18.0",
71
+ "esno": "^0.16.3",
72
+ "pnpm": "^7.2.1",
73
+ "rimraf": "^3.0.2",
74
+ "typescript": "^4.7.4",
75
+ "unbuild": "^0.7.4",
76
+ "vite": "^2.9.12",
77
+ "vitest": "^0.15.1"
78
+ }
79
+ }