UNPKG

@pitifulhawk/flash-up

Version:

Interactive project scaffolder for modern web applications

82 lines 2.56 kB
import { execa } from "execa"; export async function executeCommand(command, args = [], options = {}) { try { const result = await execa(command, args, { cwd: options.cwd || process.cwd(), stdio: options.stdio || "pipe", timeout: options.timeout || 600000, env: { ...process.env, CI: "true", npm_config_yes: "true", npm_config_audit: "false", npm_config_fund: "false", VITE_SKIP_ROLLDOWN_PROMPT: "true", VITE_INSTALL_DEPS: "false", TERM: "dumb", }, }); return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr, success: result.exitCode === 0, }; } catch (error) { let errorMessage = error.message || "Unknown error"; if (error.timedOut) { errorMessage = `Command timed out after ${options.timeout || 600000} milliseconds: ${command} ${args.join(" ")}`; } return { exitCode: error.exitCode || 1, stdout: error.stdout || "", stderr: error.stderr || errorMessage, success: false, }; } } export async function executeCommandWithOutput(command, args = [], cwd) { return executeCommand(command, args, { cwd: cwd || process.cwd(), stdio: "inherit", }); } export async function commandExists(command) { try { const result = await executeCommand("which", [command]); return result.success; } catch { try { const result = await executeCommand("where", [command]); return result.success; } catch { return false; } } } export async function getCommandVersion(command, versionFlag = "--version") { try { const result = await executeCommand(command, [versionFlag]); if (result.success) { return result.stdout.trim(); } return null; } catch { return null; } } export function parseCommand(commandString) { const parts = commandString.trim().split(/\s+/); const command = parts[0] || ""; const args = parts.slice(1); return { command, args }; } export async function executeCommandString(commandString, options = {}) { const { command, args } = parseCommand(commandString); return executeCommand(command, args, options); } //# sourceMappingURL=shell.js.map