-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (41 loc) · 923 Bytes
/
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
54
55
var typescript = require("typestring"),
through = require("through");
var isTypescript, compile, typeify;
isTypescript = (function () {
var tsReg = new RegExp("\\.ts$", "i");
return function (file) {
return tsReg.test(file);
};
}());
compile = function (file, data, callback) {
var compiled;
try {
compiled = typescript.compile(data.toString());
} catch (e) {
return callback(e);
}
callback(null, compiled);
};
typeify = function (file) {
var data, stream, write, end;
if (!isTypescript(file)) {
return through();
}
data = "";
write = function (buf) {
data += buf;
};
end = function () {
compile(file, data, function (error, result) {
if (error) {
stream.emit("error", error);
}
stream.queue(result);
stream.queue(null);
});
};
return stream = through(write, end);
};
typeify.compile = compile;
typeify.isTypescript = isTypescript;
module.exports = typeify;