Skip to content

Instantly share code, notes, and snippets.

@sunb0002
Created April 21, 2020 11:53
Show Gist options
  • Save sunb0002/c581a14b2075e1fe470c0a2a4e6d8a83 to your computer and use it in GitHub Desktop.
Save sunb0002/c581a14b2075e1fe470c0a2a4e6d8a83 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
'use strict';
const usage = () => console.log(`
Usage:
node config-env.js <envKey>
(e.g node config-env.js sit-ocip)
The script will replace config.json with config-<envKey>.json in /build folder,
and remove all config-*.json in the same folder.
`);
if (process.argv.length < 3) {
usage();
process.exit(0);
}
const fs = require('fs');
const configDir = `${__dirname}/../build/config`;
const envKey = process.argv[2];
const srcFile = `${configDir}/config.${envKey}.json`;
const targetFile = `${configDir}/config.json`;
console.log(`Replacing ${targetFile}\n with ${srcFile}.\n And removing other config files.`);
fs.renameSync(srcFile, targetFile);
fs.readdirSync(configDir)
.filter(f => /^config\..+\.json$/.test(f))
.map(f => fs.unlinkSync(`${configDir}/${f}`));
console.log("Config env completed.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment