From 87918fd55cf966d8031387a32449f352f9361676 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 18 Mar 2021 18:26:41 +0000 Subject: [PATCH] Updating the CLI to have a fast init method, this will make using it for DO much much easier. --- packages/cli/src/constants.js | 4 ++++ packages/cli/src/hosting/index.js | 26 +++++++++++++++----------- packages/cli/src/hosting/makeEnv.js | 24 ++++++++++++++++-------- packages/cli/src/structures/Command.js | 13 +++++-------- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/packages/cli/src/constants.js b/packages/cli/src/constants.js index a601909232..40c63d218d 100644 --- a/packages/cli/src/constants.js +++ b/packages/cli/src/constants.js @@ -2,3 +2,7 @@ exports.CommandWords = { HOSTING: "hosting", HELP: "help", } + +exports.InitTypes = { + QUICK: "quick", +} diff --git a/packages/cli/src/hosting/index.js b/packages/cli/src/hosting/index.js index a8e77f49d7..f5c2552c64 100644 --- a/packages/cli/src/hosting/index.js +++ b/packages/cli/src/hosting/index.js @@ -1,5 +1,5 @@ const Command = require("../structures/Command") -const { CommandWords } = require("../constants") +const { CommandWords, InitTypes } = require("../constants") const { lookpath } = require("lookpath") const { downloadFile, logErrorToFile, success, info } = require("../utils") const { confirmation } = require("../questions") @@ -50,17 +50,21 @@ async function handleError(func) { } } -async function init() { +async function init(info) { + const isQuick = info === InitTypes.QUICK await checkDockerConfigured() - const shouldContinue = await confirmation( - "This will create multiple files in current directory, should continue?" - ) - if (!shouldContinue) { - console.log("Stopping.") - return + if (!isQuick) { + const shouldContinue = await confirmation( + "This will create multiple files in current directory, should continue?" + ) + if (!shouldContinue) { + console.log("Stopping.") + return + } } await downloadFiles() - await envFile.make() + const config = isQuick ? envFile.QUICK_CONFIG : {} + await envFile.make(config) } async function start() { @@ -128,8 +132,8 @@ async function update() { const command = new Command(`${CommandWords.HOSTING}`) .addHelp("Controls self hosting on the Budibase platform.") .addSubOption( - "--init", - "Configure a self hosted platform in current directory.", + "--init [type]", + "Configure a self hosted platform in current directory, type can be unspecified or 'quick'.", init ) .addSubOption( diff --git a/packages/cli/src/hosting/makeEnv.js b/packages/cli/src/hosting/makeEnv.js index b7d3b9e849..b84e50eb6b 100644 --- a/packages/cli/src/hosting/makeEnv.js +++ b/packages/cli/src/hosting/makeEnv.js @@ -30,15 +30,23 @@ BUDIBASE_ENVIRONMENT=PRODUCTION` } module.exports.filePath = FILE_PATH +module.exports.QUICK_CONFIG = { + key: "budibase", + port: 10000, +} -module.exports.make = async () => { - const hostingKey = await string( - "Please input the password you'd like to use as your hosting key: " - ) - const hostingPort = await number( - "Please enter the port on which you want your installation to run: ", - 10000 - ) +module.exports.make = async (inputs = {}) => { + const hostingKey = + inputs.key || + (await string( + "Please input the password you'd like to use as your hosting key: " + )) + const hostingPort = + inputs.port || + (await number( + "Please enter the port on which you want your installation to run: ", + 10000 + )) const fileContents = getContents(hostingPort, hostingKey) fs.writeFileSync(FILE_PATH, fileContents) console.log( diff --git a/packages/cli/src/structures/Command.js b/packages/cli/src/structures/Command.js index 5ca0ce67ee..a8d24566be 100644 --- a/packages/cli/src/structures/Command.js +++ b/packages/cli/src/structures/Command.js @@ -13,8 +13,8 @@ class Command { return this } - addSubOption(command, help, func) { - this.opts.push({ command, help, func }) + addSubOption(command, help, func, extras = []) { + this.opts.push({ command, help, func, extras }) return this } @@ -37,13 +37,10 @@ class Command { command.action(async options => { try { let executed = false - if (thisCmd.func) { - await thisCmd.func(options) - executed = true - } for (let opt of thisCmd.opts) { - if (options[opt.command.replace("--", "")]) { - await opt.func(options) + const lookup = opt.command.split(" ")[0].replace("--", "") + if (options[lookup]) { + await opt.func(options[lookup]) executed = true } }