UNPKG

run-script-cli

Version:

<p align="center"> <a href="https://www.npmjs.com/package/run-script-cli" target="_blank" rel="noopener noreferrer"> <img src="https://github.com/hunghg255/run-script-cli/blob/main/assets/icon.png?raw=true" alt="logo" width='100'/></a> </p>

70 lines (67 loc) 2 kB
import process from 'node:process'; import { d as detectAgent, t as te, $, H, n as ne, o as oe, e as execaCommand } from './shared/run-script-cli.f5e6c5d4.mjs'; import 'node:fs'; import 'node:path'; import 'node:util'; import 'node:child_process'; import 'node:buffer'; import 'child_process'; import 'path'; import 'fs'; import 'node:url'; import 'node:os'; import 'node:timers/promises'; import 'stream'; import 'tty'; import 'node:readline'; import 'node:tty'; import 'events'; const niCli = async (cwd = process.cwd(), argv = process.argv) => { try { const agent = await detectAgent(cwd); let nodeManager = agent?.name; let scriptValue = ""; if (!nodeManager) { nodeManager = await te({ message: $.bgCyan(" Choose npm manager "), options: ["npm", "pnpm", "yarn", "bun"].map((scriptItem) => ({ label: `${$.yellow(scriptItem)}`, value: scriptItem })) }); if (H(nodeManager)) { ne("Choose npm manager cancelled"); return process.exit(0); } } if (argv?.length > 2) { scriptValue = argv.slice(2).join(" "); } if (nodeManager === "bun") { const cmd = scriptValue ? `bun add ${scriptValue}` : "bun install"; oe($.bold($.green(`${cmd} `))); await execaCommand(`${cmd}`, { stdio: "inherit", cwd }); } if (nodeManager === "pnpm") { const cmd = scriptValue ? `pnpm add ${scriptValue}` : "pnpm install"; oe($.bold($.green(`${cmd} `))); await execaCommand(`${cmd}`, { stdio: "inherit", cwd }); } if (nodeManager === "npm") { oe($.bold($.green(`npm install ${scriptValue} `))); await execaCommand(`npm install ${scriptValue}`, { stdio: "inherit", cwd }); } if (nodeManager === "yarn") { const cmd = scriptValue ? `yarn add ${scriptValue}` : "yarn install"; oe($.bold($.green(`${cmd} `))); await execaCommand(`${cmd}`, { stdio: "inherit", cwd }); } } catch { } }; niCli(); export { niCli };