-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgulpfile.js
76 lines (60 loc) · 2.21 KB
/
gulpfile.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
75
76
var gulp = require('gulp');
var ts = require('typescript');
var through = require('through2');
var gutil = require('gulp-util');
var merge = require('merge-stream');
var del = require('del');
var _ = require('lodash');
var path = require('path');
// Simply take TS code and strip anything not javascript
// Does not do any compile time checking.
function tsTranspile() {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
var res = ts.transpile(file.contents.toString(), { module: ts.ModuleKind.CommonJS });
file.contents = new Buffer(res);
file.path = gutil.replaceExtension(file.path, '.js');
gutil.log(gutil.colors.cyan('Writing ') + gutil.colors.green(_.trim(file.path.replace(__dirname, ''), path.sep)));
this.push(file);
cb();
});
}
function tsTranspiler(source, dest) {
return source
.pipe(tsTranspile())
.pipe(gulp.dest(dest));
}
var metadata = {
lib: ['lib/**/*.ts', '!lib/**/*.d.ts'],
//spec: ['spec/**/*.ts'],
}
gulp.task('typescript', ['clean'], function() {
var lib = tsTranspiler(gulp.src(metadata.lib), './lib');
//var spec = tsTranspiler(gulp.src(metadata.spec), './spec');
//return merge(lib, spec);
return lib;
});
gulp.task('clean', ['clean:lib'/*, 'clean:spec'*/]);
gulp.task('clean:lib', function(done) {
del(metadata.lib.map(function(z) { return gutil.replaceExtension(z, '.js'); }), function(err, paths) {
_.each(paths, function(path) {
gutil.log(gutil.colors.red('Deleted ') + gutil.colors.magenta(path.replace(__dirname, '').substring(1)));
});
done();
});
});
gulp.task('clean:spec', function(done) {
del(metadata.spec.map(function(z) { return gutil.replaceExtension(z, '.js'); }), function(err, paths) {
_.each(paths, function(path) {
gutil.log(gutil.colors.red('Deleted ') + gutil.colors.magenta(path.replace(__dirname, '').substring(1)));
});
done();
});
});
gulp.task('npm-postinstall', ['typescript']);
gulp.task('npm-prepublish', ['typescript']);
// The default task (called when you run `gulp` from CLI)
gulp.task('default', ['typescript']);