Getting dependency installation working correctly.

This commit is contained in:
mike12345567 2022-08-11 17:29:07 +01:00
parent c9c468a424
commit 1f2f130907
3 changed files with 9 additions and 6 deletions

4
.gitignore vendored
View File

@ -102,4 +102,6 @@ packages/builder/cypress/reports
stats.html
# TypeScript cache
*.tsbuildinfo
*.tsbuildinfo
budibase-component
budibase-datasource

View File

@ -1,8 +1,8 @@
const util = require("util")
const exec = util.promisify(require("child_process").exec)
exports.exec = async command => {
const { stdout } = await exec(command)
exports.exec = async (command, dir = "./") => {
const { stdout } = await exec(command, { cwd: dir })
return stdout
}
@ -15,12 +15,13 @@ exports.utilityInstalled = async utilName => {
}
}
exports.runPkgCommand = async command => {
exports.runPkgCommand = async (command, dir = "./") => {
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.")
}
const npmCmd = command === "install" ? `npm ${command}` : `npm run ${command}`
await exports.exec(yarn ? `yarn ${command}` : npmCmd)
const cmd = yarn ? `yarn ${command}` : npmCmd
await exports.exec(cmd, dir)
}

View File

@ -37,7 +37,7 @@ async function init(opts) {
await getSkeleton(type, name)
await fleshOutSkeleton(name, desc, version)
console.log(info("Installing dependencies..."))
await runPkgCommand("install")
await runPkgCommand("install", join(process.cwd(), name))
console.log(info(`Plugin created in directory "${name}"`))
}