forked from kotas/gulp-tsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (57 loc) · 1.7 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
54
55
56
57
58
59
60
61
62
63
64
'use strict';
var Compiler = require('./lib/compiler');
var gutil = require('gulp-util');
var through = require('through2');
var async = require('async');
module.exports = function (options) {
var sourceFiles = [];
var emitError = (!options || options.emitError !== false);
function eachFile(file, encoding, done) {
sourceFiles.push(file);
done();
}
function endStream(done) {
if (sourceFiles.length === 0) {
return done();
}
var _this = this;
var compiler = new Compiler(sourceFiles, options);
compiler.on('stdout', function (line) {
gutil.log(gutil.colors.green('[tsc] >'), line);
});
compiler.on('stderr', function (line) {
gutil.log(gutil.colors.red('[tsc] >'), line);
});
compiler.on('error', function (err) {
gutil.log(gutil.colors.red('[tsc] Error: ' + err.toString()));
err.stack && console.log(gutil.colors.gray(err.stack));
});
compiler.on('data', function (file) {
_this.push(file);
});
async.waterfall([
function (next) {
compiler.getVersion(next);
},
function (version, next) {
gutil.log('Compiling TypeScript files using tsc version ' + version);
compiler.compile(next);
}
], function (err) {
if (err) {
gutil.log(gutil.colors.red('Failed to compile TypeScript:', err));
if (emitError) {
Compiler.abortAll(function () {
_this.emit('error', new gutil.PluginError('gulp-tsc', 'Failed to compile: ' + (err.message || err)));
sourceFiles = [];
done();
});
return;
}
}
sourceFiles = [];
done();
});
}
return through.obj(eachFile, endStream);
};