-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
30 lines (23 loc) · 810 Bytes
/
index.js
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
var findRoot = require('find-root'),
path = require('path'),
through2 = require('through2');
function versionify(file, options) {
options = options || {};
var filter = options.filter;
if (filter && !filter.test(file)) {
return through2();
}
var placeholder = options.placeholder || '__VERSION__',
re = new RegExp(placeholder, 'g'),
version = options.version ||
require(path.join(findRoot(file), 'package.json')).version;
return through2({objectMode: true}, function(chunk, encoding, callback) {
return callback(null, chunk.toString().replace(re, version));
});
}
versionify.configure = function(options) {
return function(file) {
return versionify(file, options);
};
};
module.exports = versionify;