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",
HELP: "help",
}
exports.InitTypes = {
QUICK: "quick",
}

View File

@ -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,8 +50,10 @@ async function handleError(func) {
}
}
async function init() {
async function init(info) {
const isQuick = info === InitTypes.QUICK
await checkDockerConfigured()
if (!isQuick) {
const shouldContinue = await confirmation(
"This will create multiple files in current directory, should continue?"
)
@ -59,8 +61,10 @@ async function init() {
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(

View File

@ -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(
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 = await number(
))
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(

View File

@ -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
}
}