1
0
Fork 0
mirror of synced 2024-09-10 22:46:09 +12:00
budibase/packages/cli/src/exec.ts

28 lines
846 B
TypeScript

import util from "util"
import childProcess from "child_process"
const runCommand = util.promisify(childProcess.exec)
export async function exec(command: string, dir = "./") {
const { stdout } = await runCommand(command, { cwd: dir })
return stdout
}
export async function utilityInstalled(utilName: string) {
try {
await exec(`${utilName} --version`)
return true
} catch (err) {
return false
}
}
export async function runPkgCommand(command: string, dir = "./") {
const yarn = await utilityInstalled("yarn")
const npm = await utilityInstalled("npm")
if (!yarn && !npm) {
throw new Error("Must have yarn or npm installed to run build.")
}
const npmCmd = command === "install" ? `npm ${command}` : `npm run ${command}`
const cmd = yarn ? `yarn ${command} --ignore-engines` : npmCmd
await exec(cmd, dir)
}