aboutsummaryrefslogtreecommitdiff
path: root/npmPackages/_scripts/package.js
diff options
context:
space:
mode:
Diffstat (limited to 'npmPackages/_scripts/package.js')
-rw-r--r--npmPackages/_scripts/package.js40
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