From 34bf1d8277c0e537cffe30f7f49c535bc8f57a39 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Fri, 6 Mar 2026 16:37:45 +0100 Subject: [PATCH] fix(build): auto-generate env.generated.ts on checkout via husky hook --- .husky/post-checkout | 1 + tools/load-env.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .husky/post-checkout 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); }