Created
April 21, 2020 11:53
-
-
Save sunb0002/c581a14b2075e1fe470c0a2a4e6d8a83 to your computer and use it in GitHub Desktop.
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
#!/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