1 | "use strict";
|
2 |
|
3 | var gutil = require('gulp-util');
|
4 | var through = require('through2');
|
5 |
|
6 |
|
7 | var PLUGIN_NAME = 'gulp-inline-ng2-template';
|
8 |
|
9 | module.exports = exports = function inline(options) {
|
10 | return through.obj(function (file, enc, cb) {
|
11 | if (file.isNull()) {
|
12 | return cb(null, file);
|
13 | }
|
14 |
|
15 | if (file.isStream()) {
|
16 | return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
17 | }
|
18 |
|
19 | try {
|
20 | var parse = require('./parser')(file, options);
|
21 | var _this = this
|
22 |
|
23 | parse(function (err, contents) {
|
24 | if (err) return cb(new gutil.PluginError(PLUGIN_NAME, err, {fileName: file.path}));
|
25 | file.contents = new Buffer(contents);
|
26 | _this.push(file);
|
27 | process.nextTick(cb);
|
28 | });
|
29 |
|
30 | } catch (err) {
|
31 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, err, {fileName: file.path}));
|
32 | }
|
33 | });
|
34 | };
|