-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
53 lines (46 loc) · 2.22 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var es = require('event-stream');
var iced = require('iced-coffee-script');
var gutil = require('gulp-util');
var Buffer = require('buffer').Buffer;
var path = require('path');
module.exports = function (opt) {
function modifyFile(file) {
if (file.isNull()) return this.emit('data', file); // pass along
if (file.isStream()) return this.emit('error', new Error("gulp-iced: Streaming not supported"));
var str = file.contents.toString('utf8');
var dest = gutil.replaceExtension(file.path, ".js");
var options = {
literate: /\.(litcoffee|coffee\.md)$/.test(file.path)
};
if (opt) {
options = {
bare: opt.bare != null ? !! opt.bare : false,
runtime: opt.runtime != null ? opt.runtime : 'node',
literate: opt.literate != null ? !! opt.literate : options.literate,
sourceMap: opt.sourceMap != null ? !! opt.sourceMap : false,
filename: file.path,
sourceFiles: [path.basename(file.path)],
generatedFile: path.basename(dest)
}
}
try {
data = iced.compile(str, options);
} catch (err) {
return this.emit('error', new Error(err));
}
if (options.sourceMap) {
sourceMapFile = new gutil.File({
cwd: file.cwd,
base: file.base,
path: dest + '.map',
contents: new Buffer(data.v3SourceMap)
});
this.emit('data', sourceMapFile);
data = data.js + "\n/*\n//# sourceMappingURL=" + path.basename(sourceMapFile.path) + "\n*/\n";
}
file.contents = new Buffer(data);
file.path = dest;
this.emit('data', file);
}
return es.through(modifyFile);
};