2022-08-10 17:19:08 +02:00
|
|
|
const util = require("util")
|
|
|
|
const exec = util.promisify(require("child_process").exec)
|
|
|
|
|
2022-08-11 18:29:07 +02:00
|
|
|
exports.exec = async (command, dir = "./") => {
|
|
|
|
const { stdout } = await exec(command, { cwd: dir })
|
2022-08-10 17:19:08 +02:00
|
|
|
return stdout
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.utilityInstalled = async utilName => {
|
|
|
|
try {
|
|
|
|
await exports.exec(`${utilName} --version`)
|
|
|
|
return true
|
|
|
|
} catch (err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-11 18:29:07 +02:00
|
|
|
exports.runPkgCommand = async (command, dir = "./") => {
|
2022-08-10 17:19:08 +02:00
|
|
|
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.")
|
|
|
|
}
|
2022-08-11 12:03:33 +02:00
|
|
|
const npmCmd = command === "install" ? `npm ${command}` : `npm run ${command}`
|
2022-10-04 11:18:04 +02:00
|
|
|
const cmd = yarn ? `yarn ${command} --ignore-engines` : npmCmd
|
2022-08-11 18:29:07 +02:00
|
|
|
await exports.exec(cmd, dir)
|
2022-08-10 17:19:08 +02:00
|
|
|
}
|