-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulp-dotjsify.js
More file actions
39 lines (32 loc) · 1.01 KB
/
Copy pathgulp-dotjsify.js
File metadata and controls
39 lines (32 loc) · 1.01 KB
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
var through = require('through2'),
gutil = require('gulp-util'),
doT = require('dot'),
wrapper = {
amd: function (module) {
return 'define(["exports"], function (exports) { exports = ' + module.toString() + ' });';
},
cjs: function (module) {
return 'module.exports = ' + module.toString();
},
es6: function (module) {
return 'export default ' + module.toString();
}
};
module.exports = function precompile(options) {
return through.obj(function (file, enc, cb) {
if (file.isNull())
return cb();
if (file.isStream())
return cb(new Error(PLUGIN_NAME + ': streaming is not supported'));
file.path = gutil.replaceExtension(file.path, '.js');
file.contents = new Buffer(
wrapper[options.type](
doT.template(
file.contents.toString()
)
)
);
this.push(file);
cb();
})
}