Merge pull request #7758 from Budibase/fix/cli-build

Quick fix for CLI build
This commit is contained in:
Michael Drury 2022-09-14 12:43:55 +02:00 committed by GitHub
commit 816a547345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 4 deletions

View File

@ -25,6 +25,7 @@
"@techpass/passport-openidconnect": "0.3.2",
"aws-sdk": "2.1030.0",
"bcrypt": "5.0.1",
"bcryptjs": "2.4.3",
"dotenv": "16.0.1",
"emitter-listener": "1.1.2",
"ioredis": "4.28.0",

View File

@ -19,6 +19,7 @@ if (!LOADED && isDev() && !isTest()) {
const env = {
isTest,
isDev,
JS_BCRYPT: process.env.JS_BCRYPT,
JWT_SECRET: process.env.JWT_SECRET,
COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,

View File

@ -1,5 +1,5 @@
const bcrypt = require("bcrypt")
const env = require("./environment")
const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt")
const { v4 } = require("uuid")
const SALT_ROUNDS = env.SALT_ROUNDS || 10

View File

@ -1 +1,2 @@
process.env.NO_JS = "1"
process.env.JS_BCRYPT = "1"

View File

@ -7,7 +7,7 @@ const { PLUGIN_TYPE_ARR } = require("@budibase/types")
const { validate } = require("@budibase/backend-core/plugins")
const { runPkgCommand } = require("../exec")
const { join } = require("path")
const { success, error, info } = require("../utils")
const { success, error, info, moveDirectory } = require("../utils")
function checkInPlugin() {
if (!fs.existsSync("package.json")) {
@ -22,6 +22,24 @@ function checkInPlugin() {
}
}
async function askAboutTopLevel(name) {
const files = fs.readdirSync(process.cwd())
// we are in an empty git repo, don't ask
if (files.find(file => file === ".git")) {
return false
} else {
console.log(
info(`By default the plugin will be created in the directory "${name}"`)
)
console.log(
info(
"if you are already in an empty directory, such as a new Git repo, you can disable this functionality."
)
)
return questions.confirmation("Create top level directory?")
}
}
async function init(opts) {
const type = opts["init"] || opts
if (!type || !PLUGIN_TYPE_ARR.includes(type)) {
@ -45,14 +63,21 @@ async function init(opts) {
`An amazing Budibase ${type}!`
)
const version = await questions.string("Version", "1.0.0")
const topLevel = await askAboutTopLevel(name)
// get the skeleton
console.log(info("Retrieving project..."))
await getSkeleton(type, name)
await fleshOutSkeleton(type, name, desc, version)
console.log(info("Installing dependencies..."))
await runPkgCommand("install", join(process.cwd(), name))
// if no parent directory desired move to cwd
if (!topLevel) {
moveDirectory(name, process.cwd())
console.log(info(`Plugin created in current directory.`))
} else {
console.log(info(`Plugin created in directory "${name}"`))
}
}
async function verify() {
// will throw errors if not acceptable

View File

@ -27,7 +27,10 @@ function checkForBinaries() {
}
function cleanup(evt) {
if (evt && evt.errno) {
if (!isNaN(evt)) {
return
}
if (evt) {
console.error(
error(
"Failed to run CLI command - please report with the following message:"

View File

@ -3,6 +3,7 @@ const fs = require("fs")
const axios = require("axios")
const path = require("path")
const progress = require("cli-progress")
const { join } = require("path")
exports.downloadFile = async (url, filePath) => {
filePath = path.resolve(filePath)
@ -67,3 +68,19 @@ exports.progressBar = total => {
exports.checkSlashesInUrl = url => {
return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2")
}
exports.moveDirectory = (oldPath, newPath) => {
const files = fs.readdirSync(oldPath)
// check any file exists already
for (let file of files) {
if (fs.existsSync(join(newPath, file))) {
throw new Error(
"Unable to remove top level directory - some skeleton files already exist."
)
}
}
for (let file of files) {
fs.renameSync(join(oldPath, file), join(newPath, file))
}
fs.rmdirSync(oldPath)
}