/
index.js
91 lines (58 loc) · 2.17 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var Through = require('through2');
var Revisioner = require('./revisioner');
var path = require('path');
var RevAll = (function () {
var RevAll = function (options) {
if (!(this instanceof RevAll)) {
return new RevAll(options);
}
this.revisioner = new Revisioner(options);
};
RevAll.prototype.revision = function () {
var revisioner = this.revisioner;
// Feed the RevAll Revisioner with all the files in the stream, don't emit them until all of them have been processed
return Through.obj(function (file, enc, callback) {
if (file.isStream()) {
throw new Error('Streams are not supported!');
}
if (file.isBuffer()) {
revisioner.processFile(file);
}
callback();
}, function (callback) {
revisioner.run();
var files = revisioner.files;
for (var filename in files) {
var newfilepath = path.join(files[filename].base, files[filename].revPath);
files[filename].path = newfilepath;
this.push(files[filename]);
}
callback();
});
};
RevAll.prototype.versionFile = function () {
var revisioner = this.revisioner;
// Drop any existing files off the stream, push the generated version file
return Through.obj(function (file, enc, callback) {
// Drop any existing files off the stream
callback();
}, function (callback) {
if (revisioner.files.length > 0)
this.push(revisioner.versionFile());
callback();
});
};
RevAll.prototype.manifestFile = function () {
var revisioner = this.revisioner;
// Drop any existing files off the stream, push the generated manifest file
return Through.obj(function (file, enc, callback) {
callback();
}, function (callback) {
if (revisioner.files.length > 0)
this.push(revisioner.manifestFile());
callback();
});
};
return RevAll;
})();
module.exports = RevAll;