Updating the CLI to have a fast init method, this will make using it for DO much much easier.

This commit is contained in:
mike12345567 2021-03-18 18:26:41 +00:00
parent b12b6b39b5
commit 87918fd55c
4 changed files with 40 additions and 27 deletions

View File

@ -2,3 +2,7 @@ exports.CommandWords = {
HOSTING: "hosting", HOSTING: "hosting",
HELP: "help", HELP: "help",
} }
exports.InitTypes = {
QUICK: "quick",
}

View File

@ -1,5 +1,5 @@
const Command = require("../structures/Command") const Command = require("../structures/Command")
const { CommandWords } = require("../constants") const { CommandWords, InitTypes } = require("../constants")
const { lookpath } = require("lookpath") const { lookpath } = require("lookpath")
const { downloadFile, logErrorToFile, success, info } = require("../utils") const { downloadFile, logErrorToFile, success, info } = require("../utils")
const { confirmation } = require("../questions") 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() await checkDockerConfigured()
const shouldContinue = await confirmation( if (!isQuick) {
"This will create multiple files in current directory, should continue?" const shouldContinue = await confirmation(
) "This will create multiple files in current directory, should continue?"
if (!shouldContinue) { )
console.log("Stopping.") if (!shouldContinue) {
return console.log("Stopping.")
return
}
} }
await downloadFiles() await downloadFiles()
await envFile.make() const config = isQuick ? envFile.QUICK_CONFIG : {}
await envFile.make(config)
} }
async function start() { async function start() {
@ -128,8 +132,8 @@ async function update() {
const command = new Command(`${CommandWords.HOSTING}`) const command = new Command(`${CommandWords.HOSTING}`)
.addHelp("Controls self hosting on the Budibase platform.") .addHelp("Controls self hosting on the Budibase platform.")
.addSubOption( .addSubOption(
"--init", "--init [type]",
"Configure a self hosted platform in current directory.", "Configure a self hosted platform in current directory, type can be unspecified or 'quick'.",
init init
) )
.addSubOption( .addSubOption(

View File

@ -30,15 +30,23 @@ BUDIBASE_ENVIRONMENT=PRODUCTION`
} }
module.exports.filePath = FILE_PATH module.exports.filePath = FILE_PATH
module.exports.QUICK_CONFIG = {
key: "budibase",
port: 10000,
}
module.exports.make = async () => { module.exports.make = async (inputs = {}) => {
const hostingKey = await string( const hostingKey =
"Please input the password you'd like to use as your hosting key: " inputs.key ||
) (await string(
const hostingPort = await number( "Please input the password you'd like to use as your hosting key: "
"Please enter the port on which you want your installation to run: ", ))
10000 const hostingPort =
) inputs.port ||
(await number(
"Please enter the port on which you want your installation to run: ",
10000
))
const fileContents = getContents(hostingPort, hostingKey) const fileContents = getContents(hostingPort, hostingKey)
fs.writeFileSync(FILE_PATH, fileContents) fs.writeFileSync(FILE_PATH, fileContents)
console.log( console.log(

View File

@ -13,8 +13,8 @@ class Command {
return this return this
} }
addSubOption(command, help, func) { addSubOption(command, help, func, extras = []) {
this.opts.push({ command, help, func }) this.opts.push({ command, help, func, extras })
return this return this
} }
@ -37,13 +37,10 @@ class Command {
command.action(async options => { command.action(async options => {
try { try {
let executed = false let executed = false
if (thisCmd.func) {
await thisCmd.func(options)
executed = true
}
for (let opt of thisCmd.opts) { for (let opt of thisCmd.opts) {
if (options[opt.command.replace("--", "")]) { const lookup = opt.command.split(" ")[0].replace("--", "")
await opt.func(options) if (options[lookup]) {
await opt.func(options[lookup])
executed = true executed = true
} }
} }