Finishing up init with config building rather than downloading.

This commit is contained in:
mike12345567 2021-02-26 13:48:11 +00:00
parent 333d7279ac
commit a2ce1be37a
7 changed files with 91 additions and 4 deletions

View File

@ -1 +1,4 @@
node_modules/ node_modules/
docker-compose.yaml
envoy.yaml
hosting.properties

View File

@ -10,7 +10,8 @@
"chalk": "^4.1.0", "chalk": "^4.1.0",
"commander": "^7.1.0", "commander": "^7.1.0",
"inquirer": "^8.0.0", "inquirer": "^8.0.0",
"lookpath": "^1.1.0" "lookpath": "^1.1.0",
"randomstring": "^1.1.5"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.20.0" "eslint": "^7.20.0"

View File

@ -4,11 +4,11 @@ const { spawn } = require("child_process")
const { lookpath } = require("lookpath") const { lookpath } = require("lookpath")
const { downloadFile } = require("../utils") const { downloadFile } = require("../utils")
const { confirmation } = require("../questions") const { confirmation } = require("../questions")
const makeEnvFile = require("./makeEnv")
const FILE_URLS = [ const FILE_URLS = [
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml", "https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml",
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/envoy.yaml", "https://raw.githubusercontent.com/Budibase/budibase/master/hosting/envoy.yaml"
"https://github.com/Budibase/budibase/blob/master/hosting/hosting.properties"
] ]
async function checkDockerConfigured() { async function checkDockerConfigured() {
@ -33,7 +33,7 @@ async function init() {
promises.push(downloadFile(url, `./${fileName}`)) promises.push(downloadFile(url, `./${fileName}`))
} }
await Promise.all(promises) await Promise.all(promises)
console.log("Files have been downloaded, ready to start.") await makeEnvFile()
} }
async function start() { async function start() {

View File

@ -0,0 +1,38 @@
const { string, number } = require("../questions")
const { getSuccess } = require("../utils")
const fs = require("fs")
const path = require("path")
const randomString = require("randomstring")
const FILE_PATH = path.resolve("./.env")
function getContents(port, hostingKey) {
return `
# Use the main port in the builder for your self hosting URL, e.g. localhost:10000
MAIN_PORT=${port}
# Use this password when configuring your self hosting settings
HOSTING_KEY=${hostingKey}
# This section contains all secrets pertaining to the system
JWT_SECRET=${randomString.generate()}
MINIO_ACCESS_KEY=${randomString.generate()}
MINIO_SECRET_KEY=${randomString.generate()}
COUCH_DB_PASSWORD=${randomString.generate()}
COUCH_DB_USER=${randomString.generate()}
# This section contains variables that do not need to be altered under normal circumstances
APP_PORT=4002
WORKER_PORT=4003
MINIO_PORT=4004
COUCH_DB_PORT=4005
BUDIBASE_ENVIRONMENT=PRODUCTION`
}
module.exports = 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)
const fileContents = getContents(hostingKey, hostingPort)
fs.writeFileSync(FILE_PATH, fileContents)
console.log(getSuccess("Configuration has been written successfully - please check .env file for more details."))
}

View File

@ -9,3 +9,32 @@ exports.confirmation = async question => {
} }
return (await inquirer.prompt(config)).confirmation return (await inquirer.prompt(config)).confirmation
} }
exports.string = async (question, defaultString = null) => {
const config = {
type: "input",
name: "string",
message: question,
}
if (defaultString) {
config.default = defaultString
}
return (await inquirer.prompt(config)).string
}
exports.number = async (question, defaultNumber) => {
const config = {
type: "input",
name: "number",
message: question,
validate: (value) => {
let valid = !isNaN(parseFloat(value))
return valid || "Please enter a number"
},
filter: Number,
}
if (defaultNumber) {
config.default = defaultNumber
}
return (await inquirer.prompt(config)).number
}

View File

@ -32,3 +32,7 @@ exports.getSubHelpDescription = string => {
exports.getError = error => { exports.getError = error => {
return chalk.red(`Error - ${error}`) return chalk.red(`Error - ${error}`)
} }
exports.getSuccess = success => {
return chalk.green(success)
}

View File

@ -107,6 +107,11 @@ argparse@^1.0.7:
dependencies: dependencies:
sprintf-js "~1.0.2" sprintf-js "~1.0.2"
array-uniq@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.2.tgz#5fcc373920775723cfd64d65c64bef53bf9eba6d"
integrity sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0=
astral-regex@^2.0.0: astral-regex@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
@ -685,6 +690,13 @@ punycode@^2.1.0:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
randomstring@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/randomstring/-/randomstring-1.1.5.tgz#6df0628f75cbd5932930d9fe3ab4e956a18518c3"
integrity sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=
dependencies:
array-uniq "1.0.2"
regexpp@^3.1.0: regexpp@^3.1.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2"