forked from ludohenin/gulp-inline-ng2-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 867 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
"use strict";
var gutil = require('gulp-util');
var through = require('through2');
var PLUGIN_NAME = 'gulp-inline-ng2-template';
module.exports = exports = function inline(options) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
try {
var parse = require('./parser')(file, options);
var _this = this
parse(function (err, contents) {
if (err) return cb(new gutil.PluginError(PLUGIN_NAME, err, {fileName: file.path}));
file.contents = new Buffer(contents);
_this.push(file);
process.nextTick(cb);
});
} catch (err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, err, {fileName: file.path}));
}
});
};