-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (37 loc) · 1.1 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
const through = require('through2');
const createManifest = require('./core/manifest')
module.exports = function(opts) {
//TODO God willing: option to save a manifest so don't repeat ourselves
const getManifest = createManifest(opts)
const name = opts.name || ""
async function bufferContents(file, enc, cb) {
// ignore empty files
if (file.isNull()) {
cb();
return;
}
// we don't do streams (yet)
if (file.isStream()) {
this.emit('error', new Error('process-manifest: Streaming not supported'));
cb();
return;
}
//Queue file for build
await (await getManifest).queue(file)
cb()
}
async function endStream (cb) {
try {
//Build
const publishedHash = await (await getManifest).recalculate()
console.log((opts.name ?
"Published " + opts.name + " hash: " :
"Published hash: ") + publishedHash)
opts.verbose && console.log("----------------------")
cb(null, publishedHash)
} catch (error) {
cb(error)
}
}
return () => through.obj(bufferContents, endStream);
};