From d3a4fbdeb15a45dc4477177904b6fea021b82e15 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Wed, 5 Jun 2024 15:45:47 +0700 Subject: [PATCH] Refactor env file generation and validation This commit replaces the previous use of execSync to generate .env.local files with the use of writeFileSync. It also updates the corresponding path and default value in the validation process. This change provides a more efficient and safer way to create these files and correctly update the related prompts. --- turbo/generators/templates/env/generator.ts | 8 +++----- turbo/generators/templates/validate-env/generator.ts | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/turbo/generators/templates/env/generator.ts b/turbo/generators/templates/env/generator.ts index 1cdb12331..4c37e5799 100644 --- a/turbo/generators/templates/env/generator.ts +++ b/turbo/generators/templates/env/generator.ts @@ -1,5 +1,6 @@ import type { PlopTypes } from '@turbo/gen'; import { execSync } from 'node:child_process'; +import { writeFileSync } from 'node:fs'; export function createEnvironmentVariablesGenerator( plop: PlopTypes.NodePlopAPI, @@ -20,12 +21,9 @@ export function createEnvironmentVariablesGenerator( env += `${key}=${value}\n`; } - // write .env.local here with values - execSync( - `echo "${env}" > turbo/generators/templates/env/out/.env.local`, - ); + writeFileSync('turbo/generators/templates/env/.env.local', env); - return 'Environment variables generated at turbo/generators/templates/env/out/.env.local. Please double check and use this file in your hosting provider to set the environment variables. Never commit this file, it contains secrets!'; + return 'Environment variables generated at turbo/generators/templates/env/.env.local. Please double check and use this file in your hosting provider to set the environment variables. Never commit this file, it contains secrets!'; }, ], prompts: [ diff --git a/turbo/generators/templates/validate-env/generator.ts b/turbo/generators/templates/validate-env/generator.ts index d7b67bf9a..8bc42910a 100644 --- a/turbo/generators/templates/validate-env/generator.ts +++ b/turbo/generators/templates/validate-env/generator.ts @@ -199,8 +199,8 @@ export function createEnvironmentVariablesValidatorGenerator( type: 'input', name: 'path', message: - 'Where is the path to the environment variables file? Leave empty to use the generated turbo/generators/templates/env/out/.env.local', - default: 'turbo/generators/templates/env/out/.env.local', + 'Where is the path to the environment variables file? Leave empty to use the generated turbo/generators/templates/env/.env.local', + default: 'turbo/generators/templates/env/.env.local', }, ], });