UNPKG

875 BJavaScriptView Raw
1
2'use strict';
3
4var path = require('path');
5var gutil = require('gulp-util');
6var through2 = require('through2');
7var PluginError = gutil.PluginError;
8var ResourceEmbedder = require('./lib/resource-embedder2');
9
10module.exports = function (options) {
11 return through2.obj(function (file, enc, cb) {
12
13 var filepath = file.path;
14
15 //file not exsists
16 if (file.isNull()) {
17 this.emit('error', new PluginError('gulp-embed', 'File not found: "' + filepath + '"'));
18 return cb();
19 }
20
21 var embedder = new ResourceEmbedder(filepath, options);
22
23 embedder.get(function (markup) {
24 var f = new gutil.File({
25 cwd: '',
26 path: file.relative,
27 contents: new Buffer(markup)
28 });
29
30 this.push(f);
31 cb();
32 }.bind(this));
33
34 });
35};
\No newline at end of file