forked from gulp-community/gulp-coffee
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulp-iced-coffee.js
74 lines (64 loc) · 1.98 KB
/
gulp-iced-coffee.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Generated by IcedCoffeeScript 108.0.11
var PluginError, applySourceMap, gulpIcedCoffee, gutil, iced, merge, path, through;
through = require("through2");
iced = require("iced-coffee-script");
gutil = require("gulp-util");
applySourceMap = require("vinyl-sourcemaps-apply");
path = require("path");
merge = require("merge");
PluginError = gutil.PluginError;
gulpIcedCoffee = function(options) {
var replaceExtension, transform;
replaceExtension = function(path) {
path = path.replace(/\.coffee\.md$/, ".litcoffee");
path = path.replace(/\.iced\.md$/, ".liticed");
return gutil.replaceExtension(path, ".js");
};
transform = function(file, enc, cb) {
var data, defaults, dest, err, str;
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new PluginError("gulp-iced-coffee", "Streaming not supported"));
}
data = void 0;
str = file.contents.toString("utf8");
dest = replaceExtension(file.path);
defaults = {
bare: false,
header: false,
silent: true,
sourceMap: !!file.sourceMap,
sourceRoot: false,
literate: /\.(litcoffee|coffee\.md|liticed|iced\.md)$/.test(file.path),
filename: file.path,
sourceFiles: [file.relative],
generatedFile: replaceExtension(file.relative)
};
options = merge(defaults, options);
try {
if (!options.silent) {
console.log(str);
}
data = iced.compile(str, options);
} catch (_error) {
err = _error;
return cb(new PluginError("gulp-iced-coffee", err));
}
if (!options.silent) {
console.log(data);
}
if (data && data.v3SourceMap && file.sourceMap) {
applySourceMap(file, data.v3SourceMap);
file.contents = new Buffer(data.js);
} else {
file.contents = new Buffer(data);
}
file.path = dest;
return cb(null, file);
};
return through.obj(transform);
};
module.exports = gulpIcedCoffee;
//# sourceMappingURL=gulp-iced-coffee.js.map