@simon_he/pi 0.0.16 → 0.0.18
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 +28 -2
- package/dist/index.cjs +10 -254
- package/dist/index.d.ts +10 -4
- package/dist/index.mjs +10 -238
- package/package.json +15 -9
- package/dist/chunks/index.cjs +0 -7000
- package/dist/chunks/index.mjs +0 -6982
- package/dist/seprateThread.cjs +0 -15
- package/dist/seprateThread.d.ts +0 -1
- package/dist/seprateThread.mjs +0 -13
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<span ><p align="center"></p></span>
|
|
2
2
|
|
|
3
3
|
<p align="center"> English | <a href="./README_zh.md">简体中文</a></p>
|
|
4
4
|
<p align="center"><a href="https://www.npmjs.com/package/@simon_he/pi"><img src="https://img.shields.io/npm/v/@simon_he/pi?color=3fb883&label=" alt="NPM version"></a>
|
|
@@ -15,7 +15,29 @@ A smart package manager with a custom loading style, which makes you install dep
|
|
|
15
15
|
- Support pnpm dependency installation, uninstallation and execution
|
|
16
16
|
- Support yarn dependency installation, uninstallation and execution
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Demo
|
|
19
|
+
|
|
20
|
+
- pi
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
- pui
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
- pci
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
- prun
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
- pfind
|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
- others
|
|
40
|
+

|
|
19
41
|
|
|
20
42
|
## :gear: Install
|
|
21
43
|
|
|
@@ -33,10 +55,14 @@ https://user-images.githubusercontent.com/57086651/203143603-9e78f686-399e-4c3d-
|
|
|
33
55
|
pui xxx
|
|
34
56
|
# Execute command
|
|
35
57
|
prun
|
|
58
|
+
# Execute scripts in workspace
|
|
59
|
+
pfind
|
|
36
60
|
# Initialization
|
|
37
61
|
pinit
|
|
38
62
|
# build - for cargo, go
|
|
39
63
|
pbuild
|
|
64
|
+
# pci
|
|
65
|
+
|
|
40
66
|
```
|
|
41
67
|
|
|
42
68
|
## Power
|
package/dist/index.cjs
CHANGED
|
@@ -1,254 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
require('fs');
|
|
12
|
-
require('child_process');
|
|
13
|
-
require('worker_threads');
|
|
14
|
-
require('util');
|
|
15
|
-
require('stream');
|
|
16
|
-
require('zlib');
|
|
17
|
-
require('assert');
|
|
18
|
-
require('buffer');
|
|
19
|
-
|
|
20
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
21
|
-
|
|
22
|
-
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
23
|
-
const process__default = /*#__PURE__*/_interopDefaultLegacy(process);
|
|
24
|
-
const ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
|
|
25
|
-
const fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
|
|
26
|
-
|
|
27
|
-
const version = "0.0.16";
|
|
28
|
-
|
|
29
|
-
const rootPath = process__default.cwd();
|
|
30
|
-
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)));
|
|
31
|
-
const __dirname$1 = path__default.dirname(__filename$1);
|
|
32
|
-
const url = path__default.resolve(__dirname$1, "./seprateThread.mjs");
|
|
33
|
-
async function pi(params, pkg) {
|
|
34
|
-
const text = pkg ? `Installing ${pkg} ...
|
|
35
|
-
` : "Updating dependency ...\n";
|
|
36
|
-
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
|
|
37
|
-
const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
|
|
38
|
-
const loading_status = await loading(text);
|
|
39
|
-
const { status } = await index.useNodeWorker(url, `ni ${params}`);
|
|
40
|
-
if (status === 0)
|
|
41
|
-
loading_status.succeed(successMsg);
|
|
42
|
-
else
|
|
43
|
-
loading_status.fail(failMsg);
|
|
44
|
-
process__default.exit();
|
|
45
|
-
}
|
|
46
|
-
async function pui(params, pkg) {
|
|
47
|
-
const text = `Uninstalling ${pkg} ...
|
|
48
|
-
`;
|
|
49
|
-
const successMsg = `
|
|
50
|
-
UnInstalled ${pkg} successfully! \u{1F60A}`;
|
|
51
|
-
const failMsg = `
|
|
52
|
-
Failed to uninstall ${pkg} \u{1F62D}`;
|
|
53
|
-
if (!pkg) {
|
|
54
|
-
console.log("Need to specify an uninstall package name");
|
|
55
|
-
process__default.exit(1);
|
|
56
|
-
}
|
|
57
|
-
const loading_status = await loading(text);
|
|
58
|
-
const { status } = await index.useNodeWorker(url, `nun ${params}`);
|
|
59
|
-
if (status === 0)
|
|
60
|
-
loading_status.succeed(successMsg);
|
|
61
|
-
else
|
|
62
|
-
loading_status.fail(failMsg);
|
|
63
|
-
process__default.exit();
|
|
64
|
-
}
|
|
65
|
-
function prun(params) {
|
|
66
|
-
index.jsShell(`ccommand ${params}`);
|
|
67
|
-
}
|
|
68
|
-
function pfind(params) {
|
|
69
|
-
index.jsShell(`ccommand find ${params}`);
|
|
70
|
-
}
|
|
71
|
-
function pinit() {
|
|
72
|
-
console.log("Initializing project...");
|
|
73
|
-
switch (index.getPkgTool()) {
|
|
74
|
-
case "npm":
|
|
75
|
-
index.jsShell("npm init -y");
|
|
76
|
-
return;
|
|
77
|
-
case "yarn":
|
|
78
|
-
index.jsShell("yarn init -y");
|
|
79
|
-
return;
|
|
80
|
-
case "pnpm":
|
|
81
|
-
index.jsShell("pnpm init -y");
|
|
82
|
-
return;
|
|
83
|
-
default:
|
|
84
|
-
index.jsShell("npm init -y");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function getStyle() {
|
|
88
|
-
const { result: _color = "yellow" } = await index.jsShell("echo $PI_COLOR", "pipe");
|
|
89
|
-
const color = _color;
|
|
90
|
-
const { result: _spinner = "star" } = await index.jsShell(
|
|
91
|
-
"echo $PI_SPINNER",
|
|
92
|
-
"pipe"
|
|
93
|
-
);
|
|
94
|
-
const spinner = _spinner;
|
|
95
|
-
return { color, spinner };
|
|
96
|
-
}
|
|
97
|
-
async function installDeps() {
|
|
98
|
-
const { status: hasGum } = index.jsShell("gum -v", "pipe");
|
|
99
|
-
if (hasGum === 1)
|
|
100
|
-
await index.jsShell("brew install gum", "pipe");
|
|
101
|
-
const { status: hasNi } = index.jsShell("ni -v", "pipe");
|
|
102
|
-
if (hasNi === 1)
|
|
103
|
-
await index.jsShell("npm i -g @antfu/ni", "pipe");
|
|
104
|
-
const { status: hasCcommand } = index.jsShell("ccommand -v", "pipe");
|
|
105
|
-
if (hasCcommand === 1)
|
|
106
|
-
await index.jsShell("npm i -g ccommand", "pipe");
|
|
107
|
-
}
|
|
108
|
-
function returnVersion(argv) {
|
|
109
|
-
const arg = argv[0];
|
|
110
|
-
if (arg === "-v" || arg === "--version") {
|
|
111
|
-
index.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${version}' 'Please give me a \u{1F31F} for my efforts'`);
|
|
112
|
-
process__default.exit(0);
|
|
113
|
-
} else if (arg === "-h" || arg === "--help") {
|
|
114
|
-
index.jsShell(
|
|
115
|
-
`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' 'pinit: package init' 'pbuild: go build | cargo build' 'pfind: find monorepo of yarn or pnpm'`
|
|
116
|
-
);
|
|
117
|
-
process__default.exit(0);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const runMap = {
|
|
121
|
-
pi,
|
|
122
|
-
pui,
|
|
123
|
-
prun,
|
|
124
|
-
pinit,
|
|
125
|
-
pfind
|
|
126
|
-
};
|
|
127
|
-
function isGo() {
|
|
128
|
-
const url2 = path__default.resolve(rootPath, "go.mod");
|
|
129
|
-
const { result } = index.jsShell(
|
|
130
|
-
`(test -f "main.go" || test -f "${url2}") && echo "0"|| echo "1"`,
|
|
131
|
-
"pipe"
|
|
132
|
-
);
|
|
133
|
-
return result === "0";
|
|
134
|
-
}
|
|
135
|
-
function isRust() {
|
|
136
|
-
const url2 = path__default.resolve(rootPath, "Cargo.toml");
|
|
137
|
-
const { result } = index.jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
138
|
-
return result === "0";
|
|
139
|
-
}
|
|
140
|
-
async function loading(text) {
|
|
141
|
-
const { color, spinner } = await getStyle();
|
|
142
|
-
const result = ora__default({
|
|
143
|
-
text,
|
|
144
|
-
spinner,
|
|
145
|
-
color
|
|
146
|
-
}).start();
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
function hasPkg() {
|
|
150
|
-
const url2 = path__default.resolve(rootPath, "package.json");
|
|
151
|
-
const { result } = index.jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
152
|
-
return result === "0";
|
|
153
|
-
}
|
|
154
|
-
async function runner() {
|
|
155
|
-
const cmd = process__default.argv[1];
|
|
156
|
-
const last = cmd.lastIndexOf("/") + 1;
|
|
157
|
-
const exec = cmd.slice(last, cmd.length);
|
|
158
|
-
const argv = process__default.argv.slice(2);
|
|
159
|
-
returnVersion(argv);
|
|
160
|
-
const params = argv.join(" ").trim();
|
|
161
|
-
if (!hasPkg()) {
|
|
162
|
-
if (isGo()) {
|
|
163
|
-
if (exec === "pi") {
|
|
164
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
165
|
-
`);
|
|
166
|
-
const { status } = await index.useNodeWorker(
|
|
167
|
-
url,
|
|
168
|
-
`go get ${params}`
|
|
169
|
-
);
|
|
170
|
-
if (status === 0)
|
|
171
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
172
|
-
else
|
|
173
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
174
|
-
} else if (exec === "pui") {
|
|
175
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
176
|
-
`);
|
|
177
|
-
const { status } = await index.useNodeWorker(
|
|
178
|
-
url,
|
|
179
|
-
`go clean ${params}`
|
|
180
|
-
);
|
|
181
|
-
if (status === 0)
|
|
182
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
183
|
-
else
|
|
184
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
185
|
-
} else if (exec === "prun") {
|
|
186
|
-
const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
|
|
187
|
-
const target = (await fg__default(match))[0];
|
|
188
|
-
if (!target) {
|
|
189
|
-
console.log("No such file");
|
|
190
|
-
process__default.exit(1);
|
|
191
|
-
}
|
|
192
|
-
index.jsShell(`go run ${target}`);
|
|
193
|
-
} else if (exec === "pinit") {
|
|
194
|
-
index.jsShell(`go mod init ${params}`);
|
|
195
|
-
} else if (exec === "pbuild") {
|
|
196
|
-
index.jsShell(`go build ${params}`);
|
|
197
|
-
} else {
|
|
198
|
-
console.log("The commands is not supported");
|
|
199
|
-
}
|
|
200
|
-
process__default.exit();
|
|
201
|
-
}
|
|
202
|
-
if (isRust()) {
|
|
203
|
-
if (exec === "pi") {
|
|
204
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
205
|
-
`);
|
|
206
|
-
const { status } = await index.useNodeWorker(
|
|
207
|
-
url,
|
|
208
|
-
`cargo install ${params}`
|
|
209
|
-
);
|
|
210
|
-
if (status === 0)
|
|
211
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
212
|
-
else
|
|
213
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
214
|
-
} else if (exec === "pui") {
|
|
215
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
216
|
-
`);
|
|
217
|
-
const { status } = await index.useNodeWorker(
|
|
218
|
-
url,
|
|
219
|
-
`cargo uninstall ${params}`
|
|
220
|
-
);
|
|
221
|
-
if (status === 0)
|
|
222
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
223
|
-
else
|
|
224
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
225
|
-
} else if (exec === "prun") {
|
|
226
|
-
index.jsShell(`cargo run ${params}`);
|
|
227
|
-
} else if (exec === "pinit") {
|
|
228
|
-
index.jsShell(`cargo init ${params}`);
|
|
229
|
-
} else if (exec === "pbuild") {
|
|
230
|
-
index.jsShell(`cargo build ${params}`);
|
|
231
|
-
} else {
|
|
232
|
-
console.log("The commands is not supported");
|
|
233
|
-
}
|
|
234
|
-
process__default.exit();
|
|
235
|
-
}
|
|
236
|
-
if (!runMap[exec]) {
|
|
237
|
-
console.log(
|
|
238
|
-
"The command does not exist, please execute pi -h to view the help"
|
|
239
|
-
);
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
244
|
-
await installDeps();
|
|
245
|
-
runMap[exec](params, pkg);
|
|
246
|
-
}
|
|
247
|
-
runner();
|
|
248
|
-
|
|
249
|
-
exports.pfind = pfind;
|
|
250
|
-
exports.pi = pi;
|
|
251
|
-
exports.pinit = pinit;
|
|
252
|
-
exports.prun = prun;
|
|
253
|
-
exports.pui = pui;
|
|
254
|
-
exports.runner = runner;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var b=require("path"),x=require("process"),e=require("lazy-js-utils"),I=require("ora"),N=require("fast-glob");function d(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var f=d(b),o=d(x),k=d(I),P=d(N),D="0.0.18";const g=o.default.cwd();async function p(t,s,n="ni"){const u=s?`Installing ${s} ...
|
|
2
|
+
`:`Updating dependency ...
|
|
3
|
+
`,l=s?`Installed ${s} successfully! \u{1F60A}`:"Updated dependency successfully! \u{1F60A}",c=s?`Failed to install ${s} \u{1F62D}`:"Failed to update dependency! \u{1F62D}",a=await r(u),{status:i}=await e.useNodeWorker(`${n} ${t}`);i===0?a.succeed(l):a.fail(c),o.default.exit()}async function h(t,s){const n=`Uninstalling ${s} ...
|
|
4
|
+
`,u=`
|
|
5
|
+
UnInstalled ${s} successfully! \u{1F60A}`,l=`
|
|
6
|
+
Failed to uninstall ${s} \u{1F62D}`;s||(console.log("Need to specify an uninstall package name"),o.default.exit(1));const c=await r(n),{status:a}=await e.useNodeWorker(`nun ${t}`);a===0?c.succeed(u):c.fail(l),o.default.exit()}function m(t){return e.jsShell(`ccommand ${t}`)}function $(t){return e.jsShell(`ccommand find ${t}`)}function j(){switch(console.log("Initializing project..."),e.getPkgTool()){case"npm":e.jsShell("npm init -y");return;case"yarn":e.jsShell("yarn init -y");return;case"pnpm":e.jsShell("pnpm init -y");return;default:e.jsShell("npm init -y")}}function y(t,s){const n=e.spaceFormat(t,"@latest ");return p(n,s?e.spaceFormat(`${s} `,"@latest ").trim():"")}function S(){return e.jsShell("nu")}function w(t,s){return p(t,s,"nci")}function v(){return e.jsShell("na")}async function U(){const{result:t="yellow"}=await e.jsShell("echo $PI_COLOR","pipe"),s=t,{result:n="star"}=await e.jsShell("echo $PI_SPINNER","pipe");return{color:s,spinner:n}}async function W(){const{status:t}=e.jsShell("gum -v","pipe");t===1&&await e.jsShell("brew install gum","pipe");const{status:s}=e.jsShell("ni -v","pipe");s===1&&await e.jsShell("npm i -g @antfu/ni","pipe");const{status:n}=e.jsShell("ccommand -v","pipe");n===1&&await e.jsShell("npm i -g ccommand","pipe")}function A(t){const s=t[0];s==="-v"||s==="--version"?(e.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${D}' 'Please give me a \u{1F31F} for my efforts'`),o.default.exit(0)):(s==="-h"||s==="--help")&&(e.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' '~ pi: install package' '~ pui: uninstall package' '~ prun: run package script' '~ pinit: package init' '~ pbuild: go build | cargo build' '~ pfind: find monorepo of yarn or pnpm' '~ pa: agent alias' '~ pu: package upgrade' '~ pci: package clean install' '~ pil: package latest install'`),o.default.exit(0))}const F={pi:p,pa:v,pui:h,pu:S,pil:y,pci:w,prun:m,pinit:j,pfind:$};function M(){const t=f.default.resolve(g,"go.mod"),{result:s}=e.jsShell(`(test -f "main.go" || test -f "${t}") && echo "0"|| echo "1"`,"pipe");return s==="0"}function q(){const t=f.default.resolve(g,"Cargo.toml"),{result:s}=e.jsShell(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return s==="0"}async function r(t){const{color:s,spinner:n}=await U();return k.default({text:t,spinner:n,color:s}).start()}function C(){const t=f.default.resolve(g,"package.json"),{result:s}=e.jsShell(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return s==="0"}async function _(){const t=o.default.argv[1],s=t.lastIndexOf("/")+1,n=t.slice(s,t.length),u=o.default.argv.slice(2);A(u);const l=e.spaceFormat(u.join(" ")).trim();if(!C()){if(M()){if(n==="pi"){const a=await r(`Installing ${l} ...
|
|
7
|
+
`),{status:i}=await e.useNodeWorker(`go get ${l}`);i===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(n==="pui"){const a=await r(`Uninstalling ${l} ...
|
|
8
|
+
`),{status:i}=await e.useNodeWorker(`go clean ${l}`);i===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else if(n==="prun"){const a=l?l.endsWith(".go")?[`**/${l}`]:[`**/${l}.go`,`**/${l}/main.go`]:"main.go",i=(await P.default(a))[0];i||(console.log("No such file"),o.default.exit(1)),e.jsShell(`go run ${i}`)}else n==="pinit"?e.jsShell(`go mod init ${l}`):n==="pbuild"?e.jsShell(`go build ${l}`):console.log("The commands is not supported");o.default.exit()}if(q()){if(n==="pi"){const a=await r(`Installing ${l} ...
|
|
9
|
+
`),{status:i}=await e.useNodeWorker(`cargo install ${l}`);i===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(n==="pui"){const a=await r(`Uninstalling ${l} ...
|
|
10
|
+
`),{status:i}=await e.useNodeWorker(`cargo uninstall ${l}`);i===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else n==="prun"?e.jsShell(`cargo run ${l}`):n==="pinit"?e.jsShell(`cargo init ${l}`):n==="pbuild"?e.jsShell(`cargo build ${l}`):console.log("The commands is not supported");o.default.exit()}if(!F[n]){console.log("The command does not exist, please execute pi -h to view the help");return}}const c=u.filter(a=>!a.startsWith("-")).join(" ");await W(),F[n](l,c)}_(),exports.pa=v,exports.pci=w,exports.pfind=$,exports.pi=p,exports.pil=y,exports.pinit=j,exports.prun=m,exports.pu=S,exports.pui=h,exports.runner=_;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import * as lazy_js_utils from 'lazy-js-utils';
|
|
2
|
+
|
|
3
|
+
declare function pi(params: string, pkg: string, executor?: string): Promise<void>;
|
|
2
4
|
declare function pui(params: string[], pkg: string): Promise<void>;
|
|
3
|
-
declare function prun(params: string):
|
|
4
|
-
declare function pfind(params: string):
|
|
5
|
+
declare function prun(params: string): lazy_js_utils.IShellMessage;
|
|
6
|
+
declare function pfind(params: string): lazy_js_utils.IShellMessage;
|
|
5
7
|
declare function pinit(): void;
|
|
8
|
+
declare function pil(params: string, pkg: string): Promise<void>;
|
|
9
|
+
declare function pu(): lazy_js_utils.IShellMessage;
|
|
10
|
+
declare function pci(params: string, pkg: string): Promise<void>;
|
|
11
|
+
declare function pa(): lazy_js_utils.IShellMessage;
|
|
6
12
|
declare function runner(): Promise<void>;
|
|
7
13
|
|
|
8
|
-
export { pfind, pi, pinit, prun, pui, runner };
|
|
14
|
+
export { pa, pci, pfind, pi, pil, pinit, prun, pu, pui, runner };
|
package/dist/index.mjs
CHANGED
|
@@ -1,238 +1,10 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import 'stream';
|
|
12
|
-
import 'zlib';
|
|
13
|
-
import 'assert';
|
|
14
|
-
import 'buffer';
|
|
15
|
-
|
|
16
|
-
const version = "0.0.16";
|
|
17
|
-
|
|
18
|
-
const rootPath = process.cwd();
|
|
19
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
-
const __dirname = path.dirname(__filename);
|
|
21
|
-
const url = path.resolve(__dirname, "./seprateThread.mjs");
|
|
22
|
-
async function pi(params, pkg) {
|
|
23
|
-
const text = pkg ? `Installing ${pkg} ...
|
|
24
|
-
` : "Updating dependency ...\n";
|
|
25
|
-
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
|
|
26
|
-
const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
|
|
27
|
-
const loading_status = await loading(text);
|
|
28
|
-
const { status } = await useNodeWorker(url, `ni ${params}`);
|
|
29
|
-
if (status === 0)
|
|
30
|
-
loading_status.succeed(successMsg);
|
|
31
|
-
else
|
|
32
|
-
loading_status.fail(failMsg);
|
|
33
|
-
process.exit();
|
|
34
|
-
}
|
|
35
|
-
async function pui(params, pkg) {
|
|
36
|
-
const text = `Uninstalling ${pkg} ...
|
|
37
|
-
`;
|
|
38
|
-
const successMsg = `
|
|
39
|
-
UnInstalled ${pkg} successfully! \u{1F60A}`;
|
|
40
|
-
const failMsg = `
|
|
41
|
-
Failed to uninstall ${pkg} \u{1F62D}`;
|
|
42
|
-
if (!pkg) {
|
|
43
|
-
console.log("Need to specify an uninstall package name");
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
const loading_status = await loading(text);
|
|
47
|
-
const { status } = await useNodeWorker(url, `nun ${params}`);
|
|
48
|
-
if (status === 0)
|
|
49
|
-
loading_status.succeed(successMsg);
|
|
50
|
-
else
|
|
51
|
-
loading_status.fail(failMsg);
|
|
52
|
-
process.exit();
|
|
53
|
-
}
|
|
54
|
-
function prun(params) {
|
|
55
|
-
jsShell(`ccommand ${params}`);
|
|
56
|
-
}
|
|
57
|
-
function pfind(params) {
|
|
58
|
-
jsShell(`ccommand find ${params}`);
|
|
59
|
-
}
|
|
60
|
-
function pinit() {
|
|
61
|
-
console.log("Initializing project...");
|
|
62
|
-
switch (getPkgTool()) {
|
|
63
|
-
case "npm":
|
|
64
|
-
jsShell("npm init -y");
|
|
65
|
-
return;
|
|
66
|
-
case "yarn":
|
|
67
|
-
jsShell("yarn init -y");
|
|
68
|
-
return;
|
|
69
|
-
case "pnpm":
|
|
70
|
-
jsShell("pnpm init -y");
|
|
71
|
-
return;
|
|
72
|
-
default:
|
|
73
|
-
jsShell("npm init -y");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async function getStyle() {
|
|
77
|
-
const { result: _color = "yellow" } = await jsShell("echo $PI_COLOR", "pipe");
|
|
78
|
-
const color = _color;
|
|
79
|
-
const { result: _spinner = "star" } = await jsShell(
|
|
80
|
-
"echo $PI_SPINNER",
|
|
81
|
-
"pipe"
|
|
82
|
-
);
|
|
83
|
-
const spinner = _spinner;
|
|
84
|
-
return { color, spinner };
|
|
85
|
-
}
|
|
86
|
-
async function installDeps() {
|
|
87
|
-
const { status: hasGum } = jsShell("gum -v", "pipe");
|
|
88
|
-
if (hasGum === 1)
|
|
89
|
-
await jsShell("brew install gum", "pipe");
|
|
90
|
-
const { status: hasNi } = jsShell("ni -v", "pipe");
|
|
91
|
-
if (hasNi === 1)
|
|
92
|
-
await jsShell("npm i -g @antfu/ni", "pipe");
|
|
93
|
-
const { status: hasCcommand } = jsShell("ccommand -v", "pipe");
|
|
94
|
-
if (hasCcommand === 1)
|
|
95
|
-
await jsShell("npm i -g ccommand", "pipe");
|
|
96
|
-
}
|
|
97
|
-
function returnVersion(argv) {
|
|
98
|
-
const arg = argv[0];
|
|
99
|
-
if (arg === "-v" || arg === "--version") {
|
|
100
|
-
jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${version}' 'Please give me a \u{1F31F} for my efforts'`);
|
|
101
|
-
process.exit(0);
|
|
102
|
-
} else if (arg === "-h" || arg === "--help") {
|
|
103
|
-
jsShell(
|
|
104
|
-
`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' 'pinit: package init' 'pbuild: go build | cargo build' 'pfind: find monorepo of yarn or pnpm'`
|
|
105
|
-
);
|
|
106
|
-
process.exit(0);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const runMap = {
|
|
110
|
-
pi,
|
|
111
|
-
pui,
|
|
112
|
-
prun,
|
|
113
|
-
pinit,
|
|
114
|
-
pfind
|
|
115
|
-
};
|
|
116
|
-
function isGo() {
|
|
117
|
-
const url2 = path.resolve(rootPath, "go.mod");
|
|
118
|
-
const { result } = jsShell(
|
|
119
|
-
`(test -f "main.go" || test -f "${url2}") && echo "0"|| echo "1"`,
|
|
120
|
-
"pipe"
|
|
121
|
-
);
|
|
122
|
-
return result === "0";
|
|
123
|
-
}
|
|
124
|
-
function isRust() {
|
|
125
|
-
const url2 = path.resolve(rootPath, "Cargo.toml");
|
|
126
|
-
const { result } = jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
127
|
-
return result === "0";
|
|
128
|
-
}
|
|
129
|
-
async function loading(text) {
|
|
130
|
-
const { color, spinner } = await getStyle();
|
|
131
|
-
const result = ora({
|
|
132
|
-
text,
|
|
133
|
-
spinner,
|
|
134
|
-
color
|
|
135
|
-
}).start();
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
function hasPkg() {
|
|
139
|
-
const url2 = path.resolve(rootPath, "package.json");
|
|
140
|
-
const { result } = jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
141
|
-
return result === "0";
|
|
142
|
-
}
|
|
143
|
-
async function runner() {
|
|
144
|
-
const cmd = process.argv[1];
|
|
145
|
-
const last = cmd.lastIndexOf("/") + 1;
|
|
146
|
-
const exec = cmd.slice(last, cmd.length);
|
|
147
|
-
const argv = process.argv.slice(2);
|
|
148
|
-
returnVersion(argv);
|
|
149
|
-
const params = argv.join(" ").trim();
|
|
150
|
-
if (!hasPkg()) {
|
|
151
|
-
if (isGo()) {
|
|
152
|
-
if (exec === "pi") {
|
|
153
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
154
|
-
`);
|
|
155
|
-
const { status } = await useNodeWorker(
|
|
156
|
-
url,
|
|
157
|
-
`go get ${params}`
|
|
158
|
-
);
|
|
159
|
-
if (status === 0)
|
|
160
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
161
|
-
else
|
|
162
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
163
|
-
} else if (exec === "pui") {
|
|
164
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
165
|
-
`);
|
|
166
|
-
const { status } = await useNodeWorker(
|
|
167
|
-
url,
|
|
168
|
-
`go clean ${params}`
|
|
169
|
-
);
|
|
170
|
-
if (status === 0)
|
|
171
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
172
|
-
else
|
|
173
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
174
|
-
} else if (exec === "prun") {
|
|
175
|
-
const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
|
|
176
|
-
const target = (await fg(match))[0];
|
|
177
|
-
if (!target) {
|
|
178
|
-
console.log("No such file");
|
|
179
|
-
process.exit(1);
|
|
180
|
-
}
|
|
181
|
-
jsShell(`go run ${target}`);
|
|
182
|
-
} else if (exec === "pinit") {
|
|
183
|
-
jsShell(`go mod init ${params}`);
|
|
184
|
-
} else if (exec === "pbuild") {
|
|
185
|
-
jsShell(`go build ${params}`);
|
|
186
|
-
} else {
|
|
187
|
-
console.log("The commands is not supported");
|
|
188
|
-
}
|
|
189
|
-
process.exit();
|
|
190
|
-
}
|
|
191
|
-
if (isRust()) {
|
|
192
|
-
if (exec === "pi") {
|
|
193
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
194
|
-
`);
|
|
195
|
-
const { status } = await useNodeWorker(
|
|
196
|
-
url,
|
|
197
|
-
`cargo install ${params}`
|
|
198
|
-
);
|
|
199
|
-
if (status === 0)
|
|
200
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
201
|
-
else
|
|
202
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
203
|
-
} else if (exec === "pui") {
|
|
204
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
205
|
-
`);
|
|
206
|
-
const { status } = await useNodeWorker(
|
|
207
|
-
url,
|
|
208
|
-
`cargo uninstall ${params}`
|
|
209
|
-
);
|
|
210
|
-
if (status === 0)
|
|
211
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
212
|
-
else
|
|
213
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
214
|
-
} else if (exec === "prun") {
|
|
215
|
-
jsShell(`cargo run ${params}`);
|
|
216
|
-
} else if (exec === "pinit") {
|
|
217
|
-
jsShell(`cargo init ${params}`);
|
|
218
|
-
} else if (exec === "pbuild") {
|
|
219
|
-
jsShell(`cargo build ${params}`);
|
|
220
|
-
} else {
|
|
221
|
-
console.log("The commands is not supported");
|
|
222
|
-
}
|
|
223
|
-
process.exit();
|
|
224
|
-
}
|
|
225
|
-
if (!runMap[exec]) {
|
|
226
|
-
console.log(
|
|
227
|
-
"The command does not exist, please execute pi -h to view the help"
|
|
228
|
-
);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
233
|
-
await installDeps();
|
|
234
|
-
runMap[exec](params, pkg);
|
|
235
|
-
}
|
|
236
|
-
runner();
|
|
237
|
-
|
|
238
|
-
export { pfind, pi, pinit, prun, pui, runner };
|
|
1
|
+
import d from"path";import l from"process";import{useNodeWorker as r,jsShell as e,getPkgTool as P,spaceFormat as g}from"lazy-js-utils";import D from"ora";import U from"fast-glob";var A="0.0.18";const m=l.cwd();async function f(n,t,s="ni"){const c=t?`Installing ${t} ...
|
|
2
|
+
`:`Updating dependency ...
|
|
3
|
+
`,i=t?`Installed ${t} successfully! \u{1F60A}`:"Updated dependency successfully! \u{1F60A}",u=t?`Failed to install ${t} \u{1F62D}`:"Failed to update dependency! \u{1F62D}",a=await p(c),{status:o}=await r(`${s} ${n}`);o===0?a.succeed(i):a.fail(u),l.exit()}async function $(n,t){const s=`Uninstalling ${t} ...
|
|
4
|
+
`,c=`
|
|
5
|
+
UnInstalled ${t} successfully! \u{1F60A}`,i=`
|
|
6
|
+
Failed to uninstall ${t} \u{1F62D}`;t||(console.log("Need to specify an uninstall package name"),l.exit(1));const u=await p(s),{status:a}=await r(`nun ${n}`);a===0?u.succeed(c):u.fail(i),l.exit()}function h(n){return e(`ccommand ${n}`)}function y(n){return e(`ccommand find ${n}`)}function w(){switch(console.log("Initializing project..."),P()){case"npm":e("npm init -y");return;case"yarn":e("yarn init -y");return;case"pnpm":e("pnpm init -y");return;default:e("npm init -y")}}function F(n,t){const s=g(n,"@latest ");return f(s,t?g(`${t} `,"@latest ").trim():"")}function v(){return e("nu")}function x(n,t){return f(n,t,"nci")}function b(){return e("na")}async function N(){const{result:n="yellow"}=await e("echo $PI_COLOR","pipe"),t=n,{result:s="star"}=await e("echo $PI_SPINNER","pipe");return{color:t,spinner:s}}async function j(){const{status:n}=e("gum -v","pipe");n===1&&await e("brew install gum","pipe");const{status:t}=e("ni -v","pipe");t===1&&await e("npm i -g @antfu/ni","pipe");const{status:s}=e("ccommand -v","pipe");s===1&&await e("npm i -g ccommand","pipe")}function k(n){const t=n[0];t==="-v"||t==="--version"?(e(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${A}' 'Please give me a \u{1F31F} for my efforts'`),l.exit(0)):(t==="-h"||t==="--help")&&(e(`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' '~ pi: install package' '~ pui: uninstall package' '~ prun: run package script' '~ pinit: package init' '~ pbuild: go build | cargo build' '~ pfind: find monorepo of yarn or pnpm' '~ pa: agent alias' '~ pu: package upgrade' '~ pci: package clean install' '~ pil: package latest install'`),l.exit(0))}const I={pi:f,pa:b,pui:$,pu:v,pil:F,pci:x,prun:h,pinit:w,pfind:y};function M(){const n=d.resolve(m,"go.mod"),{result:t}=e(`(test -f "main.go" || test -f "${n}") && echo "0"|| echo "1"`,"pipe");return t==="0"}function C(){const n=d.resolve(m,"Cargo.toml"),{result:t}=e(`test -f "${n}" && echo "0"|| echo "1"`,"pipe");return t==="0"}async function p(n){const{color:t,spinner:s}=await N();return D({text:n,spinner:s,color:t}).start()}function T(){const n=d.resolve(m,"package.json"),{result:t}=e(`test -f "${n}" && echo "0"|| echo "1"`,"pipe");return t==="0"}async function _(){const n=l.argv[1],t=n.lastIndexOf("/")+1,s=n.slice(t,n.length),c=l.argv.slice(2);k(c);const i=g(c.join(" ")).trim();if(!T()){if(M()){if(s==="pi"){const a=await p(`Installing ${i} ...
|
|
7
|
+
`),{status:o}=await r(`go get ${i}`);o===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(s==="pui"){const a=await p(`Uninstalling ${i} ...
|
|
8
|
+
`),{status:o}=await r(`go clean ${i}`);o===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else if(s==="prun"){const a=i?i.endsWith(".go")?[`**/${i}`]:[`**/${i}.go`,`**/${i}/main.go`]:"main.go",o=(await U(a))[0];o||(console.log("No such file"),l.exit(1)),e(`go run ${o}`)}else s==="pinit"?e(`go mod init ${i}`):s==="pbuild"?e(`go build ${i}`):console.log("The commands is not supported");l.exit()}if(C()){if(s==="pi"){const a=await p(`Installing ${i} ...
|
|
9
|
+
`),{status:o}=await r(`cargo install ${i}`);o===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(s==="pui"){const a=await p(`Uninstalling ${i} ...
|
|
10
|
+
`),{status:o}=await r(`cargo uninstall ${i}`);o===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else s==="prun"?e(`cargo run ${i}`):s==="pinit"?e(`cargo init ${i}`):s==="pbuild"?e(`cargo build ${i}`):console.log("The commands is not supported");l.exit()}if(!I[s]){console.log("The command does not exist, please execute pi -h to view the help");return}}const u=c.filter(a=>!a.startsWith("-")).join(" ");await j(),I[s](i,u)}_();export{b as pa,x as pci,y as pfind,f as pi,F as pil,w as pinit,h as prun,v as pu,$ as pui,_ as 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.18",
|
|
5
5
|
"packageManager": "pnpm@7.2.1",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "Simon He",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"import": "./dist/index.mjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
-
"main": "./dist/index.
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
26
|
"module": "./dist/index.mjs",
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"typesVersions": {
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"bin": {
|
|
37
37
|
"pi": "./cli.mjs",
|
|
38
|
+
"pa": "./cli.mjs",
|
|
39
|
+
"pu": "./cli.mjs",
|
|
40
|
+
"pci": "./cli.mjs",
|
|
41
|
+
"pil": "./cli.mjs",
|
|
38
42
|
"pui": "./cli.mjs",
|
|
39
43
|
"prun": "./cli.mjs",
|
|
40
44
|
"pinit": "./cli.mjs",
|
|
@@ -46,8 +50,8 @@
|
|
|
46
50
|
],
|
|
47
51
|
"scripts": {
|
|
48
52
|
"postinstall": "simple-git-hooks",
|
|
49
|
-
"build": "
|
|
50
|
-
"dev": "
|
|
53
|
+
"build": "pkgroll --minify",
|
|
54
|
+
"dev": "pkgroll --watch",
|
|
51
55
|
"format": "prettier --write --cache .",
|
|
52
56
|
"lint": "eslint .",
|
|
53
57
|
"lint:fix": "eslint . --fix",
|
|
@@ -59,26 +63,28 @@
|
|
|
59
63
|
},
|
|
60
64
|
"dependencies": {
|
|
61
65
|
"fast-glob": "^3.2.12",
|
|
66
|
+
"lazy-js-utils": "^0.0.8",
|
|
62
67
|
"ora": "^6.1.2"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
65
70
|
"@antfu/eslint-config": "^0.25.2",
|
|
66
71
|
"@antfu/ni": "^0.16.3",
|
|
67
72
|
"@antfu/utils": "^0.5.2",
|
|
68
|
-
"@types/node": "^18.11.
|
|
73
|
+
"@types/node": "^18.11.15",
|
|
69
74
|
"bumpp": "^8.2.1",
|
|
70
|
-
"eslint": "^8.
|
|
75
|
+
"eslint": "^8.29.0",
|
|
71
76
|
"esno": "^0.16.3",
|
|
72
77
|
"lint-staged": "^13.1.0",
|
|
73
78
|
"picocolors": "^1.0.0",
|
|
74
|
-
"
|
|
79
|
+
"pkgroll": "^1.8.0",
|
|
80
|
+
"pnpm": "^7.18.2",
|
|
75
81
|
"prettier": "^2.8.1",
|
|
76
82
|
"rimraf": "^3.0.2",
|
|
77
83
|
"simple-git-hooks": "^2.8.1",
|
|
78
84
|
"tsx": "^3.12.1",
|
|
79
|
-
"typescript": "^4.9.
|
|
85
|
+
"typescript": "^4.9.4",
|
|
80
86
|
"unbuild": "^0.7.6",
|
|
81
|
-
"vitest": "^0.25.
|
|
87
|
+
"vitest": "^0.25.8"
|
|
82
88
|
},
|
|
83
89
|
"simple-git-hooks": {
|
|
84
90
|
"pre-commit": "pnpm exec lint-staged --concurrent false",
|