-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
39 lines (32 loc) · 908 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
'use strict';
const compileSoy = require('./lib/pipelines/compileSoy');
const consume = require('stream-consume');
const defaultOptions = require('./lib/options');
const gutil = require('gulp-util');
const merge = require('merge');
const vfs = require('vinyl-fs');
module.exports = function(options) {
options = merge(
{
handleError: handleError
},
defaultOptions,
options
);
if (!Array.isArray(options.dest)) {
options.dest = [options.dest];
}
let stream = vfs
.src(options.src)
.pipe(compileSoy(options).on('error', options.handleError));
options.dest.forEach(dest => (stream = stream.pipe(vfs.dest(dest))));
if (!options.skipConsume) {
consume(stream);
}
return stream;
};
function handleError(error) {
const source = error.plugin || 'metal-tools-soy';
console.error(new gutil.PluginError(source, error.message).toString());
this.emit('end'); // jshint ignore:line
}