Last active
August 24, 2018 17:38
-
-
Save zachariahtimothy/cc655ec2c064311075cb467111cb409f to your computer and use it in GitHub Desktop.
Generates a now.json file for static docker deployments on now that require .env files (which are ignored in .gitignore)
This file contains hidden or 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
const path = require('path'); | |
const fs = require('fs'); | |
// Generates now.json | |
// Writes a now config for static site copying .env to now.json | |
function main() { | |
const baseDir = path.join(__dirname, '../'); | |
const envFile = fs.readFileSync(path.join(baseDir, '.env')); | |
const envLines = envFile.toString().split('\n'); | |
const nowConfig = { | |
public: false, | |
type: 'static', | |
alias: '<NOW ALIAS>', | |
static: { | |
rewrites: [ | |
{ | |
source: '**', | |
destination: '/index.html', | |
}, | |
], | |
}, | |
env: {}, | |
}; | |
envLines.forEach(line => { | |
if (line.trim().charAt(0) !== '#') { | |
const lineParts = line.trim().split('='); | |
nowConfig.env[lineParts[0]] = lineParts[1]; | |
} | |
}); | |
const fileToWrite = `${baseDir}now.json`; | |
fs.writeFileSync(fileToWrite, JSON.stringify(nowConfig, null, 2)); | |
console.log('Writing now.json file to', fileToWrite, '...'); | |
process.exit(0); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment