forked from OmniSharp/omnisharp-atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
110 lines (90 loc) · 3.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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 fs = require('fs');
var path = require('path');
var _ = require('lodash');
var win32 = process.platform === "win32";
var spawn = require('child_process').spawn;
var gulpPath = path.join(__dirname, 'node_modules/.bin/gulp' + (win32 && '.cmd' || ''));
// 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);
});
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('watch', function() {
// Watch is not installed by default if you want to use it
// you need to install manually but don't save it as it causes CI issues.
var watch = require('gulp-watch');
// Auto restart watch when gulpfile is changed.
var p = spawn(gulpPath, ['file-watch'], {stdio: 'inherit'});
return watch('gulpfile.js', function() {
p.kill();
p = spawn(gulpPath, ['file-watch'], {stdio: 'inherit'});
});
});
gulp.task('file-watch', function() {
// Watch is not installed by default if you want to use it
// you need to install manually but don't save it as it causes CI issues.
var watch = require('gulp-watch');
var plumber = require('gulp-plumber');
var newer = require('gulp-newer');
var lib = tsTranspiler(gulp.src(metadata.lib)
.pipe(watch(metadata.lib))
.pipe(plumber())
.pipe(newer('./lib')), './lib')
var spec = tsTranspiler(gulp.src(metadata.spec)
.pipe(watch(metadata.spec))
.pipe(plumber())
.pipe(newer('./spec')), './spec');
return merge(lib, spec);
});
gulp.task('npm-postinstall', ['typescript']);
gulp.task('npm-prepublish', ['typescript']);
// The default task (called when you run `gulp` from CLI)
gulp.task('default', ['typescript']);