1
0
Fork 0
mirror of synced 2024-07-08 07:46:10 +12:00

Ensure .env is created properly

This commit is contained in:
Adria Navarro 2023-12-13 13:14:13 +01:00
parent 935e63104c
commit 116b1ce909
2 changed files with 69 additions and 76 deletions

View file

@ -1,7 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
const compose = require("docker-compose") const compose = require("docker-compose")
const path = require("path") const path = require("path")
const fs = require("fs") const { parsed: existingConfig } = require("dotenv").config()
const updateDotEnv = require("update-dotenv")
// This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands. // This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands.
const CONFIG = { const CONFIG = {
@ -17,10 +18,8 @@ const Commands = {
} }
async function init() { async function init() {
const envFilePath = path.join(process.cwd(), ".env") let config = {
if (!fs.existsSync(envFilePath)) { PORT: "4001",
const envFileJson = {
PORT: 4001,
MINIO_URL: "http://localhost:4004", MINIO_URL: "http://localhost:4004",
COUCH_DB_URL: "http://budibase:budibase@localhost:4005", COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
REDIS_URL: "localhost:6379", REDIS_URL: "localhost:6379",
@ -36,10 +35,10 @@ async function init() {
MINIO_SECRET_KEY: "budibase", MINIO_SECRET_KEY: "budibase",
COUCH_DB_PASSWORD: "budibase", COUCH_DB_PASSWORD: "budibase",
COUCH_DB_USER: "budibase", COUCH_DB_USER: "budibase",
SELF_HOSTED: 1, SELF_HOSTED: "1",
DISABLE_ACCOUNT_PORTAL: 1, DISABLE_ACCOUNT_PORTAL: "1",
MULTI_TENANCY: "", MULTI_TENANCY: "",
DISABLE_THREADING: 1, DISABLE_THREADING: "1",
SERVICE: "app-service", SERVICE: "app-service",
DEPLOYMENT_ENVIRONMENT: "development", DEPLOYMENT_ENVIRONMENT: "development",
BB_ADMIN_USER_EMAIL: "", BB_ADMIN_USER_EMAIL: "",
@ -50,12 +49,10 @@ async function init() {
HTTP_LOGGING: "0", HTTP_LOGGING: "0",
VERSION: "0.0.0+local", VERSION: "0.0.0+local",
} }
let envFile = ""
Object.keys(envFileJson).forEach(key => { config = { ...config, ...existingConfig }
envFile += `${key}=${envFileJson[key]}\n`
}) await updateDotEnv(config)
fs.writeFileSync(envFilePath, envFile)
}
} }
async function up() { async function up() {

View file

@ -1,14 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
const path = require("path") const { parsed: existingConfig } = require("dotenv").config()
const fs = require("fs") const updateDotEnv = require("update-dotenv")
async function init() { async function init() {
const envFilePath = path.join(process.cwd(), ".env") let config = {
if (!fs.existsSync(envFilePath)) { SELF_HOSTED: "1",
const envFileJson = { PORT: "4002",
SELF_HOSTED: 1, CLUSTER_PORT: "10000",
PORT: 4002,
CLUSTER_PORT: 10000,
JWT_SECRET: "testsecret", JWT_SECRET: "testsecret",
INTERNAL_API_KEY: "budibase", INTERNAL_API_KEY: "budibase",
MINIO_ACCESS_KEY: "budibase", MINIO_ACCESS_KEY: "budibase",
@ -21,7 +19,7 @@ async function init() {
COUCH_DB_PASSWORD: "budibase", COUCH_DB_PASSWORD: "budibase",
// empty string is false // empty string is false
MULTI_TENANCY: "", MULTI_TENANCY: "",
DISABLE_ACCOUNT_PORTAL: 1, DISABLE_ACCOUNT_PORTAL: "1",
ACCOUNT_PORTAL_URL: "http://localhost:10001", ACCOUNT_PORTAL_URL: "http://localhost:10001",
ACCOUNT_PORTAL_API_KEY: "budibase", ACCOUNT_PORTAL_API_KEY: "budibase",
PLATFORM_URL: "http://localhost:10000", PLATFORM_URL: "http://localhost:10000",
@ -29,16 +27,14 @@ async function init() {
SERVICE: "worker-service", SERVICE: "worker-service",
DEPLOYMENT_ENVIRONMENT: "development", DEPLOYMENT_ENVIRONMENT: "development",
TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
ENABLE_EMAIL_TEST_MODE: 1, ENABLE_EMAIL_TEST_MODE: "1",
HTTP_LOGGING: 0, HTTP_LOGGING: "0",
VERSION: "0.0.0+local", VERSION: "0.0.0+local",
} }
let envFile = ""
Object.keys(envFileJson).forEach(key => { config = { ...config, ...existingConfig }
envFile += `${key}=${envFileJson[key]}\n`
}) await updateDotEnv(config)
fs.writeFileSync(envFilePath, envFile)
}
} }
// if more than init required use this to determine the command type // if more than init required use this to determine the command type