-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
36 lines (28 loc) · 969 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
"use strict";
var PluginError = require('plugin-error');
var through = require('through2');
var applySourceMap = require("vinyl-sourcemaps-apply");
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 PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
try {
var parse = require('./parser')(file, options);
var _this = this;
parse(function (err, result) {
if (err) return cb(new PluginError(PLUGIN_NAME, err, {fileName: file.path}));
file.contents = Buffer.from(result.contents);
applySourceMap(file, result.sourceMap);
_this.push(file);
process.nextTick(cb);
});
} catch (err) {
this.emit('error', new PluginError(PLUGIN_NAME, err, {fileName: file.path}));
}
});
};