Create a gist now

Instantly share code, notes, and snippets.

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