@simon_he/pi 0.1.19 → 0.1.21
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/dist/index.cjs +696 -704
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +729 -0
- package/package.json +14 -14
- package/dist/index.js +0 -748
package/dist/index.cjs
CHANGED
|
@@ -1,770 +1,762 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
8
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
19
21
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
setup: () => setup
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
37
|
-
var import_node_process9 = __toESM(require("process"), 1);
|
|
38
|
-
var import_ccommand3 = require("ccommand");
|
|
39
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
40
|
-
var import_lazy_js_utils2 = require("lazy-js-utils");
|
|
41
|
-
var import_node13 = require("lazy-js-utils/node");
|
|
42
|
-
var import_picocolors8 = __toESM(require("picocolors"), 1);
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path);
|
|
30
|
+
let node_process = require("node:process");
|
|
31
|
+
node_process = __toESM(node_process);
|
|
32
|
+
let fast_glob = require("fast-glob");
|
|
33
|
+
fast_glob = __toESM(fast_glob);
|
|
34
|
+
let lazy_js_utils = require("lazy-js-utils");
|
|
35
|
+
let lazy_js_utils_node = require("lazy-js-utils/node");
|
|
36
|
+
let picocolors = require("picocolors");
|
|
37
|
+
picocolors = __toESM(picocolors);
|
|
38
|
+
let node_console = require("node:console");
|
|
39
|
+
let node_fs = require("node:fs");
|
|
40
|
+
node_fs = __toESM(node_fs);
|
|
41
|
+
let node_os = require("node:os");
|
|
42
|
+
node_os = __toESM(node_os);
|
|
43
|
+
let node_module = require("node:module");
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
var version = "0.1.
|
|
45
|
+
//#region package.json
|
|
46
|
+
var version = "0.1.21";
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/installDeps.ts
|
|
50
|
+
const isZh$6 = node_process.default.env.PI_Lang === "zh";
|
|
51
|
+
const gumDocUrl = "https://github.com/charmbracelet/gum";
|
|
52
|
+
const niDocUrl = "https://github.com/antfu/ni";
|
|
53
|
+
async function installDeps(options = {}) {
|
|
54
|
+
const { gum = true, ni = true, strict = true } = options;
|
|
55
|
+
const platform = node_process.default.platform;
|
|
56
|
+
if (gum && !await (0, lazy_js_utils_node.isInstallPkg)("gum")) if (platform === "darwin") {
|
|
57
|
+
console.log(picocolors.default.cyan(isZh$6 ? "正在为您安装必要的依赖gum..." : "Installing gum..."));
|
|
58
|
+
const { status } = await (0, lazy_js_utils_node.jsShell)("brew install gum", [
|
|
59
|
+
"inherit",
|
|
60
|
+
"pipe",
|
|
61
|
+
"inherit"
|
|
62
|
+
]);
|
|
63
|
+
if (status === 0) console.log(picocolors.default.cyan(isZh$6 ? "gum 安装成功!" : "gum installed successfully!"));
|
|
64
|
+
else {
|
|
65
|
+
console.log(picocolors.default.red(isZh$6 ? `gum 安装失败,请尝试从官网解决安装问题! ${gumDocUrl}` : `gum installation failed, please try manual install: ${gumDocUrl}`));
|
|
66
|
+
if (strict) node_process.default.exit(1);
|
|
67
|
+
}
|
|
68
|
+
} else console.log(picocolors.default.yellow(isZh$6 ? `未检测到 gum,请根据系统手动安装: ${gumDocUrl}` : `gum not found, please install it manually: ${gumDocUrl}`));
|
|
69
|
+
if (ni && !await (0, lazy_js_utils_node.isInstallPkg)("ni")) {
|
|
70
|
+
console.log(picocolors.default.cyan(isZh$6 ? "正在为您安装必要的依赖ni..." : "Installing ni..."));
|
|
71
|
+
const { status } = await (0, lazy_js_utils_node.jsShell)("npm i -g @antfu/ni", [
|
|
72
|
+
"inherit",
|
|
73
|
+
"pipe",
|
|
74
|
+
"inherit"
|
|
75
|
+
]);
|
|
76
|
+
if (status === 0) console.log(picocolors.default.cyan(isZh$6 ? "ni 安装成功!" : "ni installed successfully!"));
|
|
77
|
+
else {
|
|
78
|
+
console.log(picocolors.default.red(isZh$6 ? `ni 安装失败,请尝试从官网解决安装问题! ${niDocUrl}` : `ni installation failed, please try manual install: ${niDocUrl}`));
|
|
79
|
+
if (strict) node_process.default.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/help.ts
|
|
86
|
+
const isZh$5 = node_process.default.env.PI_Lang === "zh";
|
|
87
|
+
async function ensureGum() {
|
|
88
|
+
if (await (0, lazy_js_utils_node.isInstallPkg)("gum")) return true;
|
|
89
|
+
await installDeps({
|
|
90
|
+
gum: true,
|
|
91
|
+
ni: false,
|
|
92
|
+
strict: false
|
|
93
|
+
});
|
|
94
|
+
return await (0, lazy_js_utils_node.isInstallPkg)("gum");
|
|
95
|
+
}
|
|
96
|
+
function printPlainVersion() {
|
|
97
|
+
console.log(isZh$5 ? `pi 版本: ${version}` : `pi version: ${version}`);
|
|
98
|
+
console.log(isZh$5 ? "请为我的努力点一个行 🌟" : "Please give me a 🌟 for my efforts");
|
|
99
|
+
console.log(isZh$5 ? "谢谢 🤟" : "Thank you 🤟");
|
|
100
|
+
}
|
|
101
|
+
function printPlainHelp() {
|
|
102
|
+
console.log([
|
|
103
|
+
"PI Commands:",
|
|
104
|
+
"~ pi: install package",
|
|
105
|
+
"~ pix: npx package",
|
|
106
|
+
"~ pui: uninstall package",
|
|
107
|
+
"~ prun: run package script",
|
|
108
|
+
"~ pinit: package init",
|
|
109
|
+
"~ pbuild: go build | cargo build",
|
|
110
|
+
"~ pfind: find monorepo of yarn or pnpm",
|
|
111
|
+
"~ pa: agent alias",
|
|
112
|
+
"~ pu: package upgrade",
|
|
113
|
+
"~ pci: package clean install",
|
|
114
|
+
"~ pil: package latest install"
|
|
115
|
+
].join("\n"));
|
|
116
|
+
}
|
|
117
|
+
async function help(argv) {
|
|
118
|
+
const arg = argv[0];
|
|
119
|
+
if (arg === "-v" || arg === "--version") {
|
|
120
|
+
if (await ensureGum()) await (0, lazy_js_utils_node.jsShell)(isZh$5 ? `gum style \
|
|
121
|
+
--foreground 212 --border-foreground 212 --border double \
|
|
122
|
+
--align center --width 50 --margin "1 2" --padding "2 4" \
|
|
123
|
+
"pi 版本: ${version}" "请为我的努力点一个行 🌟" "谢谢 🤟"` : `gum style \
|
|
124
|
+
--foreground 212 --border-foreground 212 --border double \
|
|
125
|
+
--align center --width 50 --margin "1 2" --padding "2 4" \
|
|
126
|
+
"pi version: ${version}" "Please give me a 🌟 for my efforts" "Thank you 🤟"`, "inherit");
|
|
127
|
+
else printPlainVersion();
|
|
128
|
+
node_process.default.exit(0);
|
|
129
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
130
|
+
if (await ensureGum()) await (0, lazy_js_utils_node.jsShell)(`gum style \
|
|
131
|
+
--foreground 212 --border-foreground 212 --border double \
|
|
132
|
+
--align left --width 50 --margin "1 2" --padding "1 1" \
|
|
133
|
+
"PI Commands:" "~ pi: install package" "~ pix: npx 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"
|
|
134
|
+
`, "inherit");
|
|
135
|
+
else printPlainHelp();
|
|
136
|
+
node_process.default.exit(0);
|
|
137
|
+
}
|
|
112
138
|
}
|
|
113
139
|
|
|
114
|
-
|
|
115
|
-
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/pa.ts
|
|
116
142
|
function pa() {
|
|
117
|
-
|
|
143
|
+
return (0, lazy_js_utils_node.jsShell)("na");
|
|
118
144
|
}
|
|
119
145
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var import_node6 = require("lazy-js-utils/node");
|
|
124
|
-
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
125
|
-
|
|
126
|
-
// src/detectNode.ts
|
|
127
|
-
var import_node_process3 = __toESM(require("process"), 1);
|
|
128
|
-
var import_node4 = require("lazy-js-utils/node");
|
|
129
|
-
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/detectNode.ts
|
|
148
|
+
const isZh$4 = node_process.default.env.PI_Lang === "zh";
|
|
130
149
|
async function detectNode() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
let pkg;
|
|
151
|
+
try {
|
|
152
|
+
pkg = await (0, lazy_js_utils_node.getPkg)();
|
|
153
|
+
} catch {
|
|
154
|
+
const cwd = node_process.default.cwd();
|
|
155
|
+
console.log(picocolors.default.red(`当前目录: ${cwd} 没有package.json文件`));
|
|
156
|
+
node_process.default.exit(1);
|
|
157
|
+
}
|
|
158
|
+
if (pkg.engines?.node) {
|
|
159
|
+
const semver = await import("semver");
|
|
160
|
+
const satisfies = semver.satisfies || semver.default?.satisfies;
|
|
161
|
+
if (!satisfies) return;
|
|
162
|
+
if (!satisfies(node_process.default.version, pkg.engines.node)) {
|
|
163
|
+
const hasGum = await (0, lazy_js_utils_node.isInstallPkg)("gum");
|
|
164
|
+
const hasFnm = await (0, lazy_js_utils_node.isInstallPkg)("fnm");
|
|
165
|
+
if (!hasGum || !hasFnm) {
|
|
166
|
+
const missing = [!hasGum ? "gum" : "", !hasFnm ? "fnm" : ""].filter(Boolean).join(", ");
|
|
167
|
+
console.log(picocolors.default.yellow(isZh$4 ? `当前 node 版本不满足 ${pkg.engines.node},未检测到 ${missing},请手动切换版本。` : `Current Node version does not satisfy ${pkg.engines.node}. Missing ${missing}. Please switch manually.`));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const { result, status } = await (0, lazy_js_utils_node.jsShell)(`echo "yes\nno" | gum filter --placeholder=" 当前node版本不满足 ${pkg.engines.node},是否切换node版本"`, [
|
|
171
|
+
"inherit",
|
|
172
|
+
"pipe",
|
|
173
|
+
"inherit"
|
|
174
|
+
]);
|
|
175
|
+
if (status === 0 && result === "yes") await (0, lazy_js_utils_node.jsShell)(`
|
|
153
176
|
current=$(echo $(fnm current))
|
|
154
|
-
registery=$(echo "$(fnm ls)" | sed 's/system//g' | sed 's/default//g' | sed 's
|
|
155
|
-
registery=$(echo
|
|
177
|
+
registery=$(echo "$(fnm ls)" | sed 's/system//g' | sed 's/default//g' | sed 's/\* //g' | sed "s/$current/\* $current/g" | gum filter --placeholder=" 请选择一个node版本")
|
|
178
|
+
registery=$(echo $\{registery// /} | sed 's/\*//g')
|
|
156
179
|
if [ $registery ]; then
|
|
157
|
-
fnm use
|
|
180
|
+
fnm use $\{registery% -*}
|
|
158
181
|
fi
|
|
159
|
-
`,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
182
|
+
`, [
|
|
183
|
+
"inherit",
|
|
184
|
+
"pipe",
|
|
185
|
+
"inherit"
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
165
189
|
}
|
|
166
190
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
var D = /\s-D(?!w)/g;
|
|
178
|
-
var d = /\s-d(?!w)/g;
|
|
179
|
-
var isZh2 = import_node_process4.default.env.PI_Lang === "zh";
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/utils.ts
|
|
193
|
+
const DW = /\s-DW/g;
|
|
194
|
+
const W = /\s-W/g;
|
|
195
|
+
const Dw = /\s-Dw/g;
|
|
196
|
+
const w = /\s-w/g;
|
|
197
|
+
const D = /\s-D(?!w)/g;
|
|
198
|
+
const d = /\s-d(?!w)/g;
|
|
199
|
+
const isZh$3 = node_process.default.env.PI_Lang === "zh";
|
|
200
|
+
const log$1 = console.log;
|
|
180
201
|
async function getParams(params) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if ((await (0, import_node5.getPkg)())?.workspaces) {
|
|
225
|
-
if (D.test(params))
|
|
226
|
-
return params.replace(D, " -DW");
|
|
227
|
-
if (d.test(params))
|
|
228
|
-
return params.replace(d, " -DW");
|
|
229
|
-
if (!params || W.test(params) || DW.test(params))
|
|
230
|
-
return params;
|
|
231
|
-
return `${params} -W`;
|
|
232
|
-
}
|
|
233
|
-
if (Dw.test(params))
|
|
234
|
-
return params.replace(Dw, " -DW");
|
|
235
|
-
if (W.test(params))
|
|
236
|
-
return params.replace(W, " -W");
|
|
237
|
-
return params;
|
|
238
|
-
default:
|
|
239
|
-
return d.test(params) ? params.replace(d, " -D") : params;
|
|
240
|
-
}
|
|
241
|
-
} catch {
|
|
242
|
-
console.log(
|
|
243
|
-
import_picocolors3.default.red(
|
|
244
|
-
`${isZh2 ? "package.json\u5E76\u4E0D\u5B58\u5728,\u5728\u4EE5\u4E0B\u76EE\u5F55\u4E2D:" : "package.json has not been found in"} ${import_node_process4.default.cwd()}`
|
|
245
|
-
)
|
|
246
|
-
);
|
|
247
|
-
import_node_process4.default.exit(1);
|
|
248
|
-
}
|
|
202
|
+
const root = node_process.default.cwd();
|
|
203
|
+
try {
|
|
204
|
+
switch (await (0, lazy_js_utils_node.getPkgTool)()) {
|
|
205
|
+
case "pnpm":
|
|
206
|
+
if (!(0, lazy_js_utils.isFile)(node_path.default.resolve(root, "./pnpm-workspace.yaml"))) {
|
|
207
|
+
if (DW.test(params)) return params.replace(DW, " -D");
|
|
208
|
+
if (Dw.test(params)) return params.replace(Dw, " -D");
|
|
209
|
+
if (W.test(params)) return params.replace(W, "");
|
|
210
|
+
if (w.test(params)) return params.replace(w, "");
|
|
211
|
+
if (d.test(params)) return params.replace(d, " -D");
|
|
212
|
+
}
|
|
213
|
+
if ((0, lazy_js_utils.isFile)("./pnpm-workspace.yaml")) {
|
|
214
|
+
if (D.test(params)) return params.replace(D, " -Dw");
|
|
215
|
+
if (d.test(params)) return params.replace(d, " -Dw");
|
|
216
|
+
if (!params || Dw.test(params) || w.test(params)) return params;
|
|
217
|
+
return `${params} -w`;
|
|
218
|
+
}
|
|
219
|
+
if (DW.test(params)) return params.replace(DW, " -Dw");
|
|
220
|
+
if (W.test(params)) return params.replace(W, " -w");
|
|
221
|
+
return params;
|
|
222
|
+
case "yarn":
|
|
223
|
+
if (!(await (0, lazy_js_utils_node.getPkg)(node_path.default.resolve(root, "./package.json")))?.workspaces) {
|
|
224
|
+
if (Dw.test(params)) return params.replace(Dw, " -D");
|
|
225
|
+
if (DW.test(params)) return params.replace(DW, " -D");
|
|
226
|
+
if (W.test(params)) return params.replace(W, "");
|
|
227
|
+
if (w.test(params)) return params.replace(w, "");
|
|
228
|
+
if (d.test(params)) return params.replace(d, " -D");
|
|
229
|
+
}
|
|
230
|
+
if ((await (0, lazy_js_utils_node.getPkg)())?.workspaces) {
|
|
231
|
+
if (D.test(params)) return params.replace(D, " -DW");
|
|
232
|
+
if (d.test(params)) return params.replace(d, " -DW");
|
|
233
|
+
if (!params || W.test(params) || DW.test(params)) return params;
|
|
234
|
+
return `${params} -W`;
|
|
235
|
+
}
|
|
236
|
+
if (Dw.test(params)) return params.replace(Dw, " -DW");
|
|
237
|
+
if (W.test(params)) return params.replace(W, " -W");
|
|
238
|
+
return params;
|
|
239
|
+
default: return d.test(params) ? params.replace(d, " -D") : params;
|
|
240
|
+
}
|
|
241
|
+
} catch {
|
|
242
|
+
console.log(picocolors.default.red(`${isZh$3 ? "package.json并不存在,在以下目录中:" : "package.json has not been found in"} ${node_process.default.cwd()}`));
|
|
243
|
+
node_process.default.exit(1);
|
|
244
|
+
}
|
|
249
245
|
}
|
|
250
246
|
async function loading(text, isSilent = false) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
247
|
+
const { color, spinner } = await getStyle();
|
|
248
|
+
const ora = (await import("ora")).default;
|
|
249
|
+
return ora({
|
|
250
|
+
text,
|
|
251
|
+
spinner,
|
|
252
|
+
color,
|
|
253
|
+
isSilent,
|
|
254
|
+
discardStdin: true
|
|
255
|
+
}).start();
|
|
260
256
|
}
|
|
261
257
|
async function getStyle() {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
258
|
+
const { PI_COLOR: color = "yellow", PI_SPINNER: spinner = "star" } = node_process.default.env;
|
|
259
|
+
return {
|
|
260
|
+
color,
|
|
261
|
+
spinner
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async function getLatestVersion(pkg, isZh = true) {
|
|
265
|
+
const data = [];
|
|
266
|
+
for (const p of pkg.replace(/\s+/, " ").split(" ")) {
|
|
267
|
+
const [pName, v] = p.split("$");
|
|
268
|
+
let { status, result } = await (0, lazy_js_utils_node.jsShell)(`npm view ${pName}`, [
|
|
269
|
+
"inherit",
|
|
270
|
+
"pipe",
|
|
271
|
+
"inherit"
|
|
272
|
+
]);
|
|
273
|
+
if (status === 0) {
|
|
274
|
+
if (result.startsWith("@")) result = result.slice(1);
|
|
275
|
+
const item = isZh ? `${pName} ${picocolors.default.gray(v)} -> ${result.match(/@(\S+)/)[1]}` : `Installed ${pName} ${picocolors.default.dim(v)} -> latest version:${result.match(/@(\S+)/)[1]}`;
|
|
276
|
+
data.push(item);
|
|
277
|
+
} else throw new Error(result);
|
|
278
|
+
}
|
|
279
|
+
return `${data.join(" ")}${isZh ? " 安装成功! 😊" : " successfully! 😊"}`;
|
|
267
280
|
}
|
|
268
|
-
async function
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
281
|
+
async function pushHistory(command) {
|
|
282
|
+
log$1(picocolors.default.bold(picocolors.default.blue(`${isZh$3 ? "快捷指令" : "shortcut command"}: ${command}`)));
|
|
283
|
+
const shellName = (node_process.default.env.SHELL || "/bin/bash").split("/").pop() || "bash";
|
|
284
|
+
let historyFile = "";
|
|
285
|
+
let historyFormat = "bash";
|
|
286
|
+
const home = node_process.default.env.HOME || node_os.default.homedir();
|
|
287
|
+
switch (shellName) {
|
|
288
|
+
case "zsh":
|
|
289
|
+
historyFile = node_path.default.join(home, ".zsh_history");
|
|
290
|
+
historyFormat = "zsh";
|
|
291
|
+
break;
|
|
292
|
+
case "bash":
|
|
293
|
+
historyFile = node_process.default.env.HISTFILE || node_path.default.join(home, ".bash_history");
|
|
294
|
+
historyFormat = "bash";
|
|
295
|
+
break;
|
|
296
|
+
case "fish":
|
|
297
|
+
historyFile = node_path.default.join(home, ".local", "share", "fish", "fish_history");
|
|
298
|
+
historyFormat = "fish";
|
|
299
|
+
break;
|
|
300
|
+
default:
|
|
301
|
+
historyFile = node_process.default.env.HISTFILE || node_path.default.join(home, ".bash_history");
|
|
302
|
+
historyFormat = "bash";
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
if (!node_fs.default.existsSync(historyFile)) {
|
|
306
|
+
log$1(picocolors.default.yellow(`${isZh$3 ? `未找到 ${shellName} 历史文件` : `${shellName} history file not found`}`));
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const raw = node_fs.default.readFileSync(historyFile, "utf8");
|
|
310
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
311
|
+
let newEntry = "";
|
|
312
|
+
if (historyFormat === "zsh") newEntry = `: ${timestamp}:0;${command}`;
|
|
313
|
+
else if (historyFormat === "fish") newEntry = `- cmd: ${command}\n when: ${timestamp}`;
|
|
314
|
+
else if (node_process.default.env.HISTTIMEFORMAT) newEntry = `#${timestamp}\n${command}`;
|
|
315
|
+
else newEntry = command;
|
|
316
|
+
function parseEntries(content) {
|
|
317
|
+
if (historyFormat === "fish") {
|
|
318
|
+
const lines = content.split(/\r?\n/);
|
|
319
|
+
const blocks = [];
|
|
320
|
+
let buffer = [];
|
|
321
|
+
for (const line of lines) if (line.startsWith("- cmd: ")) {
|
|
322
|
+
if (buffer.length) {
|
|
323
|
+
blocks.push(buffer.join("\n"));
|
|
324
|
+
buffer = [];
|
|
325
|
+
}
|
|
326
|
+
buffer.push(line);
|
|
327
|
+
} else if (buffer.length) buffer.push(line);
|
|
328
|
+
else if (line.trim() !== "") blocks.push(line);
|
|
329
|
+
if (buffer.length) blocks.push(buffer.join("\n"));
|
|
330
|
+
return blocks.filter(Boolean);
|
|
331
|
+
} else if (historyFormat === "zsh") return content.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
332
|
+
else {
|
|
333
|
+
const lines = content.split(/\r?\n/);
|
|
334
|
+
const entries = [];
|
|
335
|
+
for (let i = 0; i < lines.length; i++) {
|
|
336
|
+
const line = lines[i];
|
|
337
|
+
if (line.startsWith("#")) {
|
|
338
|
+
const next = lines[i + 1] ?? "";
|
|
339
|
+
entries.push(`${line}\n${next}`);
|
|
340
|
+
i++;
|
|
341
|
+
} else if (line.trim() !== "") entries.push(line);
|
|
342
|
+
}
|
|
343
|
+
return entries;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const entries = parseEntries(raw);
|
|
347
|
+
function extractCommand(entry) {
|
|
348
|
+
if (historyFormat === "fish") {
|
|
349
|
+
const m = entry.split("\n")[0].match(/^- cmd: (.*)$/);
|
|
350
|
+
return m ? m[1] : entry;
|
|
351
|
+
} else if (historyFormat === "zsh") {
|
|
352
|
+
const m = entry.match(/^[^;]*;(.+)$/);
|
|
353
|
+
return m ? m[1] : entry;
|
|
354
|
+
} else {
|
|
355
|
+
if (entry.startsWith("#")) {
|
|
356
|
+
const parts = entry.split(/\r?\n/);
|
|
357
|
+
return parts[1] ?? parts[0];
|
|
358
|
+
}
|
|
359
|
+
return entry;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const newEntries = [];
|
|
363
|
+
const newCmd = extractCommand(newEntry);
|
|
364
|
+
let existingFishBlock = null;
|
|
365
|
+
for (const e of entries) {
|
|
366
|
+
if (extractCommand(e) === newCmd) {
|
|
367
|
+
if (historyFormat === "fish") {
|
|
368
|
+
existingFishBlock = e;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
newEntries.push(e);
|
|
374
|
+
}
|
|
375
|
+
if (historyFormat === "fish" && existingFishBlock) {
|
|
376
|
+
const lines = existingFishBlock.split("\n");
|
|
377
|
+
let hasWhen = false;
|
|
378
|
+
const updated = lines.map((line) => {
|
|
379
|
+
if (line.trim().startsWith("when:") || line.startsWith(" when:")) {
|
|
380
|
+
hasWhen = true;
|
|
381
|
+
return ` when: ${timestamp}`;
|
|
382
|
+
}
|
|
383
|
+
return line;
|
|
384
|
+
});
|
|
385
|
+
if (!hasWhen) updated.splice(1, 0, ` when: ${timestamp}`);
|
|
386
|
+
newEntries.push(updated.join("\n"));
|
|
387
|
+
} else newEntries.push(newEntry);
|
|
388
|
+
let finalContent = "";
|
|
389
|
+
if (historyFormat === "fish") finalContent = `${newEntries.map((e) => e.trimEnd()).join("\n")}\n`;
|
|
390
|
+
else finalContent = `${newEntries.join("\n")}\n`;
|
|
391
|
+
const tmpPath = `${historyFile}.ccommand.tmp`;
|
|
392
|
+
node_fs.default.writeFileSync(tmpPath, finalContent, "utf8");
|
|
393
|
+
node_fs.default.renameSync(tmpPath, historyFile);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
log$1(picocolors.default.red(`${isZh$3 ? `❌ 添加到 ${shellName} 历史记录失败` : `❌ Failed to add to ${shellName} history`}${err ? `: ${String(err)}` : ""}`));
|
|
396
|
+
}
|
|
287
397
|
}
|
|
288
398
|
|
|
289
|
-
|
|
290
|
-
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/pi.ts
|
|
401
|
+
const isZh$2 = node_process.default.env.PI_Lang === "zh";
|
|
291
402
|
async function pi(params, pkg, executor = "ni") {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
${
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const dep = match[1];
|
|
371
|
-
(0, import_node6.jsShell)(`pi ${dep}@latest`);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
import_node_process5.default.exit();
|
|
403
|
+
await detectNode();
|
|
404
|
+
const text = pkg ? `Installing ${params} ...` : "Updating dependency ...";
|
|
405
|
+
const isLatest = executor === "pil";
|
|
406
|
+
const start = Date.now();
|
|
407
|
+
let successMsg = "";
|
|
408
|
+
if (isLatest) successMsg = await getLatestVersion(pkg, isZh$2);
|
|
409
|
+
else successMsg = pkg ? isZh$2 ? `${pkg} 安装成功! 😊` : `Installed ${pkg} successfully! 😊` : isZh$2 ? "依赖更新成功! 😊" : "Updated dependency successfully! 😊";
|
|
410
|
+
const failMsg = pkg ? isZh$2 ? `${params} 安装失败 😭` : `Failed to install ${params} 😭` : isZh$2 ? "依赖更新失败 😭" : "Failed to update dependency 😭";
|
|
411
|
+
const isSilent = node_process.default.env.PI_SILENT === "true";
|
|
412
|
+
let stdio = isSilent ? "inherit" : [
|
|
413
|
+
"inherit",
|
|
414
|
+
"pipe",
|
|
415
|
+
"inherit"
|
|
416
|
+
];
|
|
417
|
+
let loading_status;
|
|
418
|
+
const { PI_DEFAULT, PI_MaxSockets: sockets } = node_process.default.env;
|
|
419
|
+
const pkgTool = await (0, lazy_js_utils_node.getPkgTool)();
|
|
420
|
+
const maxSockets = sockets || 4;
|
|
421
|
+
const install = !params ? "install" : "add";
|
|
422
|
+
if (pkgTool === "npm") if (PI_DEFAULT) {
|
|
423
|
+
executor = `${PI_DEFAULT} ${install}`;
|
|
424
|
+
loading_status = await loading(text, isSilent);
|
|
425
|
+
} else {
|
|
426
|
+
stdio = "inherit";
|
|
427
|
+
executor = "ni";
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
executor = `${pkgTool} ${install}`;
|
|
431
|
+
loading_status = await loading(text, isSilent);
|
|
432
|
+
}
|
|
433
|
+
const newParams = isLatest ? "" : await getParams(params);
|
|
434
|
+
const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
|
|
435
|
+
const latestParams = Array.isArray(params) ? params : params ? [params] : [];
|
|
436
|
+
const cmdList = isLatest ? latestParams.map((p) => `${executor} ${p}`) : [`${executor}${newParams ? ` ${newParams}` : runSockets}`];
|
|
437
|
+
const runCmd = isLatest ? cmdList.join(" & ") : cmdList[0];
|
|
438
|
+
const runCommands = async (commands) => {
|
|
439
|
+
const results = await Promise.all(commands.map((command) => (0, lazy_js_utils_node.useNodeWorker)({
|
|
440
|
+
params: command,
|
|
441
|
+
stdio,
|
|
442
|
+
errorExit: false
|
|
443
|
+
})));
|
|
444
|
+
const failed = results.find((r) => r.status !== 0);
|
|
445
|
+
const merged = results.map((r) => r.result).filter(Boolean).join("\n");
|
|
446
|
+
return {
|
|
447
|
+
status: failed ? failed.status : 0,
|
|
448
|
+
result: failed?.result || merged
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
let { status, result } = await runCommands(cmdList);
|
|
452
|
+
if (result && result.includes("pnpm versions with respective Node.js version support")) {
|
|
453
|
+
(0, node_console.log)(result);
|
|
454
|
+
(0, node_console.log)(picocolors.default.yellow(isZh$2 ? "正在尝试使用 npm 再次执行..." : "Trying to use npm to run again..."));
|
|
455
|
+
const fallbackCommands = isLatest ? latestParams.map((p) => `npm install ${p}`) : [`npm install${newParams ? ` ${newParams}` : runSockets}`];
|
|
456
|
+
const fallbackResults = await Promise.all(fallbackCommands.map((command) => (0, lazy_js_utils_node.jsShell)(command, { stdio })));
|
|
457
|
+
const fallbackFailed = fallbackResults.find((r) => r.status !== 0);
|
|
458
|
+
const fallbackMerged = fallbackResults.map((r) => r.result).filter(Boolean).join("\n");
|
|
459
|
+
status = fallbackFailed ? fallbackFailed.status : 0;
|
|
460
|
+
result = fallbackFailed?.result || fallbackMerged;
|
|
461
|
+
}
|
|
462
|
+
if (stdio === "inherit") loading_status = await loading("");
|
|
463
|
+
const costTime = (Date.now() - start) / 1e3;
|
|
464
|
+
successMsg += picocolors.default.blue(` ---- ⏰:${costTime}s`);
|
|
465
|
+
if (status === 0) {
|
|
466
|
+
loading_status.succeed(picocolors.default.green(successMsg));
|
|
467
|
+
pushHistory(runCmd);
|
|
468
|
+
} else if (result && result.includes("Not Found - 404")) {
|
|
469
|
+
const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
|
|
470
|
+
const _result = isZh$2 ? `${_pkg} 包名可能有误或者版本号不存在,并不能在npm中搜索到,请检查` : `${_pkg} the package name may be wrong, and cannot be found in npm, please check`;
|
|
471
|
+
loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${_result}` : failMsg));
|
|
472
|
+
} else loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${result}` : failMsg));
|
|
473
|
+
if (result) {
|
|
474
|
+
const match = result.match(/ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE\u2009 In : No matching version found for\s+([^@]+)/);
|
|
475
|
+
if (match) {
|
|
476
|
+
const dep = match[1];
|
|
477
|
+
(0, lazy_js_utils_node.jsShell)(`pi ${dep}@latest`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
node_process.default.exit();
|
|
375
481
|
}
|
|
376
482
|
|
|
377
|
-
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/pci.ts
|
|
378
485
|
function pci(params, pkg) {
|
|
379
|
-
|
|
486
|
+
return pi(params, pkg, "nci");
|
|
380
487
|
}
|
|
381
488
|
|
|
382
|
-
|
|
383
|
-
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/require.ts
|
|
491
|
+
const entry = node_process.default.argv[1];
|
|
492
|
+
const base = entry ? node_path.default.resolve(entry) : node_path.default.join(node_process.default.cwd(), "index.js");
|
|
493
|
+
const localRequire = (0, node_module.createRequire)(base);
|
|
494
|
+
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/pfind.ts
|
|
384
497
|
function pfind(params) {
|
|
385
|
-
|
|
498
|
+
const { ccommand } = localRequire("ccommand");
|
|
499
|
+
return ccommand(`find ${params}`);
|
|
386
500
|
}
|
|
387
501
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
var import_node7 = require("lazy-js-utils/node");
|
|
391
|
-
var import_picocolors5 = __toESM(require("picocolors"), 1);
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/pil.ts
|
|
392
504
|
async function pil(params) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
return f;
|
|
457
|
-
};
|
|
458
|
-
const combineWorkspace = (f, w2) => {
|
|
459
|
-
if (!w2)
|
|
460
|
-
return f;
|
|
461
|
-
if (/w/i.test(f))
|
|
462
|
-
return f;
|
|
463
|
-
if (!f)
|
|
464
|
-
return w2;
|
|
465
|
-
if (/d/i.test(f))
|
|
466
|
-
return `-D${w2.slice(1)}`;
|
|
467
|
-
return w2;
|
|
468
|
-
};
|
|
469
|
-
const finalFlags = pkgs.map((_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag));
|
|
470
|
-
const group = {};
|
|
471
|
-
pkgs.forEach((p, i) => {
|
|
472
|
-
const key = finalFlags[i] || "";
|
|
473
|
-
if (!group[key])
|
|
474
|
-
group[key] = [];
|
|
475
|
-
group[key].push(p);
|
|
476
|
-
});
|
|
477
|
-
const cmds = Object.entries(group).map(([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`);
|
|
478
|
-
return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
|
|
505
|
+
const isZh = node_process.default.env.PI_Lang === "zh";
|
|
506
|
+
const { dependencies = {}, devDependencies = {} } = await (0, lazy_js_utils_node.getPkg)();
|
|
507
|
+
if (!params) {
|
|
508
|
+
if (!await (0, lazy_js_utils_node.isInstallPkg)("gum")) {
|
|
509
|
+
console.log(picocolors.default.yellow(isZh ? "未检测到 gum,请先安装 gum 后再选择依赖。" : "gum not found. Please install gum before selecting dependencies."));
|
|
510
|
+
node_process.default.exit(1);
|
|
511
|
+
}
|
|
512
|
+
const { result: choose, status } = await (0, lazy_js_utils_node.jsShell)(`echo ${[...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`), ...Object.keys(devDependencies).map((key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`)].join(",")} | sed "s/,/\\n/g" | gum filter --no-limit --placeholder=" 🤔${node_process.default.env.PI_Lang === "zh" ? "请选择一个需要获取最新版本的依赖" : "Please select a dependency that needs to obtain the latest version."}"`, { stdio: [
|
|
513
|
+
"inherit",
|
|
514
|
+
"pipe",
|
|
515
|
+
"inherit"
|
|
516
|
+
] });
|
|
517
|
+
if (status === 130) {
|
|
518
|
+
console.log(picocolors.default.dim("已取消"));
|
|
519
|
+
node_process.default.exit(0);
|
|
520
|
+
} else if (status !== 0) throw new Error(choose);
|
|
521
|
+
params = choose.trim().split("\n").map((i) => {
|
|
522
|
+
const name = i.split(": ")[0];
|
|
523
|
+
if (name in devDependencies) return `${name}@latest -D`;
|
|
524
|
+
return `${name}@latest -S`;
|
|
525
|
+
}).join(" ");
|
|
526
|
+
}
|
|
527
|
+
let latestPkgname = params;
|
|
528
|
+
const reg = /\s(-[dws]+)/gi;
|
|
529
|
+
const suffix = [];
|
|
530
|
+
const command = latestPkgname = (await getParams(params)).replace(reg, (_, k) => {
|
|
531
|
+
suffix.push(k);
|
|
532
|
+
return "";
|
|
533
|
+
});
|
|
534
|
+
latestPkgname = latestPkgname.replace(/@latest/g, "").split(" ").filter(Boolean).map((i) => {
|
|
535
|
+
return `${i}$${dependencies[i] || devDependencies[i]}`;
|
|
536
|
+
}).join(" ");
|
|
537
|
+
const pkgs = command.replace(/\s+/, " ").trim().split(" ").filter(Boolean).filter((t) => !t.startsWith("-"));
|
|
538
|
+
let globalWorkspaceFlag = null;
|
|
539
|
+
const perFlags = [];
|
|
540
|
+
let assignIdx = 0;
|
|
541
|
+
for (const f of suffix) {
|
|
542
|
+
if (/^-(?:w|W)$/.test(f)) {
|
|
543
|
+
globalWorkspaceFlag = f;
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
perFlags[assignIdx++] = f;
|
|
547
|
+
}
|
|
548
|
+
const normalizeFlag = (f) => {
|
|
549
|
+
if (!f) return "";
|
|
550
|
+
if (/^-s$/i.test(f) || /^-S$/.test(f)) return "";
|
|
551
|
+
return f;
|
|
552
|
+
};
|
|
553
|
+
const combineWorkspace = (f, w) => {
|
|
554
|
+
if (!w) return f;
|
|
555
|
+
if (/w/i.test(f)) return f;
|
|
556
|
+
if (!f) return w;
|
|
557
|
+
if (/d/i.test(f)) return `-D${w.slice(1)}`;
|
|
558
|
+
return w;
|
|
559
|
+
};
|
|
560
|
+
const finalFlags = pkgs.map((_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag));
|
|
561
|
+
const group = {};
|
|
562
|
+
pkgs.forEach((p, i) => {
|
|
563
|
+
const key = finalFlags[i] || "";
|
|
564
|
+
if (!group[key]) group[key] = [];
|
|
565
|
+
group[key].push(p);
|
|
566
|
+
});
|
|
567
|
+
return await pi(Object.entries(group).map(([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`), latestPkgname.replace(/@latest/g, ""), "pil");
|
|
479
568
|
}
|
|
480
569
|
|
|
481
|
-
|
|
482
|
-
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/pinit.ts
|
|
483
572
|
async function pinit() {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
573
|
+
console.log("Initializing project...");
|
|
574
|
+
switch (await (0, lazy_js_utils_node.getPkgTool)()) {
|
|
575
|
+
case "npm":
|
|
576
|
+
await (0, lazy_js_utils_node.jsShell)("npm init -y");
|
|
577
|
+
return;
|
|
578
|
+
case "yarn":
|
|
579
|
+
await (0, lazy_js_utils_node.jsShell)("yarn init -y");
|
|
580
|
+
return;
|
|
581
|
+
case "pnpm":
|
|
582
|
+
await (0, lazy_js_utils_node.jsShell)("pnpm init -y");
|
|
583
|
+
return;
|
|
584
|
+
default: await (0, lazy_js_utils_node.jsShell)("npm init -y");
|
|
585
|
+
}
|
|
498
586
|
}
|
|
499
587
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
var import_node9 = require("lazy-js-utils/node");
|
|
503
|
-
var import_picocolors6 = __toESM(require("picocolors"), 1);
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/pio.ts
|
|
504
590
|
async function pio(params, pkg, executor = "ni") {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
loading_status.succeed(import_picocolors6.default.green(successMsg));
|
|
516
|
-
else
|
|
517
|
-
loading_status.fail(import_picocolors6.default.red(result ? `${result}
|
|
518
|
-
|
|
519
|
-
${failMsg}` : failMsg));
|
|
520
|
-
import_node_process7.default.exit();
|
|
591
|
+
const successMsg = pkg ? `Installed ${pkg} successfully! 😊` : "Updated dependency successfully! 😊";
|
|
592
|
+
const failMsg = pkg ? `Failed to install ${pkg} 😭` : "Failed to update dependency! 😭";
|
|
593
|
+
const { status, result } = await (0, lazy_js_utils_node.useNodeWorker)({
|
|
594
|
+
params: `${executor} ${await getParams(params)} --prefer-offline`,
|
|
595
|
+
stdio: "inherit"
|
|
596
|
+
});
|
|
597
|
+
const loading_status = await loading("");
|
|
598
|
+
if (status === 0) loading_status.succeed(picocolors.default.green(successMsg));
|
|
599
|
+
else loading_status.fail(picocolors.default.red(result ? `${result}\n\n${failMsg}` : failMsg));
|
|
600
|
+
node_process.default.exit();
|
|
521
601
|
}
|
|
522
602
|
|
|
523
|
-
|
|
524
|
-
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/pix.ts
|
|
525
605
|
async function pix(params) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return (0, import_node10.jsShell)(`npx ${params}`);
|
|
531
|
-
}
|
|
606
|
+
switch (await (0, lazy_js_utils_node.getPkgTool)()) {
|
|
607
|
+
case "bun": return (0, lazy_js_utils_node.jsShell)(`bunx ${params}`);
|
|
608
|
+
default: return (0, lazy_js_utils_node.jsShell)(`npx ${params}`);
|
|
609
|
+
}
|
|
532
610
|
}
|
|
533
611
|
|
|
534
|
-
|
|
535
|
-
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/prun.ts
|
|
536
614
|
function prun(params) {
|
|
537
|
-
|
|
615
|
+
const { ccommand } = localRequire("ccommand");
|
|
616
|
+
return ccommand(params);
|
|
538
617
|
}
|
|
539
618
|
|
|
540
|
-
|
|
541
|
-
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/pu.ts
|
|
542
621
|
function pu() {
|
|
543
|
-
|
|
622
|
+
return (0, lazy_js_utils_node.jsShell)("nu");
|
|
544
623
|
}
|
|
545
624
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
var import_picocolors7 = __toESM(require("picocolors"), 1);
|
|
550
|
-
var isZh4 = import_node_process8.default.env.PI_Lang === "zh";
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/pui.ts
|
|
627
|
+
const isZh$1 = node_process.default.env.PI_Lang === "zh";
|
|
551
628
|
async function pui(params, pkg) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
import_picocolors7.default.yellow(
|
|
581
|
-
isZh4 ? "\u9700\u8981\u6307\u5B9A\u8981\u5378\u8F7D\u7684\u5305\u540D\uFF01" : "Need to specify an uninstall package name!"
|
|
582
|
-
)
|
|
583
|
-
);
|
|
584
|
-
import_node_process8.default.exit(1);
|
|
585
|
-
}
|
|
586
|
-
const loading_status = await loading(text);
|
|
587
|
-
const { status, result } = await (0, import_node12.useNodeWorker)(`nun ${params}`);
|
|
588
|
-
const end = Date.now();
|
|
589
|
-
const costTime = (end - start) / 1e3;
|
|
590
|
-
successMsg += import_picocolors7.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
|
|
591
|
-
if (status === 0)
|
|
592
|
-
loading_status.succeed(import_picocolors7.default.green(successMsg));
|
|
593
|
-
else
|
|
594
|
-
loading_status.fail(import_picocolors7.default.red(result ? `${failMsg}
|
|
595
|
-
${result}` : failMsg));
|
|
596
|
-
import_node_process8.default.exit();
|
|
629
|
+
const text = `${isZh$1 ? "正在为您卸载" : "Uninstalling"} ${pkg} ...`;
|
|
630
|
+
if (!params) {
|
|
631
|
+
const { dependencies = {}, devDependencies = {} } = await (0, lazy_js_utils_node.getPkg)();
|
|
632
|
+
const { result: choose, status } = await (0, lazy_js_utils_node.jsShell)(`echo ${[...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key]}`), ...Object.keys(devDependencies).map((key) => `${key}: ${devDependencies[key]}`)].join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" 🤔${node_process.default.env.PI_Lang === "zh" ? "请选择一个需要删除依赖" : "Please select a dependency to get the latest version."}"`, [
|
|
633
|
+
"inherit",
|
|
634
|
+
"pipe",
|
|
635
|
+
"inherit"
|
|
636
|
+
]);
|
|
637
|
+
if (status === 130) {
|
|
638
|
+
console.log(picocolors.default.dim("已取消"));
|
|
639
|
+
node_process.default.exit(0);
|
|
640
|
+
} else if (status !== 0) throw new Error(choose);
|
|
641
|
+
pkg = params = choose.split(": ")[0];
|
|
642
|
+
}
|
|
643
|
+
const start = Date.now();
|
|
644
|
+
let successMsg = isZh$1 ? `${pkg}卸载成功! 😊` : `UnInstalled ${pkg} successfully! 😊`;
|
|
645
|
+
const failMsg = isZh$1 ? `${pkg}卸载失败 😭` : `Failed to uninstall ${pkg} 😭`;
|
|
646
|
+
if (!pkg) {
|
|
647
|
+
console.log(picocolors.default.yellow(isZh$1 ? "需要指定要卸载的包名!" : "Need to specify an uninstall package name!"));
|
|
648
|
+
node_process.default.exit(1);
|
|
649
|
+
}
|
|
650
|
+
const loading_status = await loading(text);
|
|
651
|
+
const { status, result } = await (0, lazy_js_utils_node.useNodeWorker)(`nun ${params}`);
|
|
652
|
+
const costTime = (Date.now() - start) / 1e3;
|
|
653
|
+
successMsg += picocolors.default.blue(` ---- ⏰:${costTime}s`);
|
|
654
|
+
if (status === 0) loading_status.succeed(picocolors.default.green(successMsg));
|
|
655
|
+
else loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${result}` : failMsg));
|
|
656
|
+
node_process.default.exit();
|
|
597
657
|
}
|
|
598
658
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/index.ts
|
|
661
|
+
let rootPath = node_process.default.cwd();
|
|
662
|
+
const runMap = {
|
|
663
|
+
pi,
|
|
664
|
+
"pi.mjs": pi,
|
|
665
|
+
pix,
|
|
666
|
+
"pix.mjs": pix,
|
|
667
|
+
pa,
|
|
668
|
+
"pa.mjs": pa,
|
|
669
|
+
pui,
|
|
670
|
+
"pui.mjs": pui,
|
|
671
|
+
pu,
|
|
672
|
+
"pu.mjs": pu,
|
|
673
|
+
pil,
|
|
674
|
+
"pil.mjs": pil,
|
|
675
|
+
pci,
|
|
676
|
+
"pci.mjs": pci,
|
|
677
|
+
prun,
|
|
678
|
+
"prun.mjs": prun,
|
|
679
|
+
pinit,
|
|
680
|
+
"pinit.mjs": pinit,
|
|
681
|
+
pfind,
|
|
682
|
+
"pfind.mjs": pfind,
|
|
683
|
+
pio,
|
|
684
|
+
"pio.mjs": pio
|
|
624
685
|
};
|
|
625
|
-
|
|
686
|
+
const isZh = node_process.default.env.PI_Lang === "zh";
|
|
626
687
|
async function setup() {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (await (0, import_node13.isRust)(rootPath)) {
|
|
695
|
-
if (exec === "pi") {
|
|
696
|
-
const loading_status = await loading(
|
|
697
|
-
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
|
|
698
|
-
`
|
|
699
|
-
);
|
|
700
|
-
const { status } = await (0, import_node13.useNodeWorker)(
|
|
701
|
-
`cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
|
|
702
|
-
);
|
|
703
|
-
if (status === 0) {
|
|
704
|
-
loading_status.succeed(
|
|
705
|
-
import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
|
|
706
|
-
);
|
|
707
|
-
} else {
|
|
708
|
-
loading_status.fail(
|
|
709
|
-
import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
} else if (exec === "pui") {
|
|
713
|
-
const loading_status = await loading(
|
|
714
|
-
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
|
|
715
|
-
`
|
|
716
|
-
);
|
|
717
|
-
const { status } = await (0, import_node13.useNodeWorker)(
|
|
718
|
-
`cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
|
|
719
|
-
);
|
|
720
|
-
if (status === 0) {
|
|
721
|
-
loading_status.succeed(
|
|
722
|
-
import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
|
|
723
|
-
);
|
|
724
|
-
} else {
|
|
725
|
-
loading_status.fail(
|
|
726
|
-
import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
} else if (exec === "prun") {
|
|
730
|
-
await (0, import_node13.jsShell)(
|
|
731
|
-
`cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
|
|
732
|
-
"inherit"
|
|
733
|
-
);
|
|
734
|
-
} else if (exec === "pinit") {
|
|
735
|
-
await (0, import_node13.jsShell)(
|
|
736
|
-
`cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
|
|
737
|
-
"inherit"
|
|
738
|
-
);
|
|
739
|
-
} else if (exec === "pbuild") {
|
|
740
|
-
await (0, import_node13.jsShell)(
|
|
741
|
-
`cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
|
|
742
|
-
"inherit"
|
|
743
|
-
);
|
|
744
|
-
} else {
|
|
745
|
-
console.log(
|
|
746
|
-
import_picocolors8.default.red(
|
|
747
|
-
isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
|
|
748
|
-
)
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
import_node_process9.default.exit();
|
|
752
|
-
}
|
|
753
|
-
if (!runMap[exec]) {
|
|
754
|
-
console.log(
|
|
755
|
-
import_picocolors8.default.yellow(
|
|
756
|
-
isZh5 ? "\u547D\u4EE4\u4E0D\u5B58\u5728, \u8BF7\u6267\u884C pi -h \u67E5\u770B\u5E2E\u52A9" : "The command does not exist, please execute pi -h to view the help"
|
|
757
|
-
)
|
|
758
|
-
);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
763
|
-
await installDeps();
|
|
764
|
-
runMap[exec](params, pkg);
|
|
688
|
+
const cmd = node_process.default.argv[1];
|
|
689
|
+
let exec = "";
|
|
690
|
+
if ((0, lazy_js_utils.isWin)()) {
|
|
691
|
+
const last = cmd.lastIndexOf("\\") + 1;
|
|
692
|
+
exec = cmd.slice(last, cmd.length).split(".").slice(0, -1).join(".");
|
|
693
|
+
} else {
|
|
694
|
+
const last = cmd.lastIndexOf("/") + 1;
|
|
695
|
+
exec = cmd.slice(last, cmd.length);
|
|
696
|
+
}
|
|
697
|
+
const argv = node_process.default.argv.slice(2);
|
|
698
|
+
await help(argv);
|
|
699
|
+
let params = (0, lazy_js_utils.spaceFormat)(argv.join(" ")).trim();
|
|
700
|
+
if (!await (0, lazy_js_utils_node.hasPkg)(rootPath)) {
|
|
701
|
+
if (await (0, lazy_js_utils_node.isGo)(rootPath)) {
|
|
702
|
+
if (exec === "pi") {
|
|
703
|
+
const loading_status = await loading(`${isZh ? "正在为您安装" : "Installing"} ${params} ...\n`);
|
|
704
|
+
const { status } = params ? await (0, lazy_js_utils_node.useNodeWorker)(`go get ${params}`) : await (0, lazy_js_utils_node.useNodeWorker)("go mod tidy");
|
|
705
|
+
if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "安装成功! 😊" : "Installed successfully! 😊"));
|
|
706
|
+
else loading_status.fail(picocolors.default.red(isZh ? "安装失败 😭" : "Failed to install 😭"));
|
|
707
|
+
} else if (exec === "pui") {
|
|
708
|
+
const loading_status = await loading(`${isZh ? "正在为您卸载" : "Uninstalling"} ${params} ...\n`);
|
|
709
|
+
const { status } = await (0, lazy_js_utils_node.useNodeWorker)(`go clean ${params}`);
|
|
710
|
+
if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "卸载成功! 😊" : "Uninstalled successfully! 😊"));
|
|
711
|
+
else loading_status.fail(picocolors.default.red(isZh ? "卸载失败 😭" : "Failed to uninstall 😭"));
|
|
712
|
+
} else if (exec === "prun") {
|
|
713
|
+
const target = (await (0, fast_glob.default)(params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go"))[0];
|
|
714
|
+
if (target) return await (0, lazy_js_utils_node.jsShell)(`go run ${target}`, "inherit");
|
|
715
|
+
const { ccommand } = localRequire("ccommand");
|
|
716
|
+
return ccommand(params);
|
|
717
|
+
} else if (exec === "pinit") await (0, lazy_js_utils_node.jsShell)(`go mod init ${params}`, "inherit");
|
|
718
|
+
else if (exec === "pbuild") await (0, lazy_js_utils_node.jsShell)(`go build ${params}`, "inherit");
|
|
719
|
+
else console.log(picocolors.default.red(isZh ? "当前指令还不支持" : "The commands is not supported"));
|
|
720
|
+
node_process.default.exit();
|
|
721
|
+
}
|
|
722
|
+
let projectPath = "";
|
|
723
|
+
if (params && !await (0, lazy_js_utils_node.isRust)()) {
|
|
724
|
+
projectPath = params.split(" ")[0];
|
|
725
|
+
rootPath = node_path.default.resolve(rootPath, projectPath);
|
|
726
|
+
params = params.replace(projectPath, "").trim();
|
|
727
|
+
}
|
|
728
|
+
if (await (0, lazy_js_utils_node.isRust)(rootPath)) {
|
|
729
|
+
if (exec === "pi") {
|
|
730
|
+
const loading_status = await loading(`${isZh ? "正在为您安装" : "Installing"} ${params} ...\n`);
|
|
731
|
+
const { status } = await (0, lazy_js_utils_node.useNodeWorker)(`cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`);
|
|
732
|
+
if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "安装成功! 😊" : "Installed successfully! 😊"));
|
|
733
|
+
else loading_status.fail(picocolors.default.red(isZh ? "安装失败 😭" : "Failed to install 😭"));
|
|
734
|
+
} else if (exec === "pui") {
|
|
735
|
+
const loading_status = await loading(`${isZh ? "正在为您卸载" : "Uninstalling"} ${params} ...\n`);
|
|
736
|
+
const { status } = await (0, lazy_js_utils_node.useNodeWorker)(`cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`);
|
|
737
|
+
if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "卸载成功! 😊" : "Uninstalled successfully! 😊"));
|
|
738
|
+
else loading_status.fail(picocolors.default.red(isZh ? "卸载失败 😭" : "Failed to uninstall 😭"));
|
|
739
|
+
} else if (exec === "prun") await (0, lazy_js_utils_node.jsShell)(`cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit");
|
|
740
|
+
else if (exec === "pinit") await (0, lazy_js_utils_node.jsShell)(`cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit");
|
|
741
|
+
else if (exec === "pbuild") await (0, lazy_js_utils_node.jsShell)(`cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit");
|
|
742
|
+
else console.log(picocolors.default.red(isZh ? "当前指令还不支持" : "The commands is not supported"));
|
|
743
|
+
node_process.default.exit();
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const handler = runMap[exec];
|
|
747
|
+
if (!handler) {
|
|
748
|
+
if (exec === "pbuild" || exec === "pbuild.mjs") console.log(picocolors.default.yellow(isZh ? "pbuild 仅支持 Go/Rust 项目(go build / cargo build)。" : "pbuild is only supported for Go/Rust projects (go build / cargo build)."));
|
|
749
|
+
else console.log(picocolors.default.yellow(isZh ? "命令不存在, 请执行 pi -h 查看帮助" : "The command does not exist, please execute pi -h to view the help"));
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
753
|
+
await installDeps();
|
|
754
|
+
await handler(params, pkg);
|
|
765
755
|
}
|
|
766
|
-
setup()
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
setup
|
|
756
|
+
if (!node_process.default.env.PI_TEST) setup().catch((error) => {
|
|
757
|
+
console.error(error);
|
|
758
|
+
node_process.default.exit(1);
|
|
770
759
|
});
|
|
760
|
+
|
|
761
|
+
//#endregion
|
|
762
|
+
exports.setup = setup;
|