@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 CHANGED
@@ -1,933 +1,762 @@
1
- "use strict";
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
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
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
- // src/help.ts
45
- var import_node_process = __toESM(require("process"), 1);
46
- var import_node = require("lazy-js-utils/node");
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
- // package.json
49
- var version = "0.1.20";
46
+ //#region package.json
47
+ var version = "0.1.22";
50
48
 
51
- // src/help.ts
52
- var isZh = import_node_process.default.env.PI_Lang === "zh";
53
- async function help(argv) {
54
- const arg = argv[0];
55
- if (arg === "-v" || arg === "--version") {
56
- await (0, import_node.jsShell)(
57
- isZh ? `gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" "pi \u7248\u672C: ${version}" "\u8BF7\u4E3A\u6211\u7684\u52AA\u529B\u70B9\u4E00\u4E2A\u884C \u{1F31F}" "\u8C22\u8C22 \u{1F91F}"` : `gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" "pi version: ${version}" "Please give me a \u{1F31F} for my efforts" "Thank you \u{1F91F}"`,
58
- "inherit"
59
- );
60
- import_node_process.default.exit(0);
61
- } else if (arg === "-h" || arg === "--help") {
62
- await (0, import_node.jsShell)(
63
- `gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" "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"
64
- `,
65
- "inherit"
66
- );
67
- import_node_process.default.exit(0);
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
- // src/installDeps.ts
72
- var import_node_process2 = __toESM(require("process"), 1);
73
- var import_node2 = require("lazy-js-utils/node");
74
- var import_picocolors = __toESM(require("picocolors"), 1);
75
- async function installDeps() {
76
- if (!await (0, import_node2.isInstallPkg)("gum")) {
77
- console.log(import_picocolors.default.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56gum..."));
78
- const { status } = await (0, import_node2.jsShell)("brew install gum", [
79
- "inherit",
80
- "pipe",
81
- "inherit"
82
- ]);
83
- if (status === 0) {
84
- console.log(import_picocolors.default.cyan("gum \u5B89\u88C5\u6210\u529F!"));
85
- } else {
86
- console.log(
87
- import_picocolors.default.red(
88
- "gum \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/charmbracelet/gum"
89
- )
90
- );
91
- import_node_process2.default.exit(1);
92
- }
93
- }
94
- if (!await (0, import_node2.isInstallPkg)("ni")) {
95
- console.log(import_picocolors.default.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56ni..."));
96
- const { status } = await (0, import_node2.jsShell)("npm i -g @antfu/ni", [
97
- "inherit",
98
- "pipe",
99
- "inherit"
100
- ]);
101
- if (status === 0) {
102
- console.log(import_picocolors.default.cyan("ni \u5B89\u88C5\u6210\u529F!"));
103
- } else {
104
- console.log(
105
- import_picocolors.default.red(
106
- "ni \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/antfu/ni"
107
- )
108
- );
109
- import_node_process2.default.exit(1);
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
- // src/pa.ts
115
- var import_node3 = require("lazy-js-utils/node");
141
+ //#endregion
142
+ //#region src/pa.ts
116
143
  function pa() {
117
- return (0, import_node3.jsShell)("na");
144
+ return (0, lazy_js_utils_node.jsShell)("na");
118
145
  }
119
146
 
120
- // src/pi.ts
121
- var import_node_console = require("console");
122
- var import_node_process5 = __toESM(require("process"), 1);
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
- let pkg;
132
- try {
133
- pkg = await (0, import_node4.getPkg)();
134
- } catch {
135
- const cwd = import_node_process3.default.cwd();
136
- console.log(import_picocolors2.default.red(`\u5F53\u524D\u76EE\u5F55: ${cwd} \u6CA1\u6709package.json\u6587\u4EF6`));
137
- import_node_process3.default.exit(1);
138
- }
139
- if (pkg.engines?.node) {
140
- const isSafe = require("semver").satisfies(
141
- import_node_process3.default.version,
142
- pkg.engines.node
143
- );
144
- if (!isSafe) {
145
- const { result, status } = await (0, import_node4.jsShell)(
146
- `echo "yes
147
- no" | gum filter --placeholder=" \u5F53\u524Dnode\u7248\u672C\u4E0D\u6EE1\u8DB3 ${pkg.engines.node}\uFF0C\u662F\u5426\u5207\u6362node\u7248\u672C"`,
148
- ["inherit", "pipe", "inherit"]
149
- );
150
- if (status === 0 && result === "yes") {
151
- await (0, import_node4.jsShell)(
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/* //g' | sed "s/$current/* $current/g" | gum filter --placeholder=" \u8BF7\u9009\u62E9\u4E00\u4E2Anode\u7248\u672C")
155
- registery=$(echo \${registery// /} | sed 's/*//g')
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 \${registery% -*}
181
+ fnm use $\{registery% -*}
158
182
  fi
159
- `,
160
- ["inherit", "pipe", "inherit"]
161
- );
162
- }
163
- }
164
- }
183
+ `, [
184
+ "inherit",
185
+ "pipe",
186
+ "inherit"
187
+ ]);
188
+ }
189
+ }
165
190
  }
166
191
 
167
- // src/utils.ts
168
- var import_node_fs = __toESM(require("fs"), 1);
169
- var import_node_os = __toESM(require("os"), 1);
170
- var import_node_path = __toESM(require("path"), 1);
171
- var import_node_process4 = __toESM(require("process"), 1);
172
- var import_lazy_js_utils = require("lazy-js-utils");
173
- var import_node5 = require("lazy-js-utils/node");
174
- var import_picocolors3 = __toESM(require("picocolors"), 1);
175
- var DW = /\s-DW/g;
176
- var W = /\s-W/g;
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
- const root = import_node_process4.default.cwd();
185
- try {
186
- switch (await (0, import_node5.getPkgTool)()) {
187
- case "pnpm":
188
- if (!(0, import_lazy_js_utils.isFile)(import_node_path.default.resolve(root, "./pnpm-workspace.yaml"))) {
189
- if (DW.test(params))
190
- return params.replace(DW, " -D");
191
- if (Dw.test(params))
192
- return params.replace(Dw, " -D");
193
- if (W.test(params))
194
- return params.replace(W, "");
195
- if (w.test(params))
196
- return params.replace(w, "");
197
- if (d.test(params))
198
- return params.replace(d, " -D");
199
- }
200
- if ((0, import_lazy_js_utils.isFile)("./pnpm-workspace.yaml")) {
201
- if (D.test(params))
202
- return params.replace(D, " -Dw");
203
- if (d.test(params))
204
- return params.replace(d, " -Dw");
205
- if (!params || Dw.test(params) || w.test(params))
206
- return params;
207
- return `${params} -w`;
208
- }
209
- if (DW.test(params))
210
- return params.replace(DW, " -Dw");
211
- if (W.test(params))
212
- return params.replace(W, " -w");
213
- return params;
214
- case "yarn":
215
- if (!(await (0, import_node5.getPkg)(import_node_path.default.resolve(root, "./package.json")))?.workspaces) {
216
- if (Dw.test(params))
217
- return params.replace(Dw, " -D");
218
- if (DW.test(params))
219
- return params.replace(DW, " -D");
220
- if (W.test(params))
221
- return params.replace(W, "");
222
- if (w.test(params))
223
- return params.replace(w, "");
224
- if (d.test(params))
225
- return params.replace(d, " -D");
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
- const { color: color4, spinner } = await getStyle();
255
- const ora = (await import("ora")).default;
256
- return ora({
257
- text,
258
- spinner,
259
- color: color4,
260
- isSilent,
261
- discardStdin: true
262
- }).start();
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
- const { PI_COLOR: color4 = "yellow", PI_SPINNER: spinner = "star" } = import_node_process4.default.env;
266
- return {
267
- color: color4,
268
- spinner
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, isZh6 = true) {
272
- const data = [];
273
- for (const p of pkg.replace(/\s+/, " ").split(" ")) {
274
- const [pName, v] = p.split("$");
275
- let { status, result } = await (0, import_node5.jsShell)(`npm view ${pName}`, [
276
- "inherit",
277
- "pipe",
278
- "inherit"
279
- ]);
280
- if (status === 0) {
281
- if (result.startsWith("@"))
282
- result = result.slice(1);
283
- const item = isZh6 ? `${pName} ${import_picocolors3.default.gray(v)} -> ${result.match(/@(\S+)/)[1]}` : `Installed ${pName} ${import_picocolors3.default.dim(v)} -> latest version\uFF1A${result.match(/@(\S+)/)[1]}`;
284
- data.push(item);
285
- } else {
286
- throw new Error(result);
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
- log(
293
- import_picocolors3.default.bold(
294
- import_picocolors3.default.blue(`${isZh2 ? "\u5FEB\u6377\u6307\u4EE4" : "shortcut command"}: ${command}`)
295
- )
296
- );
297
- const currentShell = import_node_process4.default.env.SHELL || "/bin/bash";
298
- const shellName = currentShell.split("/").pop() || "bash";
299
- let historyFile = "";
300
- let historyFormat = "bash";
301
- const home = import_node_process4.default.env.HOME || import_node_os.default.homedir();
302
- switch (shellName) {
303
- case "zsh":
304
- historyFile = import_node_path.default.join(home, ".zsh_history");
305
- historyFormat = "zsh";
306
- break;
307
- case "bash":
308
- historyFile = import_node_process4.default.env.HISTFILE || import_node_path.default.join(home, ".bash_history");
309
- historyFormat = "bash";
310
- break;
311
- case "fish":
312
- historyFile = import_node_path.default.join(home, ".local", "share", "fish", "fish_history");
313
- historyFormat = "fish";
314
- break;
315
- default:
316
- historyFile = import_node_process4.default.env.HISTFILE || import_node_path.default.join(home, ".bash_history");
317
- historyFormat = "bash";
318
- }
319
- try {
320
- let parseEntries2 = function(content) {
321
- if (historyFormat === "fish") {
322
- const lines = content.split(/\r?\n/);
323
- const blocks = [];
324
- let buffer = [];
325
- for (const line of lines) {
326
- if (line.startsWith("- cmd: ")) {
327
- if (buffer.length) {
328
- blocks.push(buffer.join("\n"));
329
- buffer = [];
330
- }
331
- buffer.push(line);
332
- } else if (buffer.length) {
333
- buffer.push(line);
334
- } else if (line.trim() !== "") {
335
- blocks.push(line);
336
- }
337
- }
338
- if (buffer.length)
339
- blocks.push(buffer.join("\n"));
340
- return blocks.filter(Boolean);
341
- } else if (historyFormat === "zsh") {
342
- return content.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
343
- } else {
344
- const lines = content.split(/\r?\n/);
345
- const entries2 = [];
346
- for (let i = 0; i < lines.length; i++) {
347
- const line = lines[i];
348
- if (line.startsWith("#")) {
349
- const next = lines[i + 1] ?? "";
350
- entries2.push(`${line}
351
- ${next}`);
352
- i++;
353
- } else if (line.trim() !== "") {
354
- entries2.push(line);
355
- }
356
- }
357
- return entries2;
358
- }
359
- }, extractCommand2 = function(entry) {
360
- if (historyFormat === "fish") {
361
- const m = entry.split("\n")[0].match(/^- cmd: (.*)$/);
362
- return m ? m[1] : entry;
363
- } else if (historyFormat === "zsh") {
364
- const m = entry.match(/^[^;]*;(.+)$/);
365
- return m ? m[1] : entry;
366
- } else {
367
- if (entry.startsWith("#")) {
368
- const parts = entry.split(/\r?\n/);
369
- return parts[1] ?? parts[0];
370
- }
371
- return entry;
372
- }
373
- };
374
- var parseEntries = parseEntries2, extractCommand = extractCommand2;
375
- if (!import_node_fs.default.existsSync(historyFile)) {
376
- log(
377
- import_picocolors3.default.yellow(
378
- `${isZh2 ? `\u672A\u627E\u5230 ${shellName} \u5386\u53F2\u6587\u4EF6` : `${shellName} history file not found`}`
379
- )
380
- );
381
- return;
382
- }
383
- const raw = import_node_fs.default.readFileSync(historyFile, "utf8");
384
- const timestamp = Math.floor(Date.now() / 1e3);
385
- let newEntry = "";
386
- if (historyFormat === "zsh") {
387
- newEntry = `: ${timestamp}:0;${command}`;
388
- } else if (historyFormat === "fish") {
389
- newEntry = `- cmd: ${command}
390
- when: ${timestamp}`;
391
- } else {
392
- if (import_node_process4.default.env.HISTTIMEFORMAT) {
393
- newEntry = `#${timestamp}
394
- ${command}`;
395
- } else {
396
- newEntry = command;
397
- }
398
- }
399
- const entries = parseEntries2(raw);
400
- const newEntries = [];
401
- const newCmd = extractCommand2(newEntry);
402
- let existingFishBlock = null;
403
- for (const e of entries) {
404
- const cmd = extractCommand2(e);
405
- if (cmd === newCmd) {
406
- if (historyFormat === "fish") {
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
- // src/pi.ts
452
- var isZh3 = import_node_process5.default.env.PI_Lang === "zh";
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
- await detectNode();
455
- const text = pkg ? `Installing ${params} ...` : "Updating dependency ...";
456
- const isLatest = executor === "pil";
457
- const start = Date.now();
458
- let successMsg = "";
459
- if (isLatest) {
460
- successMsg = await getLatestVersion(pkg, isZh3);
461
- } else {
462
- successMsg = pkg ? isZh3 ? `${pkg} \u5B89\u88C5\u6210\u529F! \u{1F60A}` : `Installed ${pkg} successfully! \u{1F60A}` : isZh3 ? "\u4F9D\u8D56\u66F4\u65B0\u6210\u529F! \u{1F60A}" : "Updated dependency successfully! \u{1F60A}";
463
- }
464
- const failMsg = pkg ? isZh3 ? `${params} \u5B89\u88C5\u5931\u8D25 \u{1F62D}` : `Failed to install ${params} \u{1F62D}` : isZh3 ? "\u4F9D\u8D56\u66F4\u65B0\u5931\u8D25 \u{1F62D}" : "Failed to update dependency \u{1F62D}";
465
- const isSilent = import_node_process5.default.env.PI_SILENT === "true";
466
- let stdio = isSilent ? "inherit" : ["inherit", "pipe", "inherit"];
467
- let loading_status;
468
- const { PI_DEFAULT, PI_MaxSockets: sockets } = import_node_process5.default.env;
469
- const pkgTool = await (0, import_node6.getPkgTool)();
470
- const maxSockets = sockets || 4;
471
- const install = !params ? "install" : "add";
472
- if (pkgTool === "npm") {
473
- if (PI_DEFAULT) {
474
- executor = `${PI_DEFAULT} ${install}`;
475
- loading_status = await loading(text, isSilent);
476
- } else {
477
- stdio = "inherit";
478
- executor = "ni";
479
- }
480
- } else {
481
- executor = `${pkgTool} ${install}`;
482
- loading_status = await loading(text, isSilent);
483
- }
484
- const newParams = isLatest ? "" : await getParams(params);
485
- const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
486
- const runCmd = isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`;
487
- let { status, result } = await (0, import_node6.useNodeWorker)({
488
- params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
489
- stdio,
490
- errorExit: false
491
- });
492
- if (result && result.includes("pnpm versions with respective Node.js version support")) {
493
- (0, import_node_console.log)(result);
494
- (0, import_node_console.log)(
495
- import_picocolors4.default.yellow(
496
- isZh3 ? "\u6B63\u5728\u5C1D\u8BD5\u4F7F\u7528 npm \u518D\u6B21\u6267\u884C..." : "Trying to use npm to run again..."
497
- )
498
- );
499
- const { status: newStatus, result: newResult } = await (0, import_node6.jsShell)(
500
- `npm install${newParams ? ` ${newParams}` : runSockets}`,
501
- {
502
- stdio
503
- }
504
- );
505
- status = newStatus;
506
- result = newResult;
507
- }
508
- if (stdio === "inherit")
509
- loading_status = await loading("");
510
- const end = Date.now();
511
- const costTime = (end - start) / 1e3;
512
- successMsg += import_picocolors4.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
513
- if (status === 0) {
514
- loading_status.succeed(import_picocolors4.default.green(successMsg));
515
- pushHistory(runCmd);
516
- } else if (result && result.includes("Not Found - 404")) {
517
- const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
518
- const _result = isZh3 ? `${_pkg} \u5305\u540D\u53EF\u80FD\u6709\u8BEF\u6216\u8005\u7248\u672C\u53F7\u4E0D\u5B58\u5728\uFF0C\u5E76\u4E0D\u80FD\u5728npm\u4E2D\u641C\u7D22\u5230\uFF0C\u8BF7\u68C0\u67E5` : `${_pkg} the package name may be wrong, and cannot be found in npm, please check`;
519
- loading_status.fail(import_picocolors4.default.red(result ? `${failMsg}
520
- ${_result}` : failMsg));
521
- } else {
522
- loading_status.fail(import_picocolors4.default.red(result ? `${failMsg}
523
- ${result}` : failMsg));
524
- }
525
- if (result) {
526
- const reg = /ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE\u2009 In : No matching version found for\s+([^@]+)/;
527
- const match = result.match(reg);
528
- if (match) {
529
- const dep = match[1];
530
- (0, import_node6.jsShell)(`pi ${dep}@latest`);
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
- // src/pci.ts
484
+ //#endregion
485
+ //#region src/pci.ts
537
486
  function pci(params, pkg) {
538
- return pi(params, pkg, "nci");
487
+ return pi(params, pkg, "nci");
539
488
  }
540
489
 
541
- // src/pfind.ts
542
- var import_ccommand = require("ccommand");
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
- return (0, import_ccommand.ccommand)(`find ${params}`);
498
+ const { ccommand } = localRequire("ccommand");
499
+ return ccommand(`find ${params}`);
545
500
  }
546
501
 
547
- // src/pil.ts
548
- var import_node_process6 = __toESM(require("process"), 1);
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
- const { dependencies = {}, devDependencies = {} } = await (0, import_node7.getPkg)();
553
- if (!params) {
554
- const deps = [
555
- ...Object.keys(dependencies).map(
556
- (key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`
557
- ),
558
- ...Object.keys(devDependencies).map(
559
- (key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`
560
- )
561
- ];
562
- const { result: choose, status } = await (0, import_node7.jsShell)(
563
- `echo ${deps.join(
564
- ","
565
- )} | sed "s/,/\\n/g" | gum filter --no-limit --placeholder=" \u{1F914}${import_node_process6.default.env.PI_Lang === "zh" ? "\u8BF7\u9009\u62E9\u4E00\u4E2A\u9700\u8981\u83B7\u53D6\u6700\u65B0\u7248\u672C\u7684\u4F9D\u8D56" : "Please select a dependency that needs to obtain the latest version."}"`,
566
- {
567
- stdio: ["inherit", "pipe", "inherit"]
568
- }
569
- );
570
- if (status === 130) {
571
- console.log(import_picocolors5.default.dim("\u5DF2\u53D6\u6D88"));
572
- import_node_process6.default.exit(0);
573
- } else if (status !== 0) {
574
- throw new Error(choose);
575
- }
576
- const names = choose.trim().split("\n").map((i) => {
577
- const name = i.split(": ")[0];
578
- if (name in devDependencies)
579
- return `${name}@latest -D`;
580
- return `${name}@latest -S`;
581
- });
582
- params = names.join(" ");
583
- }
584
- let latestPkgname = params;
585
- const reg = /\s(-[dws]+)/gi;
586
- const suffix = [];
587
- const command = latestPkgname = (await getParams(params)).replace(
588
- reg,
589
- (_, k) => {
590
- suffix.push(k);
591
- return "";
592
- }
593
- );
594
- latestPkgname = latestPkgname.replace(/@latest/g, "").split(" ").filter(Boolean).map((i) => {
595
- const v = dependencies[i] || devDependencies[i];
596
- return `${i}$${v}`;
597
- }).join(" ");
598
- const tokens = command.replace(/\s+/, " ").trim().split(" ").filter(Boolean);
599
- const pkgs = tokens.filter((t) => !t.startsWith("-"));
600
- let globalWorkspaceFlag = null;
601
- const perFlags = [];
602
- let assignIdx = 0;
603
- for (const f of suffix) {
604
- if (/^-(?:w|W)$/.test(f)) {
605
- globalWorkspaceFlag = f;
606
- continue;
607
- }
608
- perFlags[assignIdx++] = f;
609
- }
610
- const normalizeFlag = (f) => {
611
- if (!f)
612
- return "";
613
- if (/^-s$/i.test(f) || /^-S$/.test(f))
614
- return "";
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
- // src/pinit.ts
645
- var import_node8 = require("lazy-js-utils/node");
570
+ //#endregion
571
+ //#region src/pinit.ts
646
572
  async function pinit() {
647
- console.log("Initializing project...");
648
- switch (await (0, import_node8.getPkgTool)()) {
649
- case "npm":
650
- (0, import_node8.jsShell)("npm init -y");
651
- return;
652
- case "yarn":
653
- (0, import_node8.jsShell)("yarn init -y");
654
- return;
655
- case "pnpm":
656
- (0, import_node8.jsShell)("pnpm init -y");
657
- return;
658
- default:
659
- (0, import_node8.jsShell)("npm init -y");
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
- // src/pio.ts
664
- var import_node_process7 = __toESM(require("process"), 1);
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
- const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
669
- const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
670
- const offline = "--prefer-offline";
671
- const newParams = await getParams(params);
672
- const { status, result } = await (0, import_node9.useNodeWorker)({
673
- params: `${executor} ${newParams} ${offline}`,
674
- stdio: "inherit"
675
- });
676
- const loading_status = await loading("");
677
- if (status === 0)
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
- // src/pix.ts
687
- var import_node10 = require("lazy-js-utils/node");
603
+ //#endregion
604
+ //#region src/pix.ts
688
605
  async function pix(params) {
689
- switch (await (0, import_node10.getPkgTool)()) {
690
- case "bun":
691
- return (0, import_node10.jsShell)(`bunx ${params}`);
692
- default:
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
- // src/prun.ts
698
- var import_ccommand2 = require("ccommand");
612
+ //#endregion
613
+ //#region src/prun.ts
699
614
  function prun(params) {
700
- return (0, import_ccommand2.ccommand)(params);
615
+ const { ccommand } = localRequire("ccommand");
616
+ return ccommand(params);
701
617
  }
702
618
 
703
- // src/pu.ts
704
- var import_node11 = require("lazy-js-utils/node");
619
+ //#endregion
620
+ //#region src/pu.ts
705
621
  function pu() {
706
- return (0, import_node11.jsShell)("nu");
622
+ return (0, lazy_js_utils_node.jsShell)("nu");
707
623
  }
708
624
 
709
- // src/pui.ts
710
- var import_node_process8 = __toESM(require("process"), 1);
711
- var import_node12 = require("lazy-js-utils/node");
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
- const text = `${isZh4 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${pkg} ...`;
716
- if (!params) {
717
- const { dependencies = {}, devDependencies = {} } = await (0, import_node12.getPkg)();
718
- const deps = [
719
- ...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key]}`),
720
- ...Object.keys(devDependencies).map(
721
- (key) => `${key}: ${devDependencies[key]}`
722
- )
723
- ];
724
- const { result: choose, status: status2 } = await (0, import_node12.jsShell)(
725
- `echo ${deps.join(
726
- ","
727
- )} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${import_node_process8.default.env.PI_Lang === "zh" ? "\u8BF7\u9009\u62E9\u4E00\u4E2A\u9700\u8981\u5220\u9664\u4F9D\u8D56" : "Please select a dependency to get the latest version."}"`,
728
- ["inherit", "pipe", "inherit"]
729
- );
730
- if (status2 === 130) {
731
- console.log(import_picocolors7.default.dim("\u5DF2\u53D6\u6D88"));
732
- import_node_process8.default.exit(0);
733
- } else if (status2 !== 0) {
734
- throw new Error(choose);
735
- }
736
- pkg = params = choose.split(": ")[0];
737
- }
738
- const start = Date.now();
739
- let successMsg = isZh4 ? `${pkg}\u5378\u8F7D\u6210\u529F! \u{1F60A}` : `UnInstalled ${pkg} successfully! \u{1F60A}`;
740
- const failMsg = isZh4 ? `${pkg}\u5378\u8F7D\u5931\u8D25 \u{1F62D}` : `Failed to uninstall ${pkg} \u{1F62D}`;
741
- if (!pkg) {
742
- console.log(
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
- // src/index.ts
763
- var rootPath = import_node_process9.default.cwd();
764
- var runMap = {
765
- pi,
766
- "pi.mjs": pi,
767
- pix,
768
- "pix.mjs": pix,
769
- pa,
770
- "pa.mjs": pa,
771
- pui,
772
- "pui.mjs": pui,
773
- pu,
774
- "pu.mjs": pu,
775
- pil,
776
- "pil.mjs": pil,
777
- pci,
778
- "pci.mjs": pci,
779
- prun,
780
- "prun.mjs": prun,
781
- pinit,
782
- "pinit.mjs": pinit,
783
- pfind,
784
- "pfind.mjs": pfind,
785
- pio,
786
- "pio.mjs": pio
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
- var isZh5 = import_node_process9.default.env.PI_Lang === "zh";
686
+ const isZh = node_process.default.env.PI_Lang === "zh";
789
687
  async function setup() {
790
- const cmd = import_node_process9.default.argv[1];
791
- let exec = "";
792
- if ((0, import_lazy_js_utils2.isWin)()) {
793
- const last = cmd.lastIndexOf("\\") + 1;
794
- exec = cmd.slice(last, cmd.length).split(".").slice(0, -1).join(".");
795
- } else {
796
- const last = cmd.lastIndexOf("/") + 1;
797
- exec = cmd.slice(last, cmd.length);
798
- }
799
- const argv = import_node_process9.default.argv.slice(2);
800
- await help(argv);
801
- let params = (0, import_lazy_js_utils2.spaceFormat)(argv.join(" ")).trim();
802
- if (!await (0, import_node13.hasPkg)(rootPath)) {
803
- if (await (0, import_node13.isGo)(rootPath)) {
804
- if (exec === "pi") {
805
- const loading_status = await loading(
806
- `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
807
- `
808
- );
809
- const { status } = params ? await (0, import_node13.useNodeWorker)(`go get ${params}`) : await (0, import_node13.useNodeWorker)("go mod tidy");
810
- if (status === 0) {
811
- loading_status.succeed(
812
- import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
813
- );
814
- } else {
815
- loading_status.fail(
816
- import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
817
- );
818
- }
819
- } else if (exec === "pui") {
820
- const loading_status = await loading(
821
- `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
822
- `
823
- );
824
- const { status } = await (0, import_node13.useNodeWorker)(`go clean ${params}`);
825
- if (status === 0) {
826
- loading_status.succeed(
827
- import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
828
- );
829
- } else {
830
- loading_status.fail(
831
- import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
832
- );
833
- }
834
- } else if (exec === "prun") {
835
- const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
836
- const target = (await (0, import_fast_glob.default)(match))[0];
837
- return target ? await (0, import_node13.jsShell)(`go run ${target}`, "inherit") : (0, import_ccommand3.ccommand)(params);
838
- } else if (exec === "pinit") {
839
- await (0, import_node13.jsShell)(`go mod init ${params}`, "inherit");
840
- } else if (exec === "pbuild") {
841
- await (0, import_node13.jsShell)(`go build ${params}`, "inherit");
842
- } else {
843
- console.log(
844
- import_picocolors8.default.red(
845
- isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
846
- )
847
- );
848
- }
849
- import_node_process9.default.exit();
850
- }
851
- let projectPath = "";
852
- if (params && !await (0, import_node13.isRust)()) {
853
- projectPath = params.split(" ")[0];
854
- rootPath = import_node_path2.default.resolve(rootPath, projectPath);
855
- params = params.replace(projectPath, "").trim();
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
- // Annotate the CommonJS export names for ESM import in node:
931
- 0 && (module.exports = {
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;