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:
8
turbo/generators/templates/env/generator.ts
vendored
8
turbo/generators/templates/env/generator.ts
vendored
@@ -1,5 +1,6 @@
|
|||||||
import type { PlopTypes } from '@turbo/gen';
|
import type { PlopTypes } from '@turbo/gen';
|
||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
|
import { writeFileSync } from 'node:fs';
|
||||||
|
|
||||||
export function createEnvironmentVariablesGenerator(
|
export function createEnvironmentVariablesGenerator(
|
||||||
plop: PlopTypes.NodePlopAPI,
|
plop: PlopTypes.NodePlopAPI,
|
||||||
@@ -20,12 +21,9 @@ export function createEnvironmentVariablesGenerator(
|
|||||||
env += `${key}=${value}\n`;
|
env += `${key}=${value}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write .env.local here with values
|
writeFileSync('turbo/generators/templates/env/.env.local', env);
|
||||||
execSync(
|
|
||||||
`echo "${env}" > turbo/generators/templates/env/out/.env.local`,
|
|
||||||
);
|
|
||||||
|
|
||||||
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: [
|
prompts: [
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ export function createEnvironmentVariablesValidatorGenerator(
|
|||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'path',
|
name: 'path',
|
||||||
message:
|
message:
|
||||||
'Where is the path to the environment variables file? Leave empty to use the generated 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/out/.env.local',
|
default: 'turbo/generators/templates/env/.env.local',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user