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 1bb2b45d67
commit 7634ed6869
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,8 +50,10 @@ async function handleError(func) {
} }
} }
async function init() { async function init(info) {
const isQuick = info === InitTypes.QUICK
await checkDockerConfigured() await checkDockerConfigured()
if (!isQuick) {
const shouldContinue = await confirmation( const shouldContinue = await confirmation(
"This will create multiple files in current directory, should continue?" "This will create multiple files in current directory, should continue?"
) )
@ -59,8 +61,10 @@ async function init() {
console.log("Stopping.") console.log("Stopping.")
return 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 =
inputs.key ||
(await string(
"Please input the password you'd like to use as your hosting key: " "Please input the password you'd like to use as your hosting key: "
) ))
const hostingPort = await number( const hostingPort =
inputs.port ||
(await number(
"Please enter the port on which you want your installation to run: ", "Please enter the port on which you want your installation to run: ",
10000 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
} }
} }