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.
This commit is contained in:
giancarlo
2024-06-05 15:45:47 +07:00
parent 83a4f29be4
commit d3a4fbdeb1
2 changed files with 5 additions and 7 deletions

View File

@@ -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: [

View File

@@ -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',
},
],
});