From 0215671c6aab24e1885074761f44c502f0bb00e2 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Fri, 27 Sep 2019 16:05:42 +0200 Subject: Initial PoC --- npmPackages/_scripts/package.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 npmPackages/_scripts/package.js (limited to 'npmPackages/_scripts/package.js') 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 -- cgit v1.2.3