@simon_he/pi 0.0.17 → 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 +15 -1
- package/dist/index.cjs +10 -270
- package/dist/index.mjs +10 -250
- package/package.json +6 -5
- package/dist/seprateThread.cjs +0 -5
- package/dist/seprateThread.d.ts +0 -1
- package/dist/seprateThread.mjs +0 -3
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>
|
|
@@ -18,9 +18,19 @@ A smart package manager with a custom loading style, which makes you install dep
|
|
|
18
18
|
## Demo
|
|
19
19
|
|
|
20
20
|
- pi
|
|
21
|
+

|
|
22
|
+
|
|
21
23
|

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

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

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

|
|
33
|
+
|
|
24
34
|

|
|
25
35
|
|
|
26
36
|
- pfind
|
|
@@ -45,10 +55,14 @@ A smart package manager with a custom loading style, which makes you install dep
|
|
|
45
55
|
pui xxx
|
|
46
56
|
# Execute command
|
|
47
57
|
prun
|
|
58
|
+
# Execute scripts in workspace
|
|
59
|
+
pfind
|
|
48
60
|
# Initialization
|
|
49
61
|
pinit
|
|
50
62
|
# build - for cargo, go
|
|
51
63
|
pbuild
|
|
64
|
+
# pci
|
|
65
|
+
|
|
52
66
|
```
|
|
53
67
|
|
|
54
68
|
## Power
|
package/dist/index.cjs
CHANGED
|
@@ -1,270 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
13
|
-
|
|
14
|
-
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
15
|
-
const process__default = /*#__PURE__*/_interopDefaultLegacy(process);
|
|
16
|
-
const ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
|
|
17
|
-
const fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
|
|
18
|
-
|
|
19
|
-
const version = "0.0.17";
|
|
20
|
-
|
|
21
|
-
const rootPath = process__default.cwd();
|
|
22
|
-
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)));
|
|
23
|
-
const __dirname$1 = path__default.dirname(__filename$1);
|
|
24
|
-
const url = path__default.resolve(__dirname$1, "./seprateThread.mjs");
|
|
25
|
-
async function pi(params, pkg, executor = "ni") {
|
|
26
|
-
const text = pkg ? `Installing ${pkg} ...
|
|
27
|
-
` : "Updating dependency ...\n";
|
|
28
|
-
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
|
|
29
|
-
const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
|
|
30
|
-
const loading_status = await loading(text);
|
|
31
|
-
const { status } = await lazyJsUtils.useNodeWorker(
|
|
32
|
-
url,
|
|
33
|
-
`${executor} ${params}`
|
|
34
|
-
);
|
|
35
|
-
if (status === 0)
|
|
36
|
-
loading_status.succeed(successMsg);
|
|
37
|
-
else
|
|
38
|
-
loading_status.fail(failMsg);
|
|
39
|
-
process__default.exit();
|
|
40
|
-
}
|
|
41
|
-
async function pui(params, pkg) {
|
|
42
|
-
const text = `Uninstalling ${pkg} ...
|
|
43
|
-
`;
|
|
44
|
-
const successMsg = `
|
|
45
|
-
UnInstalled ${pkg} successfully! \u{1F60A}`;
|
|
46
|
-
const failMsg = `
|
|
47
|
-
Failed to uninstall ${pkg} \u{1F62D}`;
|
|
48
|
-
if (!pkg) {
|
|
49
|
-
console.log("Need to specify an uninstall package name");
|
|
50
|
-
process__default.exit(1);
|
|
51
|
-
}
|
|
52
|
-
const loading_status = await loading(text);
|
|
53
|
-
const { status } = await lazyJsUtils.useNodeWorker(url, `nun ${params}`);
|
|
54
|
-
if (status === 0)
|
|
55
|
-
loading_status.succeed(successMsg);
|
|
56
|
-
else
|
|
57
|
-
loading_status.fail(failMsg);
|
|
58
|
-
process__default.exit();
|
|
59
|
-
}
|
|
60
|
-
function prun(params) {
|
|
61
|
-
return lazyJsUtils.jsShell(`ccommand ${params}`);
|
|
62
|
-
}
|
|
63
|
-
function pfind(params) {
|
|
64
|
-
return lazyJsUtils.jsShell(`ccommand find ${params}`);
|
|
65
|
-
}
|
|
66
|
-
function pinit() {
|
|
67
|
-
console.log("Initializing project...");
|
|
68
|
-
switch (lazyJsUtils.getPkgTool()) {
|
|
69
|
-
case "npm":
|
|
70
|
-
lazyJsUtils.jsShell("npm init -y");
|
|
71
|
-
return;
|
|
72
|
-
case "yarn":
|
|
73
|
-
lazyJsUtils.jsShell("yarn init -y");
|
|
74
|
-
return;
|
|
75
|
-
case "pnpm":
|
|
76
|
-
lazyJsUtils.jsShell("pnpm init -y");
|
|
77
|
-
return;
|
|
78
|
-
default:
|
|
79
|
-
lazyJsUtils.jsShell("npm init -y");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function pil(params, pkg) {
|
|
83
|
-
const latestPkgname = lazyJsUtils.spaceFormat(params, "@latest ");
|
|
84
|
-
return pi(latestPkgname, pkg ? lazyJsUtils.spaceFormat(`${pkg} `, "@latest ").trim() : "");
|
|
85
|
-
}
|
|
86
|
-
function pu() {
|
|
87
|
-
return lazyJsUtils.jsShell("nu");
|
|
88
|
-
}
|
|
89
|
-
function pci(params, pkg) {
|
|
90
|
-
return pi(params, pkg, "nci");
|
|
91
|
-
}
|
|
92
|
-
function pa() {
|
|
93
|
-
return lazyJsUtils.jsShell("na");
|
|
94
|
-
}
|
|
95
|
-
async function getStyle() {
|
|
96
|
-
const { result: _color = "yellow" } = await lazyJsUtils.jsShell("echo $PI_COLOR", "pipe");
|
|
97
|
-
const color = _color;
|
|
98
|
-
const { result: _spinner = "star" } = await lazyJsUtils.jsShell(
|
|
99
|
-
"echo $PI_SPINNER",
|
|
100
|
-
"pipe"
|
|
101
|
-
);
|
|
102
|
-
const spinner = _spinner;
|
|
103
|
-
return { color, spinner };
|
|
104
|
-
}
|
|
105
|
-
async function installDeps() {
|
|
106
|
-
const { status: hasGum } = lazyJsUtils.jsShell("gum -v", "pipe");
|
|
107
|
-
if (hasGum === 1)
|
|
108
|
-
await lazyJsUtils.jsShell("brew install gum", "pipe");
|
|
109
|
-
const { status: hasNi } = lazyJsUtils.jsShell("ni -v", "pipe");
|
|
110
|
-
if (hasNi === 1)
|
|
111
|
-
await lazyJsUtils.jsShell("npm i -g @antfu/ni", "pipe");
|
|
112
|
-
const { status: hasCcommand } = lazyJsUtils.jsShell("ccommand -v", "pipe");
|
|
113
|
-
if (hasCcommand === 1)
|
|
114
|
-
await lazyJsUtils.jsShell("npm i -g ccommand", "pipe");
|
|
115
|
-
}
|
|
116
|
-
function returnVersion(argv) {
|
|
117
|
-
const arg = argv[0];
|
|
118
|
-
if (arg === "-v" || arg === "--version") {
|
|
119
|
-
lazyJsUtils.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'`);
|
|
120
|
-
process__default.exit(0);
|
|
121
|
-
} else if (arg === "-h" || arg === "--help") {
|
|
122
|
-
lazyJsUtils.jsShell(
|
|
123
|
-
`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'`
|
|
124
|
-
);
|
|
125
|
-
process__default.exit(0);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const runMap = {
|
|
129
|
-
pi,
|
|
130
|
-
pa,
|
|
131
|
-
pui,
|
|
132
|
-
pu,
|
|
133
|
-
pil,
|
|
134
|
-
pci,
|
|
135
|
-
prun,
|
|
136
|
-
pinit,
|
|
137
|
-
pfind
|
|
138
|
-
};
|
|
139
|
-
function isGo() {
|
|
140
|
-
const url2 = path__default.resolve(rootPath, "go.mod");
|
|
141
|
-
const { result } = lazyJsUtils.jsShell(
|
|
142
|
-
`(test -f "main.go" || test -f "${url2}") && echo "0"|| echo "1"`,
|
|
143
|
-
"pipe"
|
|
144
|
-
);
|
|
145
|
-
return result === "0";
|
|
146
|
-
}
|
|
147
|
-
function isRust() {
|
|
148
|
-
const url2 = path__default.resolve(rootPath, "Cargo.toml");
|
|
149
|
-
const { result } = lazyJsUtils.jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
150
|
-
return result === "0";
|
|
151
|
-
}
|
|
152
|
-
async function loading(text) {
|
|
153
|
-
const { color, spinner } = await getStyle();
|
|
154
|
-
const result = ora__default({
|
|
155
|
-
text,
|
|
156
|
-
spinner,
|
|
157
|
-
color
|
|
158
|
-
}).start();
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
function hasPkg() {
|
|
162
|
-
const url2 = path__default.resolve(rootPath, "package.json");
|
|
163
|
-
const { result } = lazyJsUtils.jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
164
|
-
return result === "0";
|
|
165
|
-
}
|
|
166
|
-
async function runner() {
|
|
167
|
-
const cmd = process__default.argv[1];
|
|
168
|
-
const last = cmd.lastIndexOf("/") + 1;
|
|
169
|
-
const exec = cmd.slice(last, cmd.length);
|
|
170
|
-
const argv = process__default.argv.slice(2);
|
|
171
|
-
returnVersion(argv);
|
|
172
|
-
const params = lazyJsUtils.spaceFormat(argv.join(" ")).trim();
|
|
173
|
-
if (!hasPkg()) {
|
|
174
|
-
if (isGo()) {
|
|
175
|
-
if (exec === "pi") {
|
|
176
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
177
|
-
`);
|
|
178
|
-
const { status } = await lazyJsUtils.useNodeWorker(
|
|
179
|
-
url,
|
|
180
|
-
`go get ${params}`
|
|
181
|
-
);
|
|
182
|
-
if (status === 0)
|
|
183
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
184
|
-
else
|
|
185
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
186
|
-
} else if (exec === "pui") {
|
|
187
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
188
|
-
`);
|
|
189
|
-
const { status } = await lazyJsUtils.useNodeWorker(
|
|
190
|
-
url,
|
|
191
|
-
`go clean ${params}`
|
|
192
|
-
);
|
|
193
|
-
if (status === 0)
|
|
194
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
195
|
-
else
|
|
196
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
197
|
-
} else if (exec === "prun") {
|
|
198
|
-
const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
|
|
199
|
-
const target = (await fg__default(match))[0];
|
|
200
|
-
if (!target) {
|
|
201
|
-
console.log("No such file");
|
|
202
|
-
process__default.exit(1);
|
|
203
|
-
}
|
|
204
|
-
lazyJsUtils.jsShell(`go run ${target}`);
|
|
205
|
-
} else if (exec === "pinit") {
|
|
206
|
-
lazyJsUtils.jsShell(`go mod init ${params}`);
|
|
207
|
-
} else if (exec === "pbuild") {
|
|
208
|
-
lazyJsUtils.jsShell(`go build ${params}`);
|
|
209
|
-
} else {
|
|
210
|
-
console.log("The commands is not supported");
|
|
211
|
-
}
|
|
212
|
-
process__default.exit();
|
|
213
|
-
}
|
|
214
|
-
if (isRust()) {
|
|
215
|
-
if (exec === "pi") {
|
|
216
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
217
|
-
`);
|
|
218
|
-
const { status } = await lazyJsUtils.useNodeWorker(
|
|
219
|
-
url,
|
|
220
|
-
`cargo install ${params}`
|
|
221
|
-
);
|
|
222
|
-
if (status === 0)
|
|
223
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
224
|
-
else
|
|
225
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
226
|
-
} else if (exec === "pui") {
|
|
227
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
228
|
-
`);
|
|
229
|
-
const { status } = await lazyJsUtils.useNodeWorker(
|
|
230
|
-
url,
|
|
231
|
-
`cargo uninstall ${params}`
|
|
232
|
-
);
|
|
233
|
-
if (status === 0)
|
|
234
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
235
|
-
else
|
|
236
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
237
|
-
} else if (exec === "prun") {
|
|
238
|
-
lazyJsUtils.jsShell(`cargo run ${params}`);
|
|
239
|
-
} else if (exec === "pinit") {
|
|
240
|
-
lazyJsUtils.jsShell(`cargo init ${params}`);
|
|
241
|
-
} else if (exec === "pbuild") {
|
|
242
|
-
lazyJsUtils.jsShell(`cargo build ${params}`);
|
|
243
|
-
} else {
|
|
244
|
-
console.log("The commands is not supported");
|
|
245
|
-
}
|
|
246
|
-
process__default.exit();
|
|
247
|
-
}
|
|
248
|
-
if (!runMap[exec]) {
|
|
249
|
-
console.log(
|
|
250
|
-
"The command does not exist, please execute pi -h to view the help"
|
|
251
|
-
);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
256
|
-
await installDeps();
|
|
257
|
-
runMap[exec](params, pkg);
|
|
258
|
-
}
|
|
259
|
-
runner();
|
|
260
|
-
|
|
261
|
-
exports.pa = pa;
|
|
262
|
-
exports.pci = pci;
|
|
263
|
-
exports.pfind = pfind;
|
|
264
|
-
exports.pi = pi;
|
|
265
|
-
exports.pil = pil;
|
|
266
|
-
exports.pinit = pinit;
|
|
267
|
-
exports.prun = prun;
|
|
268
|
-
exports.pu = pu;
|
|
269
|
-
exports.pui = pui;
|
|
270
|
-
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.mjs
CHANGED
|
@@ -1,250 +1,10 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
-
const __dirname = path.dirname(__filename);
|
|
13
|
-
const url = path.resolve(__dirname, "./seprateThread.mjs");
|
|
14
|
-
async function pi(params, pkg, executor = "ni") {
|
|
15
|
-
const text = pkg ? `Installing ${pkg} ...
|
|
16
|
-
` : "Updating dependency ...\n";
|
|
17
|
-
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
|
|
18
|
-
const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
|
|
19
|
-
const loading_status = await loading(text);
|
|
20
|
-
const { status } = await useNodeWorker(
|
|
21
|
-
url,
|
|
22
|
-
`${executor} ${params}`
|
|
23
|
-
);
|
|
24
|
-
if (status === 0)
|
|
25
|
-
loading_status.succeed(successMsg);
|
|
26
|
-
else
|
|
27
|
-
loading_status.fail(failMsg);
|
|
28
|
-
process.exit();
|
|
29
|
-
}
|
|
30
|
-
async function pui(params, pkg) {
|
|
31
|
-
const text = `Uninstalling ${pkg} ...
|
|
32
|
-
`;
|
|
33
|
-
const successMsg = `
|
|
34
|
-
UnInstalled ${pkg} successfully! \u{1F60A}`;
|
|
35
|
-
const failMsg = `
|
|
36
|
-
Failed to uninstall ${pkg} \u{1F62D}`;
|
|
37
|
-
if (!pkg) {
|
|
38
|
-
console.log("Need to specify an uninstall package name");
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
const loading_status = await loading(text);
|
|
42
|
-
const { status } = await useNodeWorker(url, `nun ${params}`);
|
|
43
|
-
if (status === 0)
|
|
44
|
-
loading_status.succeed(successMsg);
|
|
45
|
-
else
|
|
46
|
-
loading_status.fail(failMsg);
|
|
47
|
-
process.exit();
|
|
48
|
-
}
|
|
49
|
-
function prun(params) {
|
|
50
|
-
return jsShell(`ccommand ${params}`);
|
|
51
|
-
}
|
|
52
|
-
function pfind(params) {
|
|
53
|
-
return jsShell(`ccommand find ${params}`);
|
|
54
|
-
}
|
|
55
|
-
function pinit() {
|
|
56
|
-
console.log("Initializing project...");
|
|
57
|
-
switch (getPkgTool()) {
|
|
58
|
-
case "npm":
|
|
59
|
-
jsShell("npm init -y");
|
|
60
|
-
return;
|
|
61
|
-
case "yarn":
|
|
62
|
-
jsShell("yarn init -y");
|
|
63
|
-
return;
|
|
64
|
-
case "pnpm":
|
|
65
|
-
jsShell("pnpm init -y");
|
|
66
|
-
return;
|
|
67
|
-
default:
|
|
68
|
-
jsShell("npm init -y");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function pil(params, pkg) {
|
|
72
|
-
const latestPkgname = spaceFormat(params, "@latest ");
|
|
73
|
-
return pi(latestPkgname, pkg ? spaceFormat(`${pkg} `, "@latest ").trim() : "");
|
|
74
|
-
}
|
|
75
|
-
function pu() {
|
|
76
|
-
return jsShell("nu");
|
|
77
|
-
}
|
|
78
|
-
function pci(params, pkg) {
|
|
79
|
-
return pi(params, pkg, "nci");
|
|
80
|
-
}
|
|
81
|
-
function pa() {
|
|
82
|
-
return jsShell("na");
|
|
83
|
-
}
|
|
84
|
-
async function getStyle() {
|
|
85
|
-
const { result: _color = "yellow" } = await jsShell("echo $PI_COLOR", "pipe");
|
|
86
|
-
const color = _color;
|
|
87
|
-
const { result: _spinner = "star" } = await jsShell(
|
|
88
|
-
"echo $PI_SPINNER",
|
|
89
|
-
"pipe"
|
|
90
|
-
);
|
|
91
|
-
const spinner = _spinner;
|
|
92
|
-
return { color, spinner };
|
|
93
|
-
}
|
|
94
|
-
async function installDeps() {
|
|
95
|
-
const { status: hasGum } = jsShell("gum -v", "pipe");
|
|
96
|
-
if (hasGum === 1)
|
|
97
|
-
await jsShell("brew install gum", "pipe");
|
|
98
|
-
const { status: hasNi } = jsShell("ni -v", "pipe");
|
|
99
|
-
if (hasNi === 1)
|
|
100
|
-
await jsShell("npm i -g @antfu/ni", "pipe");
|
|
101
|
-
const { status: hasCcommand } = jsShell("ccommand -v", "pipe");
|
|
102
|
-
if (hasCcommand === 1)
|
|
103
|
-
await jsShell("npm i -g ccommand", "pipe");
|
|
104
|
-
}
|
|
105
|
-
function returnVersion(argv) {
|
|
106
|
-
const arg = argv[0];
|
|
107
|
-
if (arg === "-v" || arg === "--version") {
|
|
108
|
-
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'`);
|
|
109
|
-
process.exit(0);
|
|
110
|
-
} else if (arg === "-h" || arg === "--help") {
|
|
111
|
-
jsShell(
|
|
112
|
-
`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'`
|
|
113
|
-
);
|
|
114
|
-
process.exit(0);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const runMap = {
|
|
118
|
-
pi,
|
|
119
|
-
pa,
|
|
120
|
-
pui,
|
|
121
|
-
pu,
|
|
122
|
-
pil,
|
|
123
|
-
pci,
|
|
124
|
-
prun,
|
|
125
|
-
pinit,
|
|
126
|
-
pfind
|
|
127
|
-
};
|
|
128
|
-
function isGo() {
|
|
129
|
-
const url2 = path.resolve(rootPath, "go.mod");
|
|
130
|
-
const { result } = jsShell(
|
|
131
|
-
`(test -f "main.go" || test -f "${url2}") && echo "0"|| echo "1"`,
|
|
132
|
-
"pipe"
|
|
133
|
-
);
|
|
134
|
-
return result === "0";
|
|
135
|
-
}
|
|
136
|
-
function isRust() {
|
|
137
|
-
const url2 = path.resolve(rootPath, "Cargo.toml");
|
|
138
|
-
const { result } = jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
139
|
-
return result === "0";
|
|
140
|
-
}
|
|
141
|
-
async function loading(text) {
|
|
142
|
-
const { color, spinner } = await getStyle();
|
|
143
|
-
const result = ora({
|
|
144
|
-
text,
|
|
145
|
-
spinner,
|
|
146
|
-
color
|
|
147
|
-
}).start();
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
function hasPkg() {
|
|
151
|
-
const url2 = path.resolve(rootPath, "package.json");
|
|
152
|
-
const { result } = jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
|
|
153
|
-
return result === "0";
|
|
154
|
-
}
|
|
155
|
-
async function runner() {
|
|
156
|
-
const cmd = process.argv[1];
|
|
157
|
-
const last = cmd.lastIndexOf("/") + 1;
|
|
158
|
-
const exec = cmd.slice(last, cmd.length);
|
|
159
|
-
const argv = process.argv.slice(2);
|
|
160
|
-
returnVersion(argv);
|
|
161
|
-
const params = spaceFormat(argv.join(" ")).trim();
|
|
162
|
-
if (!hasPkg()) {
|
|
163
|
-
if (isGo()) {
|
|
164
|
-
if (exec === "pi") {
|
|
165
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
166
|
-
`);
|
|
167
|
-
const { status } = await useNodeWorker(
|
|
168
|
-
url,
|
|
169
|
-
`go get ${params}`
|
|
170
|
-
);
|
|
171
|
-
if (status === 0)
|
|
172
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
173
|
-
else
|
|
174
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
175
|
-
} else if (exec === "pui") {
|
|
176
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
177
|
-
`);
|
|
178
|
-
const { status } = await useNodeWorker(
|
|
179
|
-
url,
|
|
180
|
-
`go clean ${params}`
|
|
181
|
-
);
|
|
182
|
-
if (status === 0)
|
|
183
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
184
|
-
else
|
|
185
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
186
|
-
} else if (exec === "prun") {
|
|
187
|
-
const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
|
|
188
|
-
const target = (await fg(match))[0];
|
|
189
|
-
if (!target) {
|
|
190
|
-
console.log("No such file");
|
|
191
|
-
process.exit(1);
|
|
192
|
-
}
|
|
193
|
-
jsShell(`go run ${target}`);
|
|
194
|
-
} else if (exec === "pinit") {
|
|
195
|
-
jsShell(`go mod init ${params}`);
|
|
196
|
-
} else if (exec === "pbuild") {
|
|
197
|
-
jsShell(`go build ${params}`);
|
|
198
|
-
} else {
|
|
199
|
-
console.log("The commands is not supported");
|
|
200
|
-
}
|
|
201
|
-
process.exit();
|
|
202
|
-
}
|
|
203
|
-
if (isRust()) {
|
|
204
|
-
if (exec === "pi") {
|
|
205
|
-
const loading_status = await loading(`Installing ${params} ...
|
|
206
|
-
`);
|
|
207
|
-
const { status } = await useNodeWorker(
|
|
208
|
-
url,
|
|
209
|
-
`cargo install ${params}`
|
|
210
|
-
);
|
|
211
|
-
if (status === 0)
|
|
212
|
-
loading_status.succeed("Installed successfully! \u{1F60A}");
|
|
213
|
-
else
|
|
214
|
-
loading_status.fail("Failed to install \u{1F62D}");
|
|
215
|
-
} else if (exec === "pui") {
|
|
216
|
-
const loading_status = await loading(`Uninstalling ${params} ...
|
|
217
|
-
`);
|
|
218
|
-
const { status } = await useNodeWorker(
|
|
219
|
-
url,
|
|
220
|
-
`cargo uninstall ${params}`
|
|
221
|
-
);
|
|
222
|
-
if (status === 0)
|
|
223
|
-
loading_status.succeed("Uninstalled successfully! \u{1F60A}");
|
|
224
|
-
else
|
|
225
|
-
loading_status.fail("Failed to uninstall \u{1F62D}");
|
|
226
|
-
} else if (exec === "prun") {
|
|
227
|
-
jsShell(`cargo run ${params}`);
|
|
228
|
-
} else if (exec === "pinit") {
|
|
229
|
-
jsShell(`cargo init ${params}`);
|
|
230
|
-
} else if (exec === "pbuild") {
|
|
231
|
-
jsShell(`cargo build ${params}`);
|
|
232
|
-
} else {
|
|
233
|
-
console.log("The commands is not supported");
|
|
234
|
-
}
|
|
235
|
-
process.exit();
|
|
236
|
-
}
|
|
237
|
-
if (!runMap[exec]) {
|
|
238
|
-
console.log(
|
|
239
|
-
"The command does not exist, please execute pi -h to view the help"
|
|
240
|
-
);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
245
|
-
await installDeps();
|
|
246
|
-
runMap[exec](params, pkg);
|
|
247
|
-
}
|
|
248
|
-
runner();
|
|
249
|
-
|
|
250
|
-
export { pa, pci, pfind, pi, pil, pinit, prun, pu, 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": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
],
|
|
51
51
|
"scripts": {
|
|
52
52
|
"postinstall": "simple-git-hooks",
|
|
53
|
-
"build": "
|
|
54
|
-
"dev": "
|
|
53
|
+
"build": "pkgroll --minify",
|
|
54
|
+
"dev": "pkgroll --watch",
|
|
55
55
|
"format": "prettier --write --cache .",
|
|
56
56
|
"lint": "eslint .",
|
|
57
57
|
"lint:fix": "eslint . --fix",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"fast-glob": "^3.2.12",
|
|
66
|
-
"lazy-js-utils": "^0.0.
|
|
66
|
+
"lazy-js-utils": "^0.0.8",
|
|
67
67
|
"ora": "^6.1.2"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"esno": "^0.16.3",
|
|
77
77
|
"lint-staged": "^13.1.0",
|
|
78
78
|
"picocolors": "^1.0.0",
|
|
79
|
+
"pkgroll": "^1.8.0",
|
|
79
80
|
"pnpm": "^7.18.2",
|
|
80
81
|
"prettier": "^2.8.1",
|
|
81
82
|
"rimraf": "^3.0.2",
|
package/dist/seprateThread.cjs
DELETED
package/dist/seprateThread.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/seprateThread.mjs
DELETED