diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2019-09-27 16:05:42 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2019-10-02 07:32:32 +0200 |
commit | 0215671c6aab24e1885074761f44c502f0bb00e2 (patch) | |
tree | 14821547641342b35644f9d63a63a46bab104253 /npmPackages/_scripts/package.js | |
download | npm.nix-0215671c6aab24e1885074761f44c502f0bb00e2.tar.gz |
Initial PoC
Diffstat (limited to 'npmPackages/_scripts/package.js')
-rw-r--r-- | npmPackages/_scripts/package.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/npmPackages/_scripts/package.js b/npmPackages/_scripts/package.js new file mode 100644 index 0000000..a006655 --- /dev/null +++ b/npmPackages/_scripts/package.js @@ -0,0 +1,40 @@ +const fs = require('fs'); +const path = require('path'); +const process = require('process'); + +process.stdin.setEncoding('utf8'); + +function readPackage(dir) { + return new Promise((resolve, reject) => { + fs.readFile(path.join(dir, 'package.json'), (err, data) => { + if (err) { + return reject(err); + } else { + resolve({ + path: path.resolve(dir), + info: JSON.parse(data) + }); + } + }); + }); +} + +function pipeThrough(filter) { + var body = ''; + + process.stdin.on('data', (data) => { + body += data; + }); + + process.stdin.on('end', () => { + var pkg = JSON.parse(body); + filter(pkg, (newpkg) => { + process.stdout.write(JSON.stringify(newpkg, null, 2)) + }); + }) +} + +module.exports = { + readPackage, + pipeThrough +};
\ No newline at end of file |