threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate-example-env.mjs 943B

преди 1 година
12345678910111213141516171819202122232425262728293031
  1. import fs from 'fs'
  2. import dotenv from 'dotenv'
  3. // read .env file if exists
  4. const envFilePath = './examples/.env'
  5. if (fs.existsSync(envFilePath)) {
  6. dotenv.config({ path: envFilePath })
  7. }
  8. // Filter EX_ variables from environment
  9. const envVars = Object.entries(process.env)
  10. .filter(([key]) => key.startsWith('TP_EX_'))
  11. .reduce((acc, [key, value]) => {
  12. acc[key.replace('TP_EX_', '')] = value
  13. return acc
  14. }, {})
  15. // Generate globals.js
  16. const jsOutput = Object.entries(envVars)
  17. .map(([key, val]) => `export const ${key} = ${JSON.stringify(val)}`)
  18. .join('\n') + '\n'
  19. fs.writeFileSync('./examples/globals.js', jsOutput, 'utf8')
  20. // Generate globals.d.ts
  21. const dtsOutput = Object.entries(envVars)
  22. .map(([key, value]) => `export const ${key}: ${typeof value}`)
  23. .join('\n') + '\n'
  24. fs.writeFileSync('./examples/globals.d.ts', dtsOutput, 'utf8')
  25. console.log('✅ globals.js and globals.d.ts generated.')