2 // Usage: cat package.json | node filter-package-json-cli.js
5 function filterLocalDeps(depMap) {
6 return Object.keys(depMap).reduce((result, dependency) => {
7 const semver = depMap[dependency];
8 if (!semver.match(/^file:/i)) {
9 result[dependency] = semver;
17 process.stdin.setEncoding('utf8');
18 process.stdin.on('data', function(d) {
19 cliInput = cliInput + d;
22 process.stdin.on('end', function() {
23 const packageData = JSON.parse(cliInput);
25 const packageResultant = Object.assign({}, packageData, {
26 dependencies: filterLocalDeps(packageData.dependencies || {}),
27 devDependencies: filterLocalDeps(packageData.devDependencies || {})
30 console.log(JSON.stringify(packageResultant, null, ' '));
33 process.stdin.resume();