-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
158 lines (131 loc) · 4.35 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'use strict';
var gulp = require('gulp');
var ts = require('gulp-typescript');
var jasmine = require('gulp-jasmine');
var plumber = require('gulp-plumber');
var sourcemap = require('gulp-sourcemaps');
var rimraf = require('gulp-rimraf');
var replace = require('gulp-replace');
var tslint = require('gulp-tslint');
var formatter = require('typescript-formatter');
var shell = require('gulp-shell');
var path = require('path');
var merge = require('merge2');
var runsequence = require('run-sequence');
var through = require('through2');
var paths = {
source: "source/",
output: "dist/",
spec: "spec/"
}
gulp.task('clean:typescript', function () {
return gulp.src([paths.output], { read: false })
.pipe(rimraf());
});
gulp.task('clean:tests', function () {
return gulp.src([paths.spec + '**/*.spec.js', paths.spec + '**/*.map'], { read: false })
.pipe(rimraf());
});
gulp.task('clean', ['clean:tests', 'clean:typescript'], function () {
});
gulp.task('compile:typescript', ['clean:typescript'], function () {
var project = ts.createProject('tsconfig.json', {
typescript: require('typescript')
});
var tsResult = gulp.src([paths.source + '**/*.ts', "node_modules/@types/**/index.d.ts", "!node_modules/@types/**/node_modules/**/index.d.ts"])
.pipe(sourcemap.init())
.pipe(ts(project));
return merge([
tsResult.dts.pipe(gulp.dest(paths.output)),
tsResult.js
.pipe(sourcemap.write('.', {
sourceRoot: function (file) {
var relative = path.relative(file.path, path.join(__dirname, "source"));
var relativeSource = path.join(relative, 'source')
return relativeSource;
}
}))
.pipe(gulp.dest(paths.output))
]);
});
gulp.task('lint:typescript', function () {
return gulp.src([paths.source + '**/*.ts', paths.spec + '**/*.ts'])
.pipe(plumber())
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report());
});
function gulpTypescriptFormatter(options) {
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
// return empty file
return cb(null, file);
}
if (file.isBuffer()) {
var fileContentPromise = formatter.processString(file.path, String(file.contents), options);
fileContentPromise.then(function(result) {
file.contents = new Buffer(result.dest);
cb(null, file);
});
}
});
}
function format(sourcePattern, targetDir) {
return gulp.src(sourcePattern)
.pipe(gulpTypescriptFormatter({
baseDir: '.',
tslint: true, // use tslint.json file ?
editorconfig: true, // use .editorconfig file ?
tsfmt: true, // use tsfmt.json ?
}))
.pipe(gulp.dest(targetDir));
}
gulp.task('format:sources', function () {
return format(paths.source + '**/*.ts', paths.source);
});
gulp.task('format:tests', function () {
return format(paths.spec + '**/*.ts', paths.spec);
});
gulp.task('format', ['format:sources', 'format:tests'], function () { });
gulp.task('compile:tests', ['compile:typescript', 'clean:tests'], function () {
var project = ts.createProject('tsconfig.json', {
typescript: require('typescript')
});
var tsResult = gulp.src([paths.spec + '**/*spec.ts', "node_modules/@types/**/index.d.ts", "!node_modules/@types/**/node_modules/**/index.d.ts"])
.pipe(sourcemap.init())
.pipe(ts(project));
return tsResult.js
.pipe(sourcemap.write('.', {
sourceRoot: function (file) {
var relative = path.relative(file.path, path.join(__dirname, "spec"));
var relativeSource = path.join(relative, 'spec')
return relativeSource;
}
}))
.pipe(replace(/(require\('\..\/source\/)/g, 'require(\'..\/dist\/'))
.pipe(gulp.dest(paths.spec));
});
gulp.task('test:jasmine', function (done) {
return gulp.src('spec/*.js')
.pipe(plumber())
.pipe(jasmine({ verbose: true }));
});
gulp.task('test', function (done) {
runsequence('compile:tests', 'lint:typescript', 'test:jasmine', function (err) {
runsequence('clean:tests');
done();
});
});
gulp.task('test-no-compile', function (done) {
runsequence('test:jasmine', function (err) {
runsequence('clean:tests');
done();
});
});
gulp.task('watch', ['test'], function () {
gulp.watch(paths.source + '**/*.ts', ['test', 'lint:typescript']);
gulp.watch(paths.spec + '**/*spec.ts', ['test', 'lint:typescript']);
});
gulp.task('default', ['test'], function () {
});