diff --git a/.husky/post-checkout b/.husky/post-checkout new file mode 100644 index 0000000000..6cbbc44432 --- /dev/null +++ b/.husky/post-checkout @@ -0,0 +1 @@ +node tools/load-env.js --ensure diff --git a/tools/load-env.js b/tools/load-env.js index 3ad24b838b..729bc45f6d 100755 --- a/tools/load-env.js +++ b/tools/load-env.js @@ -3,11 +3,22 @@ const fs = require('fs'); const path = require('path'); -// --ensure flag: skip generation if env.generated.ts already exists +// --ensure flag: create empty placeholder if env.generated.ts doesn't exist, skip otherwise const ensureOnly = process.argv.includes('--ensure'); const configDir = path.join(process.cwd(), 'src/app/config'); const outputPath = path.join(configDir, 'env.generated.ts'); -if (ensureOnly && fs.existsSync(outputPath)) { +if (ensureOnly) { + if (fs.existsSync(outputPath)) { + process.exit(0); + } + if (!fs.existsSync(configDir)) { + fs.mkdirSync(configDir, { recursive: true }); + } + fs.writeFileSync( + outputPath, + `// This file is auto-generated by tools/load-env.js\n// Run 'npm run env' to populate with values from .env\n\nexport const ENV = {} as const;\n\nexport type EnvVars = typeof ENV;\n`, + ); + console.log(`✅ Created placeholder ${outputPath}`); process.exit(0); }