2021-02-26 14:48:11 +01:00
|
|
|
const { string, number } = require("../questions")
|
2021-02-26 18:08:28 +01:00
|
|
|
const { success } = require("../utils")
|
2021-02-26 14:48:11 +01:00
|
|
|
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
|
2021-03-22 17:18:29 +01:00
|
|
|
REDIS_PORT=6379
|
2021-02-26 14:48:11 +01:00
|
|
|
BUDIBASE_ENVIRONMENT=PRODUCTION`
|
|
|
|
}
|
|
|
|
|
2021-02-26 16:09:25 +01:00
|
|
|
module.exports.filePath = FILE_PATH
|
2021-03-19 11:02:29 +01:00
|
|
|
module.exports.ConfigMap = {
|
|
|
|
HOSTING_KEY: "key",
|
|
|
|
MAIN_PORT: "port",
|
|
|
|
}
|
2021-03-18 19:26:41 +01:00
|
|
|
module.exports.QUICK_CONFIG = {
|
|
|
|
key: "budibase",
|
|
|
|
port: 10000,
|
|
|
|
}
|
2021-02-26 16:09:25 +01:00
|
|
|
|
2021-03-18 19:26:41 +01:00
|
|
|
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
|
|
|
|
))
|
2021-02-26 16:09:25 +01:00
|
|
|
const fileContents = getContents(hostingPort, hostingKey)
|
2021-02-26 14:48:11 +01:00
|
|
|
fs.writeFileSync(FILE_PATH, fileContents)
|
2021-02-26 18:09:20 +01:00
|
|
|
console.log(
|
|
|
|
success(
|
|
|
|
"Configuration has been written successfully - please check .env file for more details."
|
|
|
|
)
|
|
|
|
)
|
2021-02-26 16:09:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.get = property => {
|
|
|
|
const props = fs.readFileSync(FILE_PATH, "utf8").split(property)
|
|
|
|
if (props[0].charAt(0) === "=") {
|
|
|
|
property = props[0]
|
|
|
|
} else {
|
|
|
|
property = props[1]
|
|
|
|
}
|
|
|
|
return property.split("=")[1].split("\n")[0]
|
|
|
|
}
|