1
0
Fork 0
mirror of synced 2024-09-19 18:59:06 +12:00
budibase/packages/cli/src/exec.js

26 lines
661 B
JavaScript
Raw Normal View History

const util = require("util")
const exec = util.promisify(require("child_process").exec)
exports.exec = async command => {
const { stdout } = await exec(command)
return stdout
}
exports.utilityInstalled = async utilName => {
try {
await exports.exec(`${utilName} --version`)
return true
} catch (err) {
return false
}
}
exports.runPkgCommand = async command => {
const yarn = await exports.utilityInstalled("yarn")
const npm = await exports.utilityInstalled("npm")
if (!yarn && !npm) {
throw new Error("Must have yarn or npm installed to run build.")
}
await exports.exec(yarn ? `yarn ${command}` : `npm run ${command}`)
}