Skip to content

Instantly share code, notes, and snippets.

@ThatGuySam
Last active December 16, 2022 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThatGuySam/c90d295b96422177148cfc6dce352b58 to your computer and use it in GitHub Desktop.
Save ThatGuySam/c90d295b96422177148cfc6dce352b58 to your computer and use it in GitHub Desktop.
Node script for securely keeping .env in sync with .env.example
// Can be used with Run on Save - https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
// Manually run with `npx tsx ./make-env-example.ts`
import { promises as fs } from 'node:fs'
( async () => {
// Read the .env file
const envContent = await fs.readFile( '.env', 'utf8' )
const cleanEnvContent = envContent.split( '\n' ).map( ( line ) => {
// If the line has no =, then return it as is
if ( !line.includes( '=' ) ) {
return line
}
return `${ line.split( '=' )[ 0 ] }=''`
} ).join( '\n' )
// console.log( { envContent, cleanEnvContent } )
await fs.writeFile( '.env.example', cleanEnvContent )
console.log( '✅ Updated .env.example' )
process.exit()
} )()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment