Skip to content

Instantly share code, notes, and snippets.

@sugilog
Created March 17, 2017 05:22
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 sugilog/72a8f4c31b198ec1bdd58310019e3f5c to your computer and use it in GitHub Desktop.
Save sugilog/72a8f4c31b198ec1bdd58310019e3f5c to your computer and use it in GitHub Desktop.
Switch Config by arg at package.json for npm run.
{
"a" : 1,
"b" : 2,
"c" : 3
}
{
"x" : 1,
"y" : 2,
"z" : 3
}
"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" ) ) );
{
"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