Last active
December 16, 2022 21:22
-
-
Save ThatGuySam/c90d295b96422177148cfc6dce352b58 to your computer and use it in GitHub Desktop.
Node script for securely keeping .env in sync with .env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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