From 27518cb678353d14801787a22ba14cff762fd32b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 13 Sep 2022 18:00:10 +0100 Subject: [PATCH 1/6] Fixing CLI build - prebuilds required for hashing can be disabled via environment variable. --- packages/backend-core/package.json | 1 + packages/backend-core/src/environment.ts | 1 + packages/backend-core/src/hashing.js | 2 +- packages/cli/src/environment.js | 1 + packages/cli/src/prebuilds.js | 5 ++++- 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index f6cb47bc8b..f1c4b2d28f 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -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", diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts index 04d09d2eb7..b979635fcc 100644 --- a/packages/backend-core/src/environment.ts +++ b/packages/backend-core/src/environment.ts @@ -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, diff --git a/packages/backend-core/src/hashing.js b/packages/backend-core/src/hashing.js index 45abe2f9bd..7524e66043 100644 --- a/packages/backend-core/src/hashing.js +++ b/packages/backend-core/src/hashing.js @@ -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 diff --git a/packages/cli/src/environment.js b/packages/cli/src/environment.js index a42eceb07e..c8c8fe87e9 100644 --- a/packages/cli/src/environment.js +++ b/packages/cli/src/environment.js @@ -1 +1,2 @@ process.env.NO_JS = "1" +process.env.JS_BCRYPT = "1" diff --git a/packages/cli/src/prebuilds.js b/packages/cli/src/prebuilds.js index b582b090e7..0decdc6c63 100644 --- a/packages/cli/src/prebuilds.js +++ b/packages/cli/src/prebuilds.js @@ -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:" From eae8ec97a9199c97a78757597a18b9e93216245f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 13 Sep 2022 18:22:15 +0100 Subject: [PATCH 2/6] Adding an option to disable top level parent directory creation during CLI plugin init incase using this for git repo creation. --- packages/cli/src/plugins/index.js | 19 +++++++++++++++++-- packages/cli/src/utils.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/plugins/index.js b/packages/cli/src/plugins/index.js index 714187df56..bc105ed77b 100644 --- a/packages/cli/src/plugins/index.js +++ b/packages/cli/src/plugins/index.js @@ -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")) { @@ -45,13 +45,28 @@ async function init(opts) { `An amazing Budibase ${type}!` ) const version = await questions.string("Version", "1.0.0") + 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." + ) + ) + const topLevel = await questions.confirmation("Create top level directory?") // 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)) - console.log(info(`Plugin created in directory "${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() { diff --git a/packages/cli/src/utils.js b/packages/cli/src/utils.js index 818153ef02..81520708d8 100644 --- a/packages/cli/src/utils.js +++ b/packages/cli/src/utils.js @@ -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(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) +} From 68a8a66bc7454a7387e83a754a026417fa15dd30 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 13 Sep 2022 18:28:03 +0100 Subject: [PATCH 3/6] Defaulting behaviour for empty git repos. --- packages/cli/src/plugins/index.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/plugins/index.js b/packages/cli/src/plugins/index.js index bc105ed77b..3f712c7e75 100644 --- a/packages/cli/src/plugins/index.js +++ b/packages/cli/src/plugins/index.js @@ -22,6 +22,24 @@ function checkInPlugin() { } } +async function askAboutTopLevel() { + const files = fs.readdirSync(process.cwd()) + // we are in an empty git repo, don't ask + if (files.length === 1 && files[0] === ".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,15 +63,7 @@ async function init(opts) { `An amazing Budibase ${type}!` ) const version = await questions.string("Version", "1.0.0") - 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." - ) - ) - const topLevel = await questions.confirmation("Create top level directory?") + const topLevel = await askAboutTopLevel() // get the skeleton console.log(info("Retrieving project...")) await getSkeleton(type, name) From e46ddbf65af77acc8756257aa7e7a631792cf11d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 14 Sep 2022 10:58:01 +0100 Subject: [PATCH 4/6] Fixes from PR comments. --- packages/cli/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/utils.js b/packages/cli/src/utils.js index 81520708d8..91f3263cc1 100644 --- a/packages/cli/src/utils.js +++ b/packages/cli/src/utils.js @@ -73,7 +73,7 @@ exports.moveDirectory = (oldPath, newPath) => { const files = fs.readdirSync(oldPath) // check any file exists already for (let file of files) { - if (fs.existsSync(file)) { + if (fs.existsSync(join(newPath, file))) { throw new Error( "Unable to remove top level directory - some skeleton files already exist." ) From 72736e5257723c2e7ebfd2ce1371c28bd4507f2d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 14 Sep 2022 11:04:37 +0100 Subject: [PATCH 5/6] Fixing a minor issue with plugin name not being passed through in CLI function. --- packages/cli/src/plugins/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/plugins/index.js b/packages/cli/src/plugins/index.js index 3f712c7e75..7525e9d2b1 100644 --- a/packages/cli/src/plugins/index.js +++ b/packages/cli/src/plugins/index.js @@ -22,7 +22,7 @@ function checkInPlugin() { } } -async function askAboutTopLevel() { +async function askAboutTopLevel(name) { const files = fs.readdirSync(process.cwd()) // we are in an empty git repo, don't ask if (files.length === 1 && files[0] === ".git") { @@ -63,7 +63,7 @@ async function init(opts) { `An amazing Budibase ${type}!` ) const version = await questions.string("Version", "1.0.0") - const topLevel = await askAboutTopLevel() + const topLevel = await askAboutTopLevel(name) // get the skeleton console.log(info("Retrieving project...")) await getSkeleton(type, name) From bbe0489af4bf246fdf61e6b9be1fca1267bca854 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 14 Sep 2022 11:11:20 +0100 Subject: [PATCH 6/6] Adding better controls for .git checking. --- packages/cli/src/plugins/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/plugins/index.js b/packages/cli/src/plugins/index.js index 7525e9d2b1..d184c6e70a 100644 --- a/packages/cli/src/plugins/index.js +++ b/packages/cli/src/plugins/index.js @@ -25,7 +25,7 @@ function checkInPlugin() { async function askAboutTopLevel(name) { const files = fs.readdirSync(process.cwd()) // we are in an empty git repo, don't ask - if (files.length === 1 && files[0] === ".git") { + if (files.find(file => file === ".git")) { return false } else { console.log(