Skip to content

Commit

Permalink
add index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
litstat committed Dec 8, 2023
1 parent 29fad25 commit 30d40a4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
},
});
};

0 comments on commit 30d40a4

Please sign in to comment.