Created
March 17, 2017 05:22
-
-
Save sugilog/72a8f4c31b198ec1bdd58310019e3f5c to your computer and use it in GitHub Desktop.
Switch Config by arg at package.json for npm run.
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
{ | |
"a" : 1, | |
"b" : 2, | |
"c" : 3 | |
} |
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
{ | |
"x" : 1, | |
"y" : 2, | |
"z" : 3 | |
} |
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
"use strict"; | |
const fs = require( "fs" ); | |
let args = []; | |
process.argv.forEach( ( v, idx ) => { | |
if ( idx >= 2 ) { | |
args.push( v ); | |
} | |
}); | |
console.log( args ); | |
console.log( JSON.parse( fs.readFileSync( "./config.json", "utf8" ) ) ); |
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
{ | |
"name": "Switch!", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"switch": "f(){ ln -s config.json{.$1,}; shift; node index.js $@; rm config.json; }; f" | |
}, | |
"author": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment