UNPKG

@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.

710 lines (688 loc) 25 kB
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw Error('Dynamic require of "' + x + '" is not supported'); }); // src/index.ts import path2 from "node:path"; import process9 from "node:process"; import { ccommand as ccommand3 } from "ccommand"; import fg from "fast-glob"; import { isWin, spaceFormat } from "lazy-js-utils"; import { hasPkg, isGo, isRust, jsShell as jsShell12, useNodeWorker as useNodeWorker4 } from "lazy-js-utils/node"; import color3 from "picocolors"; // src/help.ts import process from "node:process"; import { jsShell } from "lazy-js-utils/node"; // package.json var version = "0.1.16"; // src/help.ts var isZh = process.env.PI_Lang === "zh"; async function help(argv) { const arg = argv[0]; if (arg === "-v" || arg === "--version") { await 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" ); process.exit(0); } else if (arg === "-h" || arg === "--help") { await 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" ); process.exit(0); } } // src/installDeps.ts import process2 from "node:process"; import { isInstallPkg, jsShell as jsShell2 } from "lazy-js-utils/node"; import color from "picocolors"; async function installDeps() { if (!await isInstallPkg("gum")) { console.log(color.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56gum...")); const { status } = await jsShell2("brew install gum", [ "inherit", "pipe", "inherit" ]); if (status === 0) { console.log(color.cyan("gum \u5B89\u88C5\u6210\u529F!")); } else { console.log( color.red( "gum \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/charmbracelet/gum" ) ); process2.exit(1); } } if (!await isInstallPkg("ni")) { console.log(color.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56ni...")); const { status } = await jsShell2("npm i -g @antfu/ni", [ "inherit", "pipe", "inherit" ]); if (status === 0) { console.log(color.cyan("ni \u5B89\u88C5\u6210\u529F!")); } else { console.log( color.red( "ni \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/antfu/ni" ) ); process2.exit(1); } } } // src/pa.ts import { jsShell as jsShell3 } from "lazy-js-utils/node"; function pa() { return jsShell3("na"); } // src/pi.ts import { log } from "node:console"; import process5 from "node:process"; import { getPkgTool as getPkgTool2, jsShell as jsShell6, useNodeWorker } from "lazy-js-utils/node"; import colors3 from "picocolors"; // src/detectNode.ts import process3 from "node:process"; import { getPkg, jsShell as jsShell4 } from "lazy-js-utils/node"; import colors from "picocolors"; async function detectNode() { let pkg; try { pkg = await getPkg(); } catch (_) { const cwd = process3.cwd(); console.log(colors.red(`\u5F53\u524D\u76EE\u5F55: ${cwd} \u6CA1\u6709package.json\u6587\u4EF6`)); process3.exit(1); } if (pkg.engines?.node) { const isSafe = __require("semver").satisfies( process3.version, pkg.engines.node ); if (!isSafe) { const { result, status } = await jsShell4( `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 jsShell4( ` 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 import path from "node:path"; import process4 from "node:process"; import { isFile } from "lazy-js-utils"; import { getPkg as getPkg2, getPkgTool, jsShell as jsShell5 } from "lazy-js-utils/node"; import colors2 from "picocolors"; 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 = process4.env.PI_Lang === "zh"; async function getParams(params) { const root = process4.cwd(); try { switch (await getPkgTool()) { case "pnpm": if (!isFile(path.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 (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 getPkg2(path.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 getPkg2())?.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( colors2.red( `${isZh2 ? "package.json\u5E76\u4E0D\u5B58\u5728,\u5728\u4EE5\u4E0B\u76EE\u5F55\u4E2D:" : "package.json has not been found in"} ${process4.cwd()}` ) ); process4.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" } = process4.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 jsShell5(`npm view ${pName}`, [ "inherit", "pipe", "inherit" ]); if (status === 0) { if (result.startsWith("@")) result = result.slice(1); const item = isZh6 ? `${pName} ${colors2.gray(v)} -> ${result.match(/@(\S+)/)[1]}` : `Installed ${pName} ${colors2.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 = process5.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 = process5.env.PI_SILENT === "true"; let stdio = isSilent ? "inherit" : ["inherit", "pipe", "inherit"]; let loading_status; const { PI_DEFAULT, PI_MaxSockets: sockets } = process5.env; const pkgTool = await getPkgTool2(); 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(colors3.green(isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`)); let { status, result } = await 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")) { log(result); log( colors3.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 jsShell6( `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 += colors3.blue(` ---- \u23F0\uFF1A${costTime}s`); if (status === 0) { loading_status.succeed(colors3.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(colors3.red(result ? `${failMsg} ${_result}` : failMsg)); } else { loading_status.fail(colors3.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]; jsShell6(`pi ${dep}@latest`); } } process5.exit(); } // src/pci.ts function pci(params, pkg) { return pi(params, pkg, "nci"); } // src/pfind.ts import { ccommand } from "ccommand"; function pfind(params) { return ccommand(`find ${params}`); } // src/pil.ts import process6 from "node:process"; import { getPkg as getPkg3, jsShell as jsShell7 } from "lazy-js-utils/node"; import pc from "picocolors"; async function pil(params) { const { dependencies = {}, devDependencies = {} } = await getPkg3(); 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 jsShell7( `echo ${deps.join( "," )} | sed "s/,/\\n/g" | gum filter --no-limit --strict=false --placeholder=" \u{1F914}${process6.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(pc.dim("\u5DF2\u53D6\u6D88")); process6.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 import { getPkgTool as getPkgTool3, jsShell as jsShell8 } from "lazy-js-utils/node"; async function pinit() { console.log("Initializing project..."); switch (await getPkgTool3()) { case "npm": jsShell8("npm init -y"); return; case "yarn": jsShell8("yarn init -y"); return; case "pnpm": jsShell8("pnpm init -y"); return; default: jsShell8("npm init -y"); } } // src/pio.ts import process7 from "node:process"; import { useNodeWorker as useNodeWorker2 } from "lazy-js-utils/node"; import color2 from "picocolors"; 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 useNodeWorker2({ params: `${executor} ${newParams} ${offline}`, stdio: "inherit" }); const loading_status = await loading(""); if (status === 0) loading_status.succeed(color2.green(successMsg)); else loading_status.fail(color2.red(result ? `${result} ${failMsg}` : failMsg)); process7.exit(); } // src/pix.ts import { getPkgTool as getPkgTool4, jsShell as jsShell9 } from "lazy-js-utils/node"; async function pix(params) { switch (await getPkgTool4()) { case "bun": return jsShell9(`bunx ${params}`); default: return jsShell9(`npx ${params}`); } } // src/prun.ts import { ccommand as ccommand2 } from "ccommand"; function prun(params) { return ccommand2(params); } // src/pu.ts import { jsShell as jsShell10 } from "lazy-js-utils/node"; function pu() { return jsShell10("nu"); } // src/pui.ts import process8 from "node:process"; import { getPkg as getPkg4, jsShell as jsShell11, useNodeWorker as useNodeWorker3 } from "lazy-js-utils/node"; import colors4 from "picocolors"; var isZh4 = process8.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 getPkg4(); const deps = [ ...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key]}`), ...Object.keys(devDependencies).map( (key) => `${key}: ${devDependencies[key]}` ) ]; const { result: choose, status: status2 } = await jsShell11( `echo ${deps.join( "," )} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${process8.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(colors4.dim("\u5DF2\u53D6\u6D88")); process8.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( colors4.yellow( isZh4 ? "\u9700\u8981\u6307\u5B9A\u8981\u5378\u8F7D\u7684\u5305\u540D\uFF01" : "Need to specify an uninstall package name!" ) ); process8.exit(1); } const loading_status = await loading(text); const { status, result } = await useNodeWorker3(`nun ${params}`); const end = Date.now(); const costTime = (end - start) / 1e3; successMsg += colors4.blue(` ---- \u23F0\uFF1A${costTime}s`); if (status === 0) loading_status.succeed(colors4.green(successMsg)); else loading_status.fail(colors4.red(result ? `${failMsg} ${result}` : failMsg)); process8.exit(); } // src/index.ts var rootPath = process9.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 = process9.env.PI_Lang === "zh"; async function setup() { const cmd = process9.argv[1]; let exec = ""; if (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 = process9.argv.slice(2); await help(argv); let params = spaceFormat(argv.join(" ")).trim(); if (!await hasPkg(rootPath)) { if (await isGo(rootPath)) { if (exec === "pi") { const loading_status = await loading( `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ... ` ); const { status } = params ? await useNodeWorker4(`go get ${params}`) : await useNodeWorker4("go mod tidy"); if (status === 0) { loading_status.succeed( color3.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}") ); } else { loading_status.fail( color3.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 useNodeWorker4(`go clean ${params}`); if (status === 0) { loading_status.succeed( color3.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}") ); } else { loading_status.fail( color3.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 fg(match))[0]; return target ? await jsShell12(`go run ${target}`, "inherit") : ccommand3(params); } else if (exec === "pinit") { await jsShell12(`go mod init ${params}`, "inherit"); } else if (exec === "pbuild") { await jsShell12(`go build ${params}`, "inherit"); } else { console.log( color3.red( isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported" ) ); } process9.exit(); } let projectPath = ""; if (params && !await isRust()) { projectPath = params.split(" ")[0]; rootPath = path2.resolve(rootPath, projectPath); params = params.replace(projectPath, "").trim(); } if (await isRust(rootPath)) { if (exec === "pi") { const loading_status = await loading( `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ... ` ); const { status } = await useNodeWorker4( `cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}` ); if (status === 0) { loading_status.succeed( color3.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}") ); } else { loading_status.fail( color3.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 useNodeWorker4( `cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}` ); if (status === 0) { loading_status.succeed( color3.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}") ); } else { loading_status.fail( color3.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}") ); } } else if (exec === "prun") { await jsShell12( `cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit" ); } else if (exec === "pinit") { await jsShell12( `cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit" ); } else if (exec === "pbuild") { await jsShell12( `cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit" ); } else { console.log( color3.red( isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported" ) ); } process9.exit(); } if (!runMap[exec]) { console.log( color3.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(); export { setup };