Updating make dotenv file in the CLI to be a bit cleaner/easier to manipulate than a magic string.

This commit is contained in:
Michael Drury 2022-09-28 00:16:04 +01:00
parent b66df050dc
commit ccac360340
2 changed files with 41 additions and 22 deletions

View File

@ -1,5 +1,5 @@
const { number } = require("../questions") const { number } = require("../questions")
const { success } = require("../utils") const { success, stringifyToDotEnv } = require("../utils")
const fs = require("fs") const fs = require("fs")
const path = require("path") const path = require("path")
const randomString = require("randomstring") const randomString = require("randomstring")
@ -40,27 +40,38 @@ function getSingleCompose(port) {
} }
function getEnv(port) { function getEnv(port) {
return ` const partOne = stringifyToDotEnv({
# Use the main port in the builder for your self hosting URL, e.g. localhost:10000 MAIN_PORT: port,
MAIN_PORT=${port} })
const secrets = [
# This section contains all secrets pertaining to the system "JWT_SECRET",
JWT_SECRET=${randomString.generate()} "MINIO_ACCESS_KEY",
MINIO_ACCESS_KEY=${randomString.generate()} "MINIO_SECRET_KEY",
MINIO_SECRET_KEY=${randomString.generate()} "COUCH_DB_PASSWORD",
COUCH_DB_PASSWORD=${randomString.generate()} "COUCH_DB_USER",
COUCH_DB_USER=${randomString.generate()} "REDIS_PASSWORD",
REDIS_PASSWORD=${randomString.generate()} "INTERNAL_API_KEY",
INTERNAL_API_KEY=${randomString.generate()} ]
const partTwoObj = {}
# This section contains variables that do not need to be altered under normal circumstances secrets.forEach(secret => (partTwoObj[secret] = randomString.generate()))
APP_PORT=4002 const partTwo = stringifyToDotEnv(partTwoObj)
WORKER_PORT=4003 const partThree = stringifyToDotEnv({
MINIO_PORT=4004 APP_PORT: 4002,
COUCH_DB_PORT=4005 WORKER_PORT: 4003,
REDIS_PORT=6379 MINIO_PORT: 4004,
WATCHTOWER_PORT=6161 COUCH_DB_PORT: 4005,
BUDIBASE_ENVIRONMENT=PRODUCTION` REDIS_PORT: 6379,
WATCHTOWER_PORT: 6161,
BUDIBASE_ENVIRONMENT: "PRODUCTION",
})
return [
"# Use the main port in the builder for your self hosting URL, e.g. localhost:10000",
partOne,
"# This section contains all secrets pertaining to the system",
partTwo,
"# This section contains variables that do not need to be altered under normal circumstances",
partThree,
].join("\n")
} }
module.exports.filePath = ENV_PATH module.exports.filePath = ENV_PATH

View File

@ -88,3 +88,11 @@ exports.moveDirectory = (oldPath, newPath) => {
exports.capitaliseFirstLetter = str => { exports.capitaliseFirstLetter = str => {
return str.charAt(0).toUpperCase() + str.slice(1) return str.charAt(0).toUpperCase() + str.slice(1)
} }
exports.stringifyToDotEnv = json => {
let str = ""
for (let [key, value] of Object.entries(json)) {
str += `${key}=${value}\n`
}
return str
}