Last active
April 5, 2016 15:54
-
-
Save shamasis/e2969a1b9505d450586c90689061918d to your computer and use it in GitHub Desktop.
Creates a fake package.json for sending to NSP (adds ability to exclude packages using `exclusions: []` in .nsprc)
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 | |
const | |
resolve = require('path').resolve, | |
loadJSON = function (file) { | |
return JSON.parse(require('fs').readFileSync(file).toString()); | |
}, | |
dependencySources = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies', | |
'bundledDependencies']; | |
var p = '', | |
packageData, | |
nsprc, | |
fakePackage = { | |
name: 'nsp-fake' | |
}; | |
// extract the current source path | |
process.argv[2] && (p = process.argv[2].replace(/\/?package\.json$/, '')); | |
!p && (p = '.'); | |
// extract data from package and nsprc | |
packageData = loadJSON(resolve(p + '/package.json')); | |
try { | |
nsprc = loadJSON(resolve(p + '/.nsprc')); | |
} | |
catch (e) { | |
nsprc = {}; | |
} | |
!Array.isArray(nsprc.exclusions) && (nsprc.exclusions = []); | |
// copy all dependencies to fake data and exclude exceptions | |
dependencySources.forEach(function (src) { | |
packageData[src] && (fakePackage[src] = {}) && Object.keys(packageData[src]).forEach(function (dep) { | |
nsprc.exclusions.indexOf(dep) === -1 && (fakePackage[src][dep] = packageData[src][dep]); | |
}); | |
}); | |
// stdout | |
process.stdout.write(JSON.stringify(fakePackage, 0, 2) + '\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script simply makes a temporary package.json for use with nsp. Usage in any script is simple:
The
.nsprc
can contain exceptions and exclusions.As a bonus, it also masks privacy by not sending additional details of package.json