mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 19:04:43 +00:00
69 lines
1.8 KiB
JavaScript
Executable file
69 lines
1.8 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const dotenv = require('dotenv');
|
|
|
|
// Load .env file
|
|
const envPath = path.join(process.cwd(), '.env');
|
|
const envConfig = dotenv.config({ path: envPath });
|
|
|
|
if (envConfig.error) {
|
|
console.warn('⚠️ No .env file found, generating empty env.generated.ts');
|
|
}
|
|
|
|
const env = envConfig.parsed || {};
|
|
|
|
// Generate TypeScript content
|
|
const tsContent = `// This file is auto-generated by tools/load-env.js
|
|
// Do not modify directly - edit .env file instead
|
|
// Generated at: ${new Date().toISOString()}
|
|
|
|
/**
|
|
* Environment variables loaded from .env file
|
|
* Access these constants instead of process.env in your Angular app
|
|
*/
|
|
export const ENV = {
|
|
${Object.entries(env)
|
|
.map(([key, value]) => {
|
|
// Escape quotes in values
|
|
const escapedValue = value.replace(/'/g, "\\'");
|
|
return ` ${key}: '${escapedValue}',`;
|
|
})
|
|
.join('\n')}
|
|
} as const;
|
|
|
|
// Type-safe helper to ensure all expected env vars are defined
|
|
export type EnvVars = typeof ENV;
|
|
`;
|
|
|
|
// Ensure the config directory exists
|
|
const configDir = path.join(process.cwd(), 'src/app/config');
|
|
if (!fs.existsSync(configDir)) {
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
}
|
|
|
|
// Write the generated file
|
|
const outputPath = path.join(configDir, 'env.generated.ts');
|
|
fs.writeFileSync(outputPath, tsContent);
|
|
|
|
console.log(
|
|
`✅ Generated ${outputPath} with ${Object.keys(env).length} environment variables`,
|
|
);
|
|
|
|
// Pass through to the next command
|
|
if (process.argv.length > 2) {
|
|
// Execute the rest of the command
|
|
const { spawn } = require('child_process');
|
|
const command = process.argv[2];
|
|
const args = process.argv.slice(3);
|
|
|
|
const child = spawn(command, args, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
});
|
|
|
|
child.on('exit', (code) => {
|
|
process.exit(code);
|
|
});
|
|
}
|