Skip to content

Instantly share code, notes, and snippets.

@paulbjensen
Created June 18, 2018 11:24
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 paulbjensen/91ffc051331c42e9908ab178478f5a09 to your computer and use it in GitHub Desktop.
Save paulbjensen/91ffc051331c42e9908ab178478f5a09 to your computer and use it in GitHub Desktop.
The generateWebConfig.js file, part of an article on Medium
// Writes a file to src/config.js exporting the baseUrl property
const config = require('../config');
const fs = require('fs');
const path = require('path');
const {
baseUrl,
googleAnalytics,
sentryDSN,
useDevTools,
env,
secureCookie,
apiVersion
} = config;
const template = `const baseUrl = '${baseUrl}';
const googleAnalytics = '${googleAnalytics}';
const sentryDSN = '${sentryDSN}';
const useDevTools = ${useDevTools};
const secureCookie = ${secureCookie};
const apiVersion = '${apiVersion}';
export {
baseUrl,
googleAnalytics,
sentryDSN,
secureCookie,
useDevTools,
apiVersion
};`;
const filePath = path.join(process.cwd(), 'src/config.js');
fs.writeFile(filePath, template, err => {
console.log(`Generated config for web for ${env}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment