UNPKG

1.42 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.10.0
2(function() {
3 var compiler, kit, path, through;
4
5 compiler = require("../compiler");
6
7 through = require("through2");
8
9 path = require("path");
10
11 kit = require("./kit");
12
13 module.exports = function(filename, opts) {
14 var chunks, eopts, flush, transform;
15 if (opts == null) {
16 opts = {};
17 }
18 eopts = compiler.FILE_EXTENSIONS[path.extname(filename)];
19 if (eopts === false) {
20 return through();
21 }
22 if (eopts == null) {
23 eopts = {};
24 }
25 opts = kit.merge({}, eopts, opts);
26 if (opts.transform == null) {
27 opts.transform = {};
28 }
29 opts.transform.filename = filename;
30 chunks = [];
31 transform = function(chunk, encoding, callback) {
32 chunks.push(chunk);
33 return callback();
34 };
35 flush = function(callback) {
36 var e, error, res, source;
37 source = Buffer.concat(chunks).toString();
38 try {
39 if (opts.timing) {
40 console.time("transform " + filename);
41 }
42 res = compiler.compile(source, opts);
43 if (opts.timing) {
44 console.timeEnd("transform " + filename);
45 }
46 if (opts.transformDebug) {
47 console.log("result:", res);
48 }
49 this.push(res);
50 return callback();
51 } catch (error) {
52 e = error;
53 return callback(e);
54 }
55 };
56 return through(transform, flush);
57 };
58
59}).call(this);