-
Notifications
You must be signed in to change notification settings - Fork 61
/
gulpfile.js
95 lines (85 loc) · 2.97 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
var gulp = require('gulp');
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 babel = require("gulp-babel");
var tslint = require("gulp-tslint");
var sourcemaps = require("gulp-sourcemaps");
var gulpPath = path.join(__dirname, 'node_modules/.bin/gulp' + (win32 && '.cmd' || ''));
var typescript = require('typescript');
var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json', { sourceMap: false, typescript: typescript });
var metadata = {
lib: ['lib/**/*.ts', '!lib/**/*.d.ts'],
spec: ['spec/**/*.ts', '!spec/**/*.d.ts'],
};
gulp.task('typescript', ['clean'], function () {
return tsProject.src()
// .pipe(tslint({
// formatter: "verbose"
// }))
// .pipe(tslint.report())
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(babel())
.pipe(sourcemaps.write())
.pipe(gulp.dest('.'));
});
gulp.task('dist', ['typescript'], function () {
return gulp.src(['lib/**/*.js'])
.pipe(gulp.dest('dist'));
});
gulp.task('clean', ['clean:lib', 'clean:dist', 'clean:spec']);
gulp.task('clean:dist', function (done) {
del(['dist/**/*.js']).then(function (paths) {
_.each(paths, function (path) {
gutil.log(gutil.colors.red('Deleted ') + gutil.colors.magenta(path.replace(__dirname, '').substring(1)));
});
done();
});
});
gulp.task('clean:lib', function (done) {
del(metadata.lib.map(function (z) {
return gutil.replaceExtension(z, '.js');
})).then(function (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');
})).then(function (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('npm-postinstall', []);
gulp.task('npm-prepublish', ['dist']);
// The default task (called when you run `gulp` from CLI)
gulp.task('default', ['typescript']);