@simon_he/pi
Version:
An intelligent cross-platform package manager and CLI tool that autodetects project environments (Node.mjs, Go, Rust, Python) with beautiful loading animations and smart command execution.
732 lines (710 loc) • 28.8 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
setup: () => setup
});
module.exports = __toCommonJS(index_exports);
var import_node_path2 = __toESM(require("path"), 1);
var import_node_process9 = __toESM(require("process"), 1);
var import_ccommand3 = require("ccommand");
var import_fast_glob = __toESM(require("fast-glob"), 1);
var import_lazy_js_utils2 = require("lazy-js-utils");
var import_node13 = require("lazy-js-utils/node");
var import_picocolors8 = __toESM(require("picocolors"), 1);
// src/help.ts
var import_node_process = __toESM(require("process"), 1);
var import_node = require("lazy-js-utils/node");
// package.json
var version = "0.1.16";
// src/help.ts
var isZh = import_node_process.default.env.PI_Lang === "zh";
async function help(argv) {
const arg = argv[0];
if (arg === "-v" || arg === "--version") {
await (0, import_node.jsShell)(
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}"`,
"inherit"
);
import_node_process.default.exit(0);
} else if (arg === "-h" || arg === "--help") {
await (0, import_node.jsShell)(
`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" "PI Commands:" "~ pi: install package" "~ 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"
`,
"inherit"
);
import_node_process.default.exit(0);
}
}
// src/installDeps.ts
var import_node_process2 = __toESM(require("process"), 1);
var import_node2 = require("lazy-js-utils/node");
var import_picocolors = __toESM(require("picocolors"), 1);
async function installDeps() {
if (!await (0, import_node2.isInstallPkg)("gum")) {
console.log(import_picocolors.default.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56gum..."));
const { status } = await (0, import_node2.jsShell)("brew install gum", [
"inherit",
"pipe",
"inherit"
]);
if (status === 0) {
console.log(import_picocolors.default.cyan("gum \u5B89\u88C5\u6210\u529F!"));
} else {
console.log(
import_picocolors.default.red(
"gum \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/charmbracelet/gum"
)
);
import_node_process2.default.exit(1);
}
}
if (!await (0, import_node2.isInstallPkg)("ni")) {
console.log(import_picocolors.default.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56ni..."));
const { status } = await (0, import_node2.jsShell)("npm i -g @antfu/ni", [
"inherit",
"pipe",
"inherit"
]);
if (status === 0) {
console.log(import_picocolors.default.cyan("ni \u5B89\u88C5\u6210\u529F!"));
} else {
console.log(
import_picocolors.default.red(
"ni \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/antfu/ni"
)
);
import_node_process2.default.exit(1);
}
}
}
// src/pa.ts
var import_node3 = require("lazy-js-utils/node");
function pa() {
return (0, import_node3.jsShell)("na");
}
// src/pi.ts
var import_node_console = require("console");
var import_node_process5 = __toESM(require("process"), 1);
var import_node6 = require("lazy-js-utils/node");
var import_picocolors4 = __toESM(require("picocolors"), 1);
// src/detectNode.ts
var import_node_process3 = __toESM(require("process"), 1);
var import_node4 = require("lazy-js-utils/node");
var import_picocolors2 = __toESM(require("picocolors"), 1);
async function detectNode() {
let pkg;
try {
pkg = await (0, import_node4.getPkg)();
} catch (_) {
const cwd = import_node_process3.default.cwd();
console.log(import_picocolors2.default.red(`\u5F53\u524D\u76EE\u5F55: ${cwd} \u6CA1\u6709package.json\u6587\u4EF6`));
import_node_process3.default.exit(1);
}
if (pkg.engines?.node) {
const isSafe = require("semver").satisfies(
import_node_process3.default.version,
pkg.engines.node
);
if (!isSafe) {
const { result, status } = await (0, import_node4.jsShell)(
`echo "yes
no" | gum filter --placeholder=" \u5F53\u524Dnode\u7248\u672C\u4E0D\u6EE1\u8DB3 ${pkg.engines.node}\uFF0C\u662F\u5426\u5207\u6362node\u7248\u672C"`,
["inherit", "pipe", "inherit"]
);
if (status === 0 && result === "yes") {
await (0, import_node4.jsShell)(
`
current=$(echo $(fnm current))
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")
registery=$(echo \${registery// /} | sed 's/*//g')
if [ $registery ]; then
fnm use \${registery% -*}
fi
`,
["inherit", "pipe", "inherit"]
);
}
}
}
}
// src/utils.ts
var import_node_path = __toESM(require("path"), 1);
var import_node_process4 = __toESM(require("process"), 1);
var import_lazy_js_utils = require("lazy-js-utils");
var import_node5 = require("lazy-js-utils/node");
var import_picocolors3 = __toESM(require("picocolors"), 1);
var DW = /\s-DW/g;
var W = /\s-W/g;
var Dw = /\s-Dw/g;
var w = /\s-w/g;
var D = /\s-D(?!w)/g;
var d = /\s-d(?!w)/g;
var isZh2 = import_node_process4.default.env.PI_Lang === "zh";
async function getParams(params) {
const root = import_node_process4.default.cwd();
try {
switch (await (0, import_node5.getPkgTool)()) {
case "pnpm":
if (!(0, import_lazy_js_utils.isFile)(import_node_path.default.resolve(root, "./pnpm-workspace.yaml"))) {
if (DW.test(params))
return params.replace(DW, " -D");
if (Dw.test(params))
return params.replace(Dw, " -D");
if (W.test(params))
return params.replace(W, "");
if (w.test(params))
return params.replace(w, "");
if (d.test(params))
return params.replace(d, " -D");
}
if ((0, import_lazy_js_utils.isFile)("./pnpm-workspace.yaml")) {
if (D.test(params))
return params.replace(D, " -Dw");
if (d.test(params))
return params.replace(d, " -Dw");
if (!params || Dw.test(params) || w.test(params))
return params;
return `${params} -w`;
}
if (DW.test(params))
return params.replace(DW, " -Dw");
if (W.test(params))
return params.replace(W, " -w");
return params;
case "yarn":
if (!(await (0, import_node5.getPkg)(import_node_path.default.resolve(root, "./package.json")))?.workspaces) {
if (Dw.test(params))
return params.replace(Dw, " -D");
if (DW.test(params))
return params.replace(DW, " -D");
if (W.test(params))
return params.replace(W, "");
if (w.test(params))
return params.replace(w, "");
}
if ((await (0, import_node5.getPkg)())?.workspaces) {
if (D.test(params))
return params.replace(D, " -DW");
if (d.test(params))
return params.replace(d, " -DW");
if (!params || W.test(params) || DW.test(params))
return params;
return `${params} -W`;
}
if (Dw.test(params))
return params.replace(Dw, " -DW");
if (W.test(params))
return params.replace(w, " -W");
return params;
default:
return params;
}
} catch (_) {
console.log(
import_picocolors3.default.red(
`${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()}`
)
);
import_node_process4.default.exit(1);
}
}
async function loading(text, isSilent = false) {
const { color: color4, spinner } = await getStyle();
const ora = (await import("ora")).default;
return ora({
text,
spinner,
color: color4,
isSilent,
discardStdin: true
}).start();
}
async function getStyle() {
const { PI_COLOR: color4 = "yellow", PI_SPINNER: spinner = "star" } = import_node_process4.default.env;
return {
color: color4,
spinner
};
}
async function getLatestVersion(pkg, isZh6 = true) {
const data = [];
for (const p of pkg.replace(/\s+/, " ").split(" ")) {
const [pName, v] = p.split("$");
let { status, result } = await (0, import_node5.jsShell)(`npm view ${pName}`, [
"inherit",
"pipe",
"inherit"
]);
if (status === 0) {
if (result.startsWith("@"))
result = result.slice(1);
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]}`;
data.push(item);
} else {
throw new Error(result);
}
}
return `${data.join(" ")}${isZh6 ? " \u5B89\u88C5\u6210\u529F! \u{1F60A}" : " successfully! \u{1F60A}"}`;
}
// src/pi.ts
var isZh3 = import_node_process5.default.env.PI_Lang === "zh";
async function pi(params, pkg, executor = "ni") {
await detectNode();
const text = pkg ? `Installing ${params} ...` : "Updating dependency ...";
const isLatest = executor === "pil";
const start = Date.now();
let successMsg = "";
if (isLatest) {
successMsg = await getLatestVersion(pkg, isZh3);
} else {
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}";
}
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}";
const isSilent = import_node_process5.default.env.PI_SILENT === "true";
let stdio = isSilent ? "inherit" : ["inherit", "pipe", "inherit"];
let loading_status;
const { PI_DEFAULT, PI_MaxSockets: sockets } = import_node_process5.default.env;
const pkgTool = await (0, import_node6.getPkgTool)();
const maxSockets = sockets || 4;
const install = !params ? "install" : "add";
if (pkgTool === "npm") {
if (PI_DEFAULT) {
executor = `${PI_DEFAULT} ${install}`;
loading_status = await loading(text, isSilent);
} else {
stdio = "inherit";
executor = "ni";
}
} else {
executor = `${pkgTool} ${install}`;
loading_status = await loading(text, isSilent);
}
const newParams = isLatest ? "" : await getParams(params);
const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
console.log(import_picocolors4.default.green(isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`));
let { status, result } = await (0, import_node6.useNodeWorker)({
params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
stdio,
errorExit: false
});
if (result && result.includes("pnpm versions with respective Node.js version support")) {
(0, import_node_console.log)(result);
(0, import_node_console.log)(
import_picocolors4.default.yellow(
isZh3 ? "\u6B63\u5728\u5C1D\u8BD5\u4F7F\u7528 npm \u518D\u6B21\u6267\u884C..." : "Trying to use npm to run again..."
)
);
const { status: newStatus, result: newResult } = await (0, import_node6.jsShell)(
`npm install${newParams ? ` ${newParams}` : runSockets}`,
{
stdio
}
);
status = newStatus;
result = newResult;
}
if (stdio === "inherit")
loading_status = await loading("");
const end = Date.now();
const costTime = (end - start) / 1e3;
successMsg += import_picocolors4.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
if (status === 0) {
loading_status.succeed(import_picocolors4.default.green(successMsg));
} else if (result && result.includes("Not Found - 404")) {
const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
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`;
loading_status.fail(import_picocolors4.default.red(result ? `${failMsg}
${_result}` : failMsg));
} else {
loading_status.fail(import_picocolors4.default.red(result ? `${failMsg}
${result}` : failMsg));
}
if (result) {
const reg = /ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE\u2009 In : No matching version found for\s+([^@]+)/;
const match = result.match(reg);
if (match) {
const dep = match[1];
(0, import_node6.jsShell)(`pi ${dep}@latest`);
}
}
import_node_process5.default.exit();
}
// src/pci.ts
function pci(params, pkg) {
return pi(params, pkg, "nci");
}
// src/pfind.ts
var import_ccommand = require("ccommand");
function pfind(params) {
return (0, import_ccommand.ccommand)(`find ${params}`);
}
// src/pil.ts
var import_node_process6 = __toESM(require("process"), 1);
var import_node7 = require("lazy-js-utils/node");
var import_picocolors5 = __toESM(require("picocolors"), 1);
async function pil(params) {
const { dependencies = {}, devDependencies = {} } = await (0, import_node7.getPkg)();
if (!params) {
const deps = [
...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`),
...Object.keys(devDependencies).map(
(key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`
)
];
const { result: choose, status } = await (0, import_node7.jsShell)(
`echo ${deps.join(
","
)} | sed "s/,/\\n/g" | gum filter --no-limit --strict=false --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."}"`,
{
stdio: ["inherit", "pipe", "inherit"]
}
);
if (status === 130) {
console.log(import_picocolors5.default.dim("\u5DF2\u53D6\u6D88"));
import_node_process6.default.exit(0);
} else if (status !== 0) {
throw new Error(choose);
}
const names = choose.trim().split("\n").map((i) => {
const name = i.split(": ")[0];
if (name in devDependencies)
return `${name}@latest -D`;
return `${name}@latest -S`;
});
params = names.join(" ");
}
let latestPkgname = params;
const reg = /\s(-[dws]+)/gi;
const suffix = [];
const command = latestPkgname = (await getParams(params)).replace(
reg,
(_, k) => {
suffix.push(k);
return "";
}
);
latestPkgname = latestPkgname.replace(/@latest/g, "").split(" ").filter(Boolean).map((i) => {
const v = dependencies[i] || devDependencies[i];
return `${i}$${v}`;
}).join(" ");
const group = {};
const items = command.replace(/\s+/, " ").trim().split(" ").map((i, idx) => [i, suffix[idx] || "-s"]);
for (const [pkg, flag] of items) {
if (!group[flag])
group[flag] = [];
group[flag].push(pkg);
}
const cmds = Object.entries(group).map(([flag, pkgs]) => `${pkgs.join(" ")} ${flag}`);
return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
}
// src/pinit.ts
var import_node8 = require("lazy-js-utils/node");
async function pinit() {
console.log("Initializing project...");
switch (await (0, import_node8.getPkgTool)()) {
case "npm":
(0, import_node8.jsShell)("npm init -y");
return;
case "yarn":
(0, import_node8.jsShell)("yarn init -y");
return;
case "pnpm":
(0, import_node8.jsShell)("pnpm init -y");
return;
default:
(0, import_node8.jsShell)("npm init -y");
}
}
// src/pio.ts
var import_node_process7 = __toESM(require("process"), 1);
var import_node9 = require("lazy-js-utils/node");
var import_picocolors6 = __toESM(require("picocolors"), 1);
async function pio(params, pkg, executor = "ni") {
const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
const offline = "--prefer-offline";
const newParams = await getParams(params);
const { status, result } = await (0, import_node9.useNodeWorker)({
params: `${executor} ${newParams} ${offline}`,
stdio: "inherit"
});
const loading_status = await loading("");
if (status === 0)
loading_status.succeed(import_picocolors6.default.green(successMsg));
else
loading_status.fail(import_picocolors6.default.red(result ? `${result}
${failMsg}` : failMsg));
import_node_process7.default.exit();
}
// src/pix.ts
var import_node10 = require("lazy-js-utils/node");
async function pix(params) {
switch (await (0, import_node10.getPkgTool)()) {
case "bun":
return (0, import_node10.jsShell)(`bunx ${params}`);
default:
return (0, import_node10.jsShell)(`npx ${params}`);
}
}
// src/prun.ts
var import_ccommand2 = require("ccommand");
function prun(params) {
return (0, import_ccommand2.ccommand)(params);
}
// src/pu.ts
var import_node11 = require("lazy-js-utils/node");
function pu() {
return (0, import_node11.jsShell)("nu");
}
// src/pui.ts
var import_node_process8 = __toESM(require("process"), 1);
var import_node12 = require("lazy-js-utils/node");
var import_picocolors7 = __toESM(require("picocolors"), 1);
var isZh4 = import_node_process8.default.env.PI_Lang === "zh";
async function pui(params, pkg) {
const text = `${isZh4 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${pkg} ...`;
if (!params) {
const { dependencies = {}, devDependencies = {} } = await (0, import_node12.getPkg)();
const deps = [
...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key]}`),
...Object.keys(devDependencies).map(
(key) => `${key}: ${devDependencies[key]}`
)
];
const { result: choose, status: status2 } = await (0, import_node12.jsShell)(
`echo ${deps.join(
","
)} | 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."}"`,
["inherit", "pipe", "inherit"]
);
if (status2 === 130) {
console.log(import_picocolors7.default.dim("\u5DF2\u53D6\u6D88"));
import_node_process8.default.exit(0);
} else if (status2 !== 0) {
throw new Error(choose);
}
pkg = params = choose.split(": ")[0];
}
const start = Date.now();
let successMsg = isZh4 ? `${pkg}\u5378\u8F7D\u6210\u529F! \u{1F60A}` : `UnInstalled ${pkg} successfully! \u{1F60A}`;
const failMsg = isZh4 ? `${pkg}\u5378\u8F7D\u5931\u8D25 \u{1F62D}` : `Failed to uninstall ${pkg} \u{1F62D}`;
if (!pkg) {
console.log(
import_picocolors7.default.yellow(
isZh4 ? "\u9700\u8981\u6307\u5B9A\u8981\u5378\u8F7D\u7684\u5305\u540D\uFF01" : "Need to specify an uninstall package name!"
)
);
import_node_process8.default.exit(1);
}
const loading_status = await loading(text);
const { status, result } = await (0, import_node12.useNodeWorker)(`nun ${params}`);
const end = Date.now();
const costTime = (end - start) / 1e3;
successMsg += import_picocolors7.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
if (status === 0)
loading_status.succeed(import_picocolors7.default.green(successMsg));
else
loading_status.fail(import_picocolors7.default.red(result ? `${failMsg}
${result}` : failMsg));
import_node_process8.default.exit();
}
// src/index.ts
var rootPath = import_node_process9.default.cwd();
var runMap = {
pi,
"pi.mjs": pi,
pix,
"pix.mjs": pix,
pa,
"pa.mjs": pa,
pui,
"pui.mjs": pui,
pu,
"pu.mjs": pu,
pil,
"pil.mjs": pil,
pci,
"pci.mjs": pci,
prun,
"prun.mjs": prun,
pinit,
"pinit.mjs": pinit,
pfind,
"pfind.mjs": pfind,
pio,
"pio.mjs": pio
};
var isZh5 = import_node_process9.default.env.PI_Lang === "zh";
async function setup() {
const cmd = import_node_process9.default.argv[1];
let exec = "";
if ((0, import_lazy_js_utils2.isWin)()) {
const last = cmd.lastIndexOf("\\") + 1;
exec = cmd.slice(last, cmd.length).split(".").slice(0, -1).join(".");
} else {
const last = cmd.lastIndexOf("/") + 1;
exec = cmd.slice(last, cmd.length);
}
const argv = import_node_process9.default.argv.slice(2);
await help(argv);
let params = (0, import_lazy_js_utils2.spaceFormat)(argv.join(" ")).trim();
if (!await (0, import_node13.hasPkg)(rootPath)) {
if (await (0, import_node13.isGo)(rootPath)) {
if (exec === "pi") {
const loading_status = await loading(
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
`
);
const { status } = params ? await (0, import_node13.useNodeWorker)(`go get ${params}`) : await (0, import_node13.useNodeWorker)("go mod tidy");
if (status === 0) {
loading_status.succeed(
import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
);
} else {
loading_status.fail(
import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
);
}
} else if (exec === "pui") {
const loading_status = await loading(
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
`
);
const { status } = await (0, import_node13.useNodeWorker)(`go clean ${params}`);
if (status === 0) {
loading_status.succeed(
import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
);
} else {
loading_status.fail(
import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
);
}
} else if (exec === "prun") {
const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
const target = (await (0, import_fast_glob.default)(match))[0];
return target ? await (0, import_node13.jsShell)(`go run ${target}`, "inherit") : (0, import_ccommand3.ccommand)(params);
} else if (exec === "pinit") {
await (0, import_node13.jsShell)(`go mod init ${params}`, "inherit");
} else if (exec === "pbuild") {
await (0, import_node13.jsShell)(`go build ${params}`, "inherit");
} else {
console.log(
import_picocolors8.default.red(
isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
)
);
}
import_node_process9.default.exit();
}
let projectPath = "";
if (params && !await (0, import_node13.isRust)()) {
projectPath = params.split(" ")[0];
rootPath = import_node_path2.default.resolve(rootPath, projectPath);
params = params.replace(projectPath, "").trim();
}
if (await (0, import_node13.isRust)(rootPath)) {
if (exec === "pi") {
const loading_status = await loading(
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
`
);
const { status } = await (0, import_node13.useNodeWorker)(
`cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
);
if (status === 0) {
loading_status.succeed(
import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
);
} else {
loading_status.fail(
import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
);
}
} else if (exec === "pui") {
const loading_status = await loading(
`${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
`
);
const { status } = await (0, import_node13.useNodeWorker)(
`cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
);
if (status === 0) {
loading_status.succeed(
import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
);
} else {
loading_status.fail(
import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
);
}
} else if (exec === "prun") {
await (0, import_node13.jsShell)(
`cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
"inherit"
);
} else if (exec === "pinit") {
await (0, import_node13.jsShell)(
`cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
"inherit"
);
} else if (exec === "pbuild") {
await (0, import_node13.jsShell)(
`cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
"inherit"
);
} else {
console.log(
import_picocolors8.default.red(
isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
)
);
}
import_node_process9.default.exit();
}
if (!runMap[exec]) {
console.log(
import_picocolors8.default.yellow(
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"
)
);
return;
}
}
const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
await installDeps();
runMap[exec](params, pkg);
}
setup();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
setup
});