1
0
Fork 0
mirror of synced 2024-09-19 02:39:37 +12:00
budibase/packages/cli/src/exec.ts

30 lines
847 B
TypeScript
Raw Normal View History

import util from "util"
import childProcess from "child_process"
2023-11-21 09:52:29 +13:00
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)
}