From 116b1ce9098b2f07aec1ea5502c8a12701b6ec0e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 13 Dec 2023 13:14:13 +0100 Subject: [PATCH] Ensure .env is created properly --- packages/server/scripts/dev/manage.js | 75 +++++++++++++-------------- packages/worker/scripts/dev/manage.js | 70 ++++++++++++------------- 2 files changed, 69 insertions(+), 76 deletions(-) diff --git a/packages/server/scripts/dev/manage.js b/packages/server/scripts/dev/manage.js index b469c1ffc7..6dc0966f78 100644 --- a/packages/server/scripts/dev/manage.js +++ b/packages/server/scripts/dev/manage.js @@ -1,7 +1,8 @@ #!/usr/bin/env node const compose = require("docker-compose") 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. const CONFIG = { @@ -17,45 +18,41 @@ const Commands = { } async function init() { - const envFilePath = path.join(process.cwd(), ".env") - if (!fs.existsSync(envFilePath)) { - const envFileJson = { - PORT: 4001, - MINIO_URL: "http://localhost:4004", - COUCH_DB_URL: "http://budibase:budibase@localhost:4005", - REDIS_URL: "localhost:6379", - WORKER_URL: "http://localhost:4002", - INTERNAL_API_KEY: "budibase", - ACCOUNT_PORTAL_URL: "http://localhost:10001", - ACCOUNT_PORTAL_API_KEY: "budibase", - PLATFORM_URL: "http://localhost:10000", - JWT_SECRET: "testsecret", - ENCRYPTION_KEY: "testsecret", - REDIS_PASSWORD: "budibase", - MINIO_ACCESS_KEY: "budibase", - MINIO_SECRET_KEY: "budibase", - COUCH_DB_PASSWORD: "budibase", - COUCH_DB_USER: "budibase", - SELF_HOSTED: 1, - DISABLE_ACCOUNT_PORTAL: 1, - MULTI_TENANCY: "", - DISABLE_THREADING: 1, - SERVICE: "app-service", - DEPLOYMENT_ENVIRONMENT: "development", - BB_ADMIN_USER_EMAIL: "", - BB_ADMIN_USER_PASSWORD: "", - PLUGINS_DIR: "", - TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", - HTTP_MIGRATIONS: "0", - HTTP_LOGGING: "0", - VERSION: "0.0.0+local", - } - let envFile = "" - Object.keys(envFileJson).forEach(key => { - envFile += `${key}=${envFileJson[key]}\n` - }) - fs.writeFileSync(envFilePath, envFile) + let config = { + PORT: "4001", + MINIO_URL: "http://localhost:4004", + COUCH_DB_URL: "http://budibase:budibase@localhost:4005", + REDIS_URL: "localhost:6379", + WORKER_URL: "http://localhost:4002", + INTERNAL_API_KEY: "budibase", + ACCOUNT_PORTAL_URL: "http://localhost:10001", + ACCOUNT_PORTAL_API_KEY: "budibase", + PLATFORM_URL: "http://localhost:10000", + JWT_SECRET: "testsecret", + ENCRYPTION_KEY: "testsecret", + REDIS_PASSWORD: "budibase", + MINIO_ACCESS_KEY: "budibase", + MINIO_SECRET_KEY: "budibase", + COUCH_DB_PASSWORD: "budibase", + COUCH_DB_USER: "budibase", + SELF_HOSTED: "1", + DISABLE_ACCOUNT_PORTAL: "1", + MULTI_TENANCY: "", + DISABLE_THREADING: "1", + SERVICE: "app-service", + DEPLOYMENT_ENVIRONMENT: "development", + BB_ADMIN_USER_EMAIL: "", + BB_ADMIN_USER_PASSWORD: "", + PLUGINS_DIR: "", + TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", + HTTP_MIGRATIONS: "0", + HTTP_LOGGING: "0", + VERSION: "0.0.0+local", } + + config = { ...config, ...existingConfig } + + await updateDotEnv(config) } async function up() { diff --git a/packages/worker/scripts/dev/manage.js b/packages/worker/scripts/dev/manage.js index 9e6a57d4bf..1b7c6f0ddd 100644 --- a/packages/worker/scripts/dev/manage.js +++ b/packages/worker/scripts/dev/manage.js @@ -1,44 +1,40 @@ #!/usr/bin/env node -const path = require("path") -const fs = require("fs") +const { parsed: existingConfig } = require("dotenv").config() +const updateDotEnv = require("update-dotenv") async function init() { - const envFilePath = path.join(process.cwd(), ".env") - if (!fs.existsSync(envFilePath)) { - const envFileJson = { - SELF_HOSTED: 1, - PORT: 4002, - CLUSTER_PORT: 10000, - JWT_SECRET: "testsecret", - INTERNAL_API_KEY: "budibase", - MINIO_ACCESS_KEY: "budibase", - MINIO_SECRET_KEY: "budibase", - REDIS_URL: "localhost:6379", - REDIS_PASSWORD: "budibase", - MINIO_URL: "http://localhost:4004", - COUCH_DB_URL: "http://budibase:budibase@localhost:4005", - COUCH_DB_USERNAME: "budibase", - COUCH_DB_PASSWORD: "budibase", - // empty string is false - MULTI_TENANCY: "", - DISABLE_ACCOUNT_PORTAL: 1, - ACCOUNT_PORTAL_URL: "http://localhost:10001", - ACCOUNT_PORTAL_API_KEY: "budibase", - PLATFORM_URL: "http://localhost:10000", - APPS_URL: "http://localhost:4001", - SERVICE: "worker-service", - DEPLOYMENT_ENVIRONMENT: "development", - TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", - ENABLE_EMAIL_TEST_MODE: 1, - HTTP_LOGGING: 0, - VERSION: "0.0.0+local", - } - let envFile = "" - Object.keys(envFileJson).forEach(key => { - envFile += `${key}=${envFileJson[key]}\n` - }) - fs.writeFileSync(envFilePath, envFile) + let config = { + SELF_HOSTED: "1", + PORT: "4002", + CLUSTER_PORT: "10000", + JWT_SECRET: "testsecret", + INTERNAL_API_KEY: "budibase", + MINIO_ACCESS_KEY: "budibase", + MINIO_SECRET_KEY: "budibase", + REDIS_URL: "localhost:6379", + REDIS_PASSWORD: "budibase", + MINIO_URL: "http://localhost:4004", + COUCH_DB_URL: "http://budibase:budibase@localhost:4005", + COUCH_DB_USERNAME: "budibase", + COUCH_DB_PASSWORD: "budibase", + // empty string is false + MULTI_TENANCY: "", + DISABLE_ACCOUNT_PORTAL: "1", + ACCOUNT_PORTAL_URL: "http://localhost:10001", + ACCOUNT_PORTAL_API_KEY: "budibase", + PLATFORM_URL: "http://localhost:10000", + APPS_URL: "http://localhost:4001", + SERVICE: "worker-service", + DEPLOYMENT_ENVIRONMENT: "development", + TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", + ENABLE_EMAIL_TEST_MODE: "1", + HTTP_LOGGING: "0", + VERSION: "0.0.0+local", } + + config = { ...config, ...existingConfig } + + await updateDotEnv(config) } // if more than init required use this to determine the command type