-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (37 loc) · 1022 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var fs = require('fs');
var Transform = require('stream').Transform;
var Vinyl = require('vinyl');
module.exports = function() {
return new Transform({
objectMode: true,
transform(file, enc, cb) {
var dir = file.dirname;
var hash = file.contents.toString().trim();
var tags = fs.readdirSync(dir + '/refs/tags', 'utf8').reverse();
var ver = '';
if (hash.slice(0, 5) === 'ref: ') {
hash = fs.readFileSync(dir + '/' + hash.slice(5).trim(), 'utf8').trim();
}
tags.some((tag, i) => {
var h = fs.readFileSync(dir + '/refs/tags/' + tag, 'utf8').trim();
if (h === hash) {
ver = tag;
}
return ver || i > 50;
});
this.push(
new Vinyl({
path: 'revision.txt',
contents: Buffer.from(hash),
})
);
this.push(
new Vinyl({
path: 'version.txt',
contents: Buffer.from(ver),
})
);
cb();
},
});
};