-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (22 loc) · 786 Bytes
/
index.js
File metadata and controls
25 lines (22 loc) · 786 Bytes
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
var through = require('through');
var getProperty = require('lodash.get');
var path = require('path');
var fs = require('fs');
function getPackageJson (inDir) {
var dirname = path.dirname(inDir);
var pkg_route = path.join(dirname, 'package.json');
if (fs.existsSync(pkg_route)) return pkg_route;
return getPackageJson(dirname);
}
module.exports = function (file, opts) {
return through(function write(data) {
data = data.toString().replace(/require\((\'|\")package\.(.*?)(\'|\")\)/ig, function (str, p1, propertyPath) {
var package = require(getPackageJson(file));
var property = getProperty(package, propertyPath);
return JSON.stringify(property);
});
this.emit('data', data);
}, function end () { //optional
this.emit('end');
});
};