aboutsummaryrefslogtreecommitdiff
path: root/npmPackages/_scripts/package.js
blob: a00665550400b805d1ec4a5313e0f652907bb397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
};