1
0
Fork 0
mirror of synced 2024-06-30 12:00:31 +12:00

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",
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,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(

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(
"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(

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