@simon_he/pi 0.1.20 → 0.1.22
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 +694 -865
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +729 -0
- package/package.json +19 -21
- package/dist/index.js +0 -911
package/dist/index.cjs
CHANGED
|
@@ -1,933 +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");
|
|
44
|
+
let node_url = require("node:url");
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
var version = "0.1.
|
|
46
|
+
//#region package.json
|
|
47
|
+
var version = "0.1.22";
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/installDeps.ts
|
|
51
|
+
const isZh$6 = node_process.default.env.PI_Lang === "zh";
|
|
52
|
+
const gumDocUrl = "https://github.com/charmbracelet/gum";
|
|
53
|
+
const niDocUrl = "https://github.com/antfu/ni";
|
|
54
|
+
async function installDeps(options = {}) {
|
|
55
|
+
const { gum = true, ni = true, strict = true } = options;
|
|
56
|
+
const platform = node_process.default.platform;
|
|
57
|
+
if (gum && !await (0, lazy_js_utils_node.isInstallPkg)("gum")) if (platform === "darwin") {
|
|
58
|
+
console.log(picocolors.default.cyan(isZh$6 ? "正在为您安装必要的依赖gum..." : "Installing gum..."));
|
|
59
|
+
const { status } = await (0, lazy_js_utils_node.jsShell)("brew install gum", [
|
|
60
|
+
"inherit",
|
|
61
|
+
"pipe",
|
|
62
|
+
"inherit"
|
|
63
|
+
]);
|
|
64
|
+
if (status === 0) console.log(picocolors.default.cyan(isZh$6 ? "gum 安装成功!" : "gum installed successfully!"));
|
|
65
|
+
else {
|
|
66
|
+
console.log(picocolors.default.red(isZh$6 ? `gum 安装失败,请尝试从官网解决安装问题! ${gumDocUrl}` : `gum installation failed, please try manual install: ${gumDocUrl}`));
|
|
67
|
+
if (strict) node_process.default.exit(1);
|
|
68
|
+
}
|
|
69
|
+
} else console.log(picocolors.default.yellow(isZh$6 ? `未检测到 gum,请根据系统手动安装: ${gumDocUrl}` : `gum not found, please install it manually: ${gumDocUrl}`));
|
|
70
|
+
if (ni && !await (0, lazy_js_utils_node.isInstallPkg)("ni")) {
|
|
71
|
+
console.log(picocolors.default.cyan(isZh$6 ? "正在为您安装必要的依赖ni..." : "Installing ni..."));
|
|
72
|
+
const { status } = await (0, lazy_js_utils_node.jsShell)("npm i -g @antfu/ni", [
|
|
73
|
+
"inherit",
|
|
74
|
+
"pipe",
|
|
75
|
+
"inherit"
|
|
76
|
+
]);
|
|
77
|
+
if (status === 0) console.log(picocolors.default.cyan(isZh$6 ? "ni 安装成功!" : "ni installed successfully!"));
|
|
78
|
+
else {
|
|
79
|
+
console.log(picocolors.default.red(isZh$6 ? `ni 安装失败,请尝试从官网解决安装问题! ${niDocUrl}` : `ni installation failed, please try manual install: ${niDocUrl}`));
|
|
80
|
+
if (strict) node_process.default.exit(1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
69
83
|
}
|
|
70
84
|
|
|
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
|
-
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/help.ts
|
|
87
|
+
const isZh$5 = node_process.default.env.PI_Lang === "zh";
|
|
88
|
+
async function ensureGum() {
|
|
89
|
+
if (await (0, lazy_js_utils_node.isInstallPkg)("gum")) return true;
|
|
90
|
+
await installDeps({
|
|
91
|
+
gum: true,
|
|
92
|
+
ni: false,
|
|
93
|
+
strict: false
|
|
94
|
+
});
|
|
95
|
+
return await (0, lazy_js_utils_node.isInstallPkg)("gum");
|
|
96
|
+
}
|
|
97
|
+
function printPlainVersion() {
|
|
98
|
+
console.log(isZh$5 ? `pi 版本: ${version}` : `pi version: ${version}`);
|
|
99
|
+
console.log(isZh$5 ? "请为我的努力点一个行 🌟" : "Please give me a 🌟 for my efforts");
|
|
100
|
+
console.log(isZh$5 ? "谢谢 🤟" : "Thank you 🤟");
|
|
101
|
+
}
|
|
102
|
+
function printPlainHelp() {
|
|
103
|
+
console.log([
|
|
104
|
+
"PI Commands:",
|
|
105
|
+
"~ pi: install package",
|
|
106
|
+
"~ pix: npx package",
|
|
107
|
+
"~ pui: uninstall package",
|
|
108
|
+
"~ prun: run package script",
|
|
109
|
+
"~ pinit: package init",
|
|
110
|
+
"~ pbuild: go build | cargo build",
|
|
111
|
+
"~ pfind: find monorepo of yarn or pnpm",
|
|
112
|
+
"~ pa: agent alias",
|
|
113
|
+
"~ pu: package upgrade",
|
|
114
|
+
"~ pci: package clean install",
|
|
115
|
+
"~ pil: package latest install"
|
|
116
|
+
].join("\n"));
|
|
117
|
+
}
|
|
118
|
+
async function help(argv) {
|
|
119
|
+
const arg = argv[0];
|
|
120
|
+
if (arg === "-v" || arg === "--version") {
|
|
121
|
+
if (await ensureGum()) await (0, lazy_js_utils_node.jsShell)(isZh$5 ? `gum style \
|
|
122
|
+
--foreground 212 --border-foreground 212 --border double \
|
|
123
|
+
--align center --width 50 --margin "1 2" --padding "2 4" \
|
|
124
|
+
"pi 版本: ${version}" "请为我的努力点一个行 🌟" "谢谢 🤟"` : `gum style \
|
|
125
|
+
--foreground 212 --border-foreground 212 --border double \
|
|
126
|
+
--align center --width 50 --margin "1 2" --padding "2 4" \
|
|
127
|
+
"pi version: ${version}" "Please give me a 🌟 for my efforts" "Thank you 🤟"`, "inherit");
|
|
128
|
+
else printPlainVersion();
|
|
129
|
+
node_process.default.exit(0);
|
|
130
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
131
|
+
if (await ensureGum()) await (0, lazy_js_utils_node.jsShell)(`gum style \
|
|
132
|
+
--foreground 212 --border-foreground 212 --border double \
|
|
133
|
+
--align left --width 50 --margin "1 2" --padding "1 1" \
|
|
134
|
+
"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"
|
|
135
|
+
`, "inherit");
|
|
136
|
+
else printPlainHelp();
|
|
137
|
+
node_process.default.exit(0);
|
|
138
|
+
}
|
|
112
139
|
}
|
|
113
140
|
|
|
114
|
-
|
|
115
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/pa.ts
|
|
116
143
|
function pa() {
|
|
117
|
-
|
|
144
|
+
return (0, lazy_js_utils_node.jsShell)("na");
|
|
118
145
|
}
|
|
119
146
|
|
|
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);
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/detectNode.ts
|
|
149
|
+
const isZh$4 = node_process.default.env.PI_Lang === "zh";
|
|
130
150
|
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
|
-
|
|
151
|
+
let pkg;
|
|
152
|
+
try {
|
|
153
|
+
pkg = await (0, lazy_js_utils_node.getPkg)();
|
|
154
|
+
} catch {
|
|
155
|
+
const cwd = node_process.default.cwd();
|
|
156
|
+
console.log(picocolors.default.red(`当前目录: ${cwd} 没有package.json文件`));
|
|
157
|
+
node_process.default.exit(1);
|
|
158
|
+
}
|
|
159
|
+
if (pkg.engines?.node) {
|
|
160
|
+
const semver = await import("semver");
|
|
161
|
+
const satisfies = semver.satisfies || semver.default?.satisfies;
|
|
162
|
+
if (!satisfies) return;
|
|
163
|
+
if (!satisfies(node_process.default.version, pkg.engines.node)) {
|
|
164
|
+
const hasGum = await (0, lazy_js_utils_node.isInstallPkg)("gum");
|
|
165
|
+
const hasFnm = await (0, lazy_js_utils_node.isInstallPkg)("fnm");
|
|
166
|
+
if (!hasGum || !hasFnm) {
|
|
167
|
+
const missing = [!hasGum ? "gum" : "", !hasFnm ? "fnm" : ""].filter(Boolean).join(", ");
|
|
168
|
+
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.`));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const { result, status } = await (0, lazy_js_utils_node.jsShell)(`echo "yes\nno" | gum filter --placeholder=" 当前node版本不满足 ${pkg.engines.node},是否切换node版本"`, [
|
|
172
|
+
"inherit",
|
|
173
|
+
"pipe",
|
|
174
|
+
"inherit"
|
|
175
|
+
]);
|
|
176
|
+
if (status === 0 && result === "yes") await (0, lazy_js_utils_node.jsShell)(`
|
|
153
177
|
current=$(echo $(fnm current))
|
|
154
|
-
registery=$(echo "$(fnm ls)" | sed 's/system//g' | sed 's/default//g' | sed 's
|
|
155
|
-
registery=$(echo
|
|
178
|
+
registery=$(echo "$(fnm ls)" | sed 's/system//g' | sed 's/default//g' | sed 's/\* //g' | sed "s/$current/\* $current/g" | gum filter --placeholder=" 请选择一个node版本")
|
|
179
|
+
registery=$(echo $\{registery// /} | sed 's/\*//g')
|
|
156
180
|
if [ $registery ]; then
|
|
157
|
-
fnm use
|
|
181
|
+
fnm use $\{registery% -*}
|
|
158
182
|
fi
|
|
159
|
-
`,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
183
|
+
`, [
|
|
184
|
+
"inherit",
|
|
185
|
+
"pipe",
|
|
186
|
+
"inherit"
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
165
190
|
}
|
|
166
191
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
var Dw = /\s-Dw/g;
|
|
178
|
-
var w = /\s-w/g;
|
|
179
|
-
var D = /\s-D(?!w)/g;
|
|
180
|
-
var d = /\s-d(?!w)/g;
|
|
181
|
-
var isZh2 = import_node_process4.default.env.PI_Lang === "zh";
|
|
182
|
-
var log = console.log;
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/utils.ts
|
|
194
|
+
const DW = /\s-DW/g;
|
|
195
|
+
const W = /\s-W/g;
|
|
196
|
+
const Dw = /\s-Dw/g;
|
|
197
|
+
const w = /\s-w/g;
|
|
198
|
+
const D = /\s-D(?!w)/g;
|
|
199
|
+
const d = /\s-d(?!w)/g;
|
|
200
|
+
const isZh$3 = node_process.default.env.PI_Lang === "zh";
|
|
201
|
+
const log$1 = console.log;
|
|
183
202
|
async function getParams(params) {
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if ((await (0, import_node5.getPkg)())?.workspaces) {
|
|
228
|
-
if (D.test(params))
|
|
229
|
-
return params.replace(D, " -DW");
|
|
230
|
-
if (d.test(params))
|
|
231
|
-
return params.replace(d, " -DW");
|
|
232
|
-
if (!params || W.test(params) || DW.test(params))
|
|
233
|
-
return params;
|
|
234
|
-
return `${params} -W`;
|
|
235
|
-
}
|
|
236
|
-
if (Dw.test(params))
|
|
237
|
-
return params.replace(Dw, " -DW");
|
|
238
|
-
if (W.test(params))
|
|
239
|
-
return params.replace(W, " -W");
|
|
240
|
-
return params;
|
|
241
|
-
default:
|
|
242
|
-
return d.test(params) ? params.replace(d, " -D") : params;
|
|
243
|
-
}
|
|
244
|
-
} catch {
|
|
245
|
-
console.log(
|
|
246
|
-
import_picocolors3.default.red(
|
|
247
|
-
`${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()}`
|
|
248
|
-
)
|
|
249
|
-
);
|
|
250
|
-
import_node_process4.default.exit(1);
|
|
251
|
-
}
|
|
203
|
+
const root = node_process.default.cwd();
|
|
204
|
+
try {
|
|
205
|
+
switch (await (0, lazy_js_utils_node.getPkgTool)()) {
|
|
206
|
+
case "pnpm":
|
|
207
|
+
if (!(0, lazy_js_utils.isFile)(node_path.default.resolve(root, "./pnpm-workspace.yaml"))) {
|
|
208
|
+
if (DW.test(params)) return params.replace(DW, " -D");
|
|
209
|
+
if (Dw.test(params)) return params.replace(Dw, " -D");
|
|
210
|
+
if (W.test(params)) return params.replace(W, "");
|
|
211
|
+
if (w.test(params)) return params.replace(w, "");
|
|
212
|
+
if (d.test(params)) return params.replace(d, " -D");
|
|
213
|
+
}
|
|
214
|
+
if ((0, lazy_js_utils.isFile)("./pnpm-workspace.yaml")) {
|
|
215
|
+
if (D.test(params)) return params.replace(D, " -Dw");
|
|
216
|
+
if (d.test(params)) return params.replace(d, " -Dw");
|
|
217
|
+
if (!params || Dw.test(params) || w.test(params)) return params;
|
|
218
|
+
return `${params} -w`;
|
|
219
|
+
}
|
|
220
|
+
if (DW.test(params)) return params.replace(DW, " -Dw");
|
|
221
|
+
if (W.test(params)) return params.replace(W, " -w");
|
|
222
|
+
return params;
|
|
223
|
+
case "yarn":
|
|
224
|
+
if (!(await (0, lazy_js_utils_node.getPkg)(node_path.default.resolve(root, "./package.json")))?.workspaces) {
|
|
225
|
+
if (Dw.test(params)) return params.replace(Dw, " -D");
|
|
226
|
+
if (DW.test(params)) return params.replace(DW, " -D");
|
|
227
|
+
if (W.test(params)) return params.replace(W, "");
|
|
228
|
+
if (w.test(params)) return params.replace(w, "");
|
|
229
|
+
if (d.test(params)) return params.replace(d, " -D");
|
|
230
|
+
}
|
|
231
|
+
if ((await (0, lazy_js_utils_node.getPkg)())?.workspaces) {
|
|
232
|
+
if (D.test(params)) return params.replace(D, " -DW");
|
|
233
|
+
if (d.test(params)) return params.replace(d, " -DW");
|
|
234
|
+
if (!params || W.test(params) || DW.test(params)) return params;
|
|
235
|
+
return `${params} -W`;
|
|
236
|
+
}
|
|
237
|
+
if (Dw.test(params)) return params.replace(Dw, " -DW");
|
|
238
|
+
if (W.test(params)) return params.replace(W, " -W");
|
|
239
|
+
return params;
|
|
240
|
+
default: return d.test(params) ? params.replace(d, " -D") : params;
|
|
241
|
+
}
|
|
242
|
+
} catch {
|
|
243
|
+
console.log(picocolors.default.red(`${isZh$3 ? "package.json并不存在,在以下目录中:" : "package.json has not been found in"} ${node_process.default.cwd()}`));
|
|
244
|
+
node_process.default.exit(1);
|
|
245
|
+
}
|
|
252
246
|
}
|
|
253
247
|
async function loading(text, isSilent = false) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
248
|
+
const { color, spinner } = await getStyle();
|
|
249
|
+
const ora = (await import("ora")).default;
|
|
250
|
+
return ora({
|
|
251
|
+
text,
|
|
252
|
+
spinner,
|
|
253
|
+
color,
|
|
254
|
+
isSilent,
|
|
255
|
+
discardStdin: true
|
|
256
|
+
}).start();
|
|
263
257
|
}
|
|
264
258
|
async function getStyle() {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
259
|
+
const { PI_COLOR: color = "yellow", PI_SPINNER: spinner = "star" } = node_process.default.env;
|
|
260
|
+
return {
|
|
261
|
+
color,
|
|
262
|
+
spinner
|
|
263
|
+
};
|
|
270
264
|
}
|
|
271
|
-
async function getLatestVersion(pkg,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return `${data.join(" ")}${isZh6 ? " \u5B89\u88C5\u6210\u529F! \u{1F60A}" : " successfully! \u{1F60A}"}`;
|
|
265
|
+
async function getLatestVersion(pkg, isZh = true) {
|
|
266
|
+
const data = [];
|
|
267
|
+
for (const p of pkg.replace(/\s+/, " ").split(" ")) {
|
|
268
|
+
const [pName, v] = p.split("$");
|
|
269
|
+
let { status, result } = await (0, lazy_js_utils_node.jsShell)(`npm view ${pName}`, [
|
|
270
|
+
"inherit",
|
|
271
|
+
"pipe",
|
|
272
|
+
"inherit"
|
|
273
|
+
]);
|
|
274
|
+
if (status === 0) {
|
|
275
|
+
if (result.startsWith("@")) result = result.slice(1);
|
|
276
|
+
const item = isZh ? `${pName} ${picocolors.default.gray(v)} -> ${result.match(/@(\S+)/)[1]}` : `Installed ${pName} ${picocolors.default.dim(v)} -> latest version:${result.match(/@(\S+)/)[1]}`;
|
|
277
|
+
data.push(item);
|
|
278
|
+
} else throw new Error(result);
|
|
279
|
+
}
|
|
280
|
+
return `${data.join(" ")}${isZh ? " 安装成功! 😊" : " successfully! 😊"}`;
|
|
290
281
|
}
|
|
291
282
|
async function pushHistory(command) {
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
existingFishBlock = e;
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
newEntries.push(e);
|
|
413
|
-
}
|
|
414
|
-
if (historyFormat === "fish" && existingFishBlock) {
|
|
415
|
-
const lines = existingFishBlock.split("\n");
|
|
416
|
-
let hasWhen = false;
|
|
417
|
-
const updated = lines.map((line) => {
|
|
418
|
-
if (line.trim().startsWith("when:") || line.startsWith(" when:")) {
|
|
419
|
-
hasWhen = true;
|
|
420
|
-
return ` when: ${timestamp}`;
|
|
421
|
-
}
|
|
422
|
-
return line;
|
|
423
|
-
});
|
|
424
|
-
if (!hasWhen) {
|
|
425
|
-
updated.splice(1, 0, ` when: ${timestamp}`);
|
|
426
|
-
}
|
|
427
|
-
newEntries.push(updated.join("\n"));
|
|
428
|
-
} else {
|
|
429
|
-
newEntries.push(newEntry);
|
|
430
|
-
}
|
|
431
|
-
let finalContent = "";
|
|
432
|
-
if (historyFormat === "fish") {
|
|
433
|
-
finalContent = `${newEntries.map((e) => e.trimEnd()).join("\n")}
|
|
434
|
-
`;
|
|
435
|
-
} else {
|
|
436
|
-
finalContent = `${newEntries.join("\n")}
|
|
437
|
-
`;
|
|
438
|
-
}
|
|
439
|
-
const tmpPath = `${historyFile}.ccommand.tmp`;
|
|
440
|
-
import_node_fs.default.writeFileSync(tmpPath, finalContent, "utf8");
|
|
441
|
-
import_node_fs.default.renameSync(tmpPath, historyFile);
|
|
442
|
-
} catch (err) {
|
|
443
|
-
log(
|
|
444
|
-
import_picocolors3.default.red(
|
|
445
|
-
`${isZh2 ? `\u274C \u6DFB\u52A0\u5230 ${shellName} \u5386\u53F2\u8BB0\u5F55\u5931\u8D25` : `\u274C Failed to add to ${shellName} history`}${err ? `: ${String(err)}` : ""}`
|
|
446
|
-
)
|
|
447
|
-
);
|
|
448
|
-
}
|
|
283
|
+
log$1(picocolors.default.bold(picocolors.default.blue(`${isZh$3 ? "快捷指令" : "shortcut command"}: ${command}`)));
|
|
284
|
+
const shellName = (node_process.default.env.SHELL || "/bin/bash").split("/").pop() || "bash";
|
|
285
|
+
let historyFile = "";
|
|
286
|
+
let historyFormat = "bash";
|
|
287
|
+
const home = node_process.default.env.HOME || node_os.default.homedir();
|
|
288
|
+
switch (shellName) {
|
|
289
|
+
case "zsh":
|
|
290
|
+
historyFile = node_path.default.join(home, ".zsh_history");
|
|
291
|
+
historyFormat = "zsh";
|
|
292
|
+
break;
|
|
293
|
+
case "bash":
|
|
294
|
+
historyFile = node_process.default.env.HISTFILE || node_path.default.join(home, ".bash_history");
|
|
295
|
+
historyFormat = "bash";
|
|
296
|
+
break;
|
|
297
|
+
case "fish":
|
|
298
|
+
historyFile = node_path.default.join(home, ".local", "share", "fish", "fish_history");
|
|
299
|
+
historyFormat = "fish";
|
|
300
|
+
break;
|
|
301
|
+
default:
|
|
302
|
+
historyFile = node_process.default.env.HISTFILE || node_path.default.join(home, ".bash_history");
|
|
303
|
+
historyFormat = "bash";
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
if (!node_fs.default.existsSync(historyFile)) {
|
|
307
|
+
log$1(picocolors.default.yellow(`${isZh$3 ? `未找到 ${shellName} 历史文件` : `${shellName} history file not found`}`));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const raw = node_fs.default.readFileSync(historyFile, "utf8");
|
|
311
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
312
|
+
let newEntry = "";
|
|
313
|
+
if (historyFormat === "zsh") newEntry = `: ${timestamp}:0;${command}`;
|
|
314
|
+
else if (historyFormat === "fish") newEntry = `- cmd: ${command}\n when: ${timestamp}`;
|
|
315
|
+
else if (node_process.default.env.HISTTIMEFORMAT) newEntry = `#${timestamp}\n${command}`;
|
|
316
|
+
else newEntry = command;
|
|
317
|
+
function parseEntries(content) {
|
|
318
|
+
if (historyFormat === "fish") {
|
|
319
|
+
const lines = content.split(/\r?\n/);
|
|
320
|
+
const blocks = [];
|
|
321
|
+
let buffer = [];
|
|
322
|
+
for (const line of lines) if (line.startsWith("- cmd: ")) {
|
|
323
|
+
if (buffer.length) {
|
|
324
|
+
blocks.push(buffer.join("\n"));
|
|
325
|
+
buffer = [];
|
|
326
|
+
}
|
|
327
|
+
buffer.push(line);
|
|
328
|
+
} else if (buffer.length) buffer.push(line);
|
|
329
|
+
else if (line.trim() !== "") blocks.push(line);
|
|
330
|
+
if (buffer.length) blocks.push(buffer.join("\n"));
|
|
331
|
+
return blocks.filter(Boolean);
|
|
332
|
+
} else if (historyFormat === "zsh") return content.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
333
|
+
else {
|
|
334
|
+
const lines = content.split(/\r?\n/);
|
|
335
|
+
const entries = [];
|
|
336
|
+
for (let i = 0; i < lines.length; i++) {
|
|
337
|
+
const line = lines[i];
|
|
338
|
+
if (line.startsWith("#")) {
|
|
339
|
+
const next = lines[i + 1] ?? "";
|
|
340
|
+
entries.push(`${line}\n${next}`);
|
|
341
|
+
i++;
|
|
342
|
+
} else if (line.trim() !== "") entries.push(line);
|
|
343
|
+
}
|
|
344
|
+
return entries;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const entries = parseEntries(raw);
|
|
348
|
+
function extractCommand(entry) {
|
|
349
|
+
if (historyFormat === "fish") {
|
|
350
|
+
const m = entry.split("\n")[0].match(/^- cmd: (.*)$/);
|
|
351
|
+
return m ? m[1] : entry;
|
|
352
|
+
} else if (historyFormat === "zsh") {
|
|
353
|
+
const m = entry.match(/^[^;]*;(.+)$/);
|
|
354
|
+
return m ? m[1] : entry;
|
|
355
|
+
} else {
|
|
356
|
+
if (entry.startsWith("#")) {
|
|
357
|
+
const parts = entry.split(/\r?\n/);
|
|
358
|
+
return parts[1] ?? parts[0];
|
|
359
|
+
}
|
|
360
|
+
return entry;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const newEntries = [];
|
|
364
|
+
const newCmd = extractCommand(newEntry);
|
|
365
|
+
let existingFishBlock = null;
|
|
366
|
+
for (const e of entries) {
|
|
367
|
+
if (extractCommand(e) === newCmd) {
|
|
368
|
+
if (historyFormat === "fish") {
|
|
369
|
+
existingFishBlock = e;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
newEntries.push(e);
|
|
375
|
+
}
|
|
376
|
+
if (historyFormat === "fish" && existingFishBlock) {
|
|
377
|
+
const lines = existingFishBlock.split("\n");
|
|
378
|
+
let hasWhen = false;
|
|
379
|
+
const updated = lines.map((line) => {
|
|
380
|
+
if (line.trim().startsWith("when:") || line.startsWith(" when:")) {
|
|
381
|
+
hasWhen = true;
|
|
382
|
+
return ` when: ${timestamp}`;
|
|
383
|
+
}
|
|
384
|
+
return line;
|
|
385
|
+
});
|
|
386
|
+
if (!hasWhen) updated.splice(1, 0, ` when: ${timestamp}`);
|
|
387
|
+
newEntries.push(updated.join("\n"));
|
|
388
|
+
} else newEntries.push(newEntry);
|
|
389
|
+
let finalContent = "";
|
|
390
|
+
if (historyFormat === "fish") finalContent = `${newEntries.map((e) => e.trimEnd()).join("\n")}\n`;
|
|
391
|
+
else finalContent = `${newEntries.join("\n")}\n`;
|
|
392
|
+
const tmpPath = `${historyFile}.ccommand.tmp`;
|
|
393
|
+
node_fs.default.writeFileSync(tmpPath, finalContent, "utf8");
|
|
394
|
+
node_fs.default.renameSync(tmpPath, historyFile);
|
|
395
|
+
} catch (err) {
|
|
396
|
+
log$1(picocolors.default.red(`${isZh$3 ? `❌ 添加到 ${shellName} 历史记录失败` : `❌ Failed to add to ${shellName} history`}${err ? `: ${String(err)}` : ""}`));
|
|
397
|
+
}
|
|
449
398
|
}
|
|
450
399
|
|
|
451
|
-
|
|
452
|
-
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/pi.ts
|
|
402
|
+
const isZh$2 = node_process.default.env.PI_Lang === "zh";
|
|
453
403
|
async function pi(params, pkg, executor = "ni") {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
${result}` : failMsg));
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
import_node_process5.default.exit();
|
|
404
|
+
await detectNode();
|
|
405
|
+
const text = pkg ? `Installing ${params} ...` : "Updating dependency ...";
|
|
406
|
+
const isLatest = executor === "pil";
|
|
407
|
+
const start = Date.now();
|
|
408
|
+
let successMsg = "";
|
|
409
|
+
if (isLatest) successMsg = await getLatestVersion(pkg, isZh$2);
|
|
410
|
+
else successMsg = pkg ? isZh$2 ? `${pkg} 安装成功! 😊` : `Installed ${pkg} successfully! 😊` : isZh$2 ? "依赖更新成功! 😊" : "Updated dependency successfully! 😊";
|
|
411
|
+
const failMsg = pkg ? isZh$2 ? `${params} 安装失败 😭` : `Failed to install ${params} 😭` : isZh$2 ? "依赖更新失败 😭" : "Failed to update dependency 😭";
|
|
412
|
+
const isSilent = node_process.default.env.PI_SILENT === "true";
|
|
413
|
+
let stdio = isSilent ? "inherit" : [
|
|
414
|
+
"inherit",
|
|
415
|
+
"pipe",
|
|
416
|
+
"inherit"
|
|
417
|
+
];
|
|
418
|
+
let loading_status;
|
|
419
|
+
const { PI_DEFAULT, PI_MaxSockets: sockets } = node_process.default.env;
|
|
420
|
+
const pkgTool = await (0, lazy_js_utils_node.getPkgTool)();
|
|
421
|
+
const maxSockets = sockets || 4;
|
|
422
|
+
const install = !params ? "install" : "add";
|
|
423
|
+
if (pkgTool === "npm") if (PI_DEFAULT) {
|
|
424
|
+
executor = `${PI_DEFAULT} ${install}`;
|
|
425
|
+
loading_status = await loading(text, isSilent);
|
|
426
|
+
} else {
|
|
427
|
+
stdio = "inherit";
|
|
428
|
+
executor = "ni";
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
executor = `${pkgTool} ${install}`;
|
|
432
|
+
loading_status = await loading(text, isSilent);
|
|
433
|
+
}
|
|
434
|
+
const newParams = isLatest ? "" : await getParams(params);
|
|
435
|
+
const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
|
|
436
|
+
const latestParams = Array.isArray(params) ? params : params ? [params] : [];
|
|
437
|
+
const cmdList = isLatest ? latestParams.map((p) => `${executor} ${p}`) : [`${executor}${newParams ? ` ${newParams}` : runSockets}`];
|
|
438
|
+
const runCmd = isLatest ? cmdList.join(" & ") : cmdList[0];
|
|
439
|
+
const runCommands = async (commands) => {
|
|
440
|
+
const results = await Promise.all(commands.map((command) => (0, lazy_js_utils_node.useNodeWorker)({
|
|
441
|
+
params: command,
|
|
442
|
+
stdio,
|
|
443
|
+
errorExit: false
|
|
444
|
+
})));
|
|
445
|
+
const failed = results.find((r) => r.status !== 0);
|
|
446
|
+
const merged = results.map((r) => r.result).filter(Boolean).join("\n");
|
|
447
|
+
return {
|
|
448
|
+
status: failed ? failed.status : 0,
|
|
449
|
+
result: failed?.result || merged
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
let { status, result } = await runCommands(cmdList);
|
|
453
|
+
if (result && result.includes("pnpm versions with respective Node.js version support")) {
|
|
454
|
+
(0, node_console.log)(result);
|
|
455
|
+
(0, node_console.log)(picocolors.default.yellow(isZh$2 ? "正在尝试使用 npm 再次执行..." : "Trying to use npm to run again..."));
|
|
456
|
+
const fallbackCommands = isLatest ? latestParams.map((p) => `npm install ${p}`) : [`npm install${newParams ? ` ${newParams}` : runSockets}`];
|
|
457
|
+
const fallbackResults = await Promise.all(fallbackCommands.map((command) => (0, lazy_js_utils_node.jsShell)(command, { stdio })));
|
|
458
|
+
const fallbackFailed = fallbackResults.find((r) => r.status !== 0);
|
|
459
|
+
const fallbackMerged = fallbackResults.map((r) => r.result).filter(Boolean).join("\n");
|
|
460
|
+
status = fallbackFailed ? fallbackFailed.status : 0;
|
|
461
|
+
result = fallbackFailed?.result || fallbackMerged;
|
|
462
|
+
}
|
|
463
|
+
if (stdio === "inherit") loading_status = await loading("");
|
|
464
|
+
const costTime = (Date.now() - start) / 1e3;
|
|
465
|
+
successMsg += picocolors.default.blue(` ---- ⏰:${costTime}s`);
|
|
466
|
+
if (status === 0) {
|
|
467
|
+
loading_status.succeed(picocolors.default.green(successMsg));
|
|
468
|
+
pushHistory(runCmd);
|
|
469
|
+
} else if (result && result.includes("Not Found - 404")) {
|
|
470
|
+
const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
|
|
471
|
+
const _result = isZh$2 ? `${_pkg} 包名可能有误或者版本号不存在,并不能在npm中搜索到,请检查` : `${_pkg} the package name may be wrong, and cannot be found in npm, please check`;
|
|
472
|
+
loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${_result}` : failMsg));
|
|
473
|
+
} else loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${result}` : failMsg));
|
|
474
|
+
if (result) {
|
|
475
|
+
const match = result.match(/ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE\u2009 In : No matching version found for\s+([^@]+)/);
|
|
476
|
+
if (match) {
|
|
477
|
+
const dep = match[1];
|
|
478
|
+
(0, lazy_js_utils_node.jsShell)(`pi ${dep}@latest`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
node_process.default.exit();
|
|
534
482
|
}
|
|
535
483
|
|
|
536
|
-
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/pci.ts
|
|
537
486
|
function pci(params, pkg) {
|
|
538
|
-
|
|
487
|
+
return pi(params, pkg, "nci");
|
|
539
488
|
}
|
|
540
489
|
|
|
541
|
-
|
|
542
|
-
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/require.ts
|
|
492
|
+
const base = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
493
|
+
const localRequire = (0, node_module.createRequire)(base);
|
|
494
|
+
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/pfind.ts
|
|
543
497
|
function pfind(params) {
|
|
544
|
-
|
|
498
|
+
const { ccommand } = localRequire("ccommand");
|
|
499
|
+
return ccommand(`find ${params}`);
|
|
545
500
|
}
|
|
546
501
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
var import_node7 = require("lazy-js-utils/node");
|
|
550
|
-
var import_picocolors5 = __toESM(require("picocolors"), 1);
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/pil.ts
|
|
551
504
|
async function pil(params) {
|
|
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
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
return f;
|
|
616
|
-
};
|
|
617
|
-
const combineWorkspace = (f, w2) => {
|
|
618
|
-
if (!w2)
|
|
619
|
-
return f;
|
|
620
|
-
if (/w/i.test(f))
|
|
621
|
-
return f;
|
|
622
|
-
if (!f)
|
|
623
|
-
return w2;
|
|
624
|
-
if (/d/i.test(f))
|
|
625
|
-
return `-D${w2.slice(1)}`;
|
|
626
|
-
return w2;
|
|
627
|
-
};
|
|
628
|
-
const finalFlags = pkgs.map(
|
|
629
|
-
(_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag)
|
|
630
|
-
);
|
|
631
|
-
const group = {};
|
|
632
|
-
pkgs.forEach((p, i) => {
|
|
633
|
-
const key = finalFlags[i] || "";
|
|
634
|
-
if (!group[key])
|
|
635
|
-
group[key] = [];
|
|
636
|
-
group[key].push(p);
|
|
637
|
-
});
|
|
638
|
-
const cmds = Object.entries(group).map(
|
|
639
|
-
([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`
|
|
640
|
-
);
|
|
641
|
-
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");
|
|
642
568
|
}
|
|
643
569
|
|
|
644
|
-
|
|
645
|
-
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/pinit.ts
|
|
646
572
|
async function pinit() {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
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
|
+
}
|
|
661
586
|
}
|
|
662
587
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
var import_node9 = require("lazy-js-utils/node");
|
|
666
|
-
var import_picocolors6 = __toESM(require("picocolors"), 1);
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/pio.ts
|
|
667
590
|
async function pio(params, pkg, executor = "ni") {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
loading_status.succeed(import_picocolors6.default.green(successMsg));
|
|
679
|
-
else
|
|
680
|
-
loading_status.fail(import_picocolors6.default.red(result ? `${result}
|
|
681
|
-
|
|
682
|
-
${failMsg}` : failMsg));
|
|
683
|
-
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();
|
|
684
601
|
}
|
|
685
602
|
|
|
686
|
-
|
|
687
|
-
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/pix.ts
|
|
688
605
|
async function pix(params) {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
return (0, import_node10.jsShell)(`npx ${params}`);
|
|
694
|
-
}
|
|
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
|
+
}
|
|
695
610
|
}
|
|
696
611
|
|
|
697
|
-
|
|
698
|
-
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/prun.ts
|
|
699
614
|
function prun(params) {
|
|
700
|
-
|
|
615
|
+
const { ccommand } = localRequire("ccommand");
|
|
616
|
+
return ccommand(params);
|
|
701
617
|
}
|
|
702
618
|
|
|
703
|
-
|
|
704
|
-
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/pu.ts
|
|
705
621
|
function pu() {
|
|
706
|
-
|
|
622
|
+
return (0, lazy_js_utils_node.jsShell)("nu");
|
|
707
623
|
}
|
|
708
624
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
var import_picocolors7 = __toESM(require("picocolors"), 1);
|
|
713
|
-
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";
|
|
714
628
|
async function pui(params, pkg) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
import_picocolors7.default.yellow(
|
|
744
|
-
isZh4 ? "\u9700\u8981\u6307\u5B9A\u8981\u5378\u8F7D\u7684\u5305\u540D\uFF01" : "Need to specify an uninstall package name!"
|
|
745
|
-
)
|
|
746
|
-
);
|
|
747
|
-
import_node_process8.default.exit(1);
|
|
748
|
-
}
|
|
749
|
-
const loading_status = await loading(text);
|
|
750
|
-
const { status, result } = await (0, import_node12.useNodeWorker)(`nun ${params}`);
|
|
751
|
-
const end = Date.now();
|
|
752
|
-
const costTime = (end - start) / 1e3;
|
|
753
|
-
successMsg += import_picocolors7.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
|
|
754
|
-
if (status === 0)
|
|
755
|
-
loading_status.succeed(import_picocolors7.default.green(successMsg));
|
|
756
|
-
else
|
|
757
|
-
loading_status.fail(import_picocolors7.default.red(result ? `${failMsg}
|
|
758
|
-
${result}` : failMsg));
|
|
759
|
-
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();
|
|
760
657
|
}
|
|
761
658
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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
|
|
787
685
|
};
|
|
788
|
-
|
|
686
|
+
const isZh = node_process.default.env.PI_Lang === "zh";
|
|
789
687
|
async function setup() {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (await (0, import_node13.isRust)(rootPath)) {
|
|
858
|
-
if (exec === "pi") {
|
|
859
|
-
const loading_status = await loading(
|
|
860
|
-
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
|
|
861
|
-
`
|
|
862
|
-
);
|
|
863
|
-
const { status } = await (0, import_node13.useNodeWorker)(
|
|
864
|
-
`cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
|
|
865
|
-
);
|
|
866
|
-
if (status === 0) {
|
|
867
|
-
loading_status.succeed(
|
|
868
|
-
import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
|
|
869
|
-
);
|
|
870
|
-
} else {
|
|
871
|
-
loading_status.fail(
|
|
872
|
-
import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
} else if (exec === "pui") {
|
|
876
|
-
const loading_status = await loading(
|
|
877
|
-
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
|
|
878
|
-
`
|
|
879
|
-
);
|
|
880
|
-
const { status } = await (0, import_node13.useNodeWorker)(
|
|
881
|
-
`cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
|
|
882
|
-
);
|
|
883
|
-
if (status === 0) {
|
|
884
|
-
loading_status.succeed(
|
|
885
|
-
import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
|
|
886
|
-
);
|
|
887
|
-
} else {
|
|
888
|
-
loading_status.fail(
|
|
889
|
-
import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
} else if (exec === "prun") {
|
|
893
|
-
await (0, import_node13.jsShell)(
|
|
894
|
-
`cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
|
|
895
|
-
"inherit"
|
|
896
|
-
);
|
|
897
|
-
} else if (exec === "pinit") {
|
|
898
|
-
await (0, import_node13.jsShell)(
|
|
899
|
-
`cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
|
|
900
|
-
"inherit"
|
|
901
|
-
);
|
|
902
|
-
} else if (exec === "pbuild") {
|
|
903
|
-
await (0, import_node13.jsShell)(
|
|
904
|
-
`cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
|
|
905
|
-
"inherit"
|
|
906
|
-
);
|
|
907
|
-
} else {
|
|
908
|
-
console.log(
|
|
909
|
-
import_picocolors8.default.red(
|
|
910
|
-
isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
|
|
911
|
-
)
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
import_node_process9.default.exit();
|
|
915
|
-
}
|
|
916
|
-
if (!runMap[exec]) {
|
|
917
|
-
console.log(
|
|
918
|
-
import_picocolors8.default.yellow(
|
|
919
|
-
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"
|
|
920
|
-
)
|
|
921
|
-
);
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
|
|
926
|
-
await installDeps();
|
|
927
|
-
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);
|
|
928
755
|
}
|
|
929
|
-
setup()
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
setup
|
|
756
|
+
if (!node_process.default.env.PI_TEST) setup().catch((error) => {
|
|
757
|
+
console.error(error);
|
|
758
|
+
node_process.default.exit(1);
|
|
933
759
|
});
|
|
760
|
+
|
|
761
|
+
//#endregion
|
|
762
|
+
exports.setup = setup;
|