-
Notifications
You must be signed in to change notification settings - Fork 110
/
gulpfile.js
199 lines (169 loc) · 5.28 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
'use strict';
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var path = require('path');
var gulp = require('gulp');
var sass = require('gulp-sass');
var scsslint = require('gulp-scss-lint');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer-core');
var tsc = require('gulp-typescript');
var concat = require('gulp-concat');
var tslint = require('gulp-tslint');
var foreach = require('gulp-foreach');
var watch = require('gulp-watch');
var sourcemaps = require('gulp-sourcemaps');
var merge = require('merge-stream');
var debug = require('gulp-debug');
var del = require('del');
var typescript = require('typescript');
var mocha = require('gulp-mocha');
var tsLintConfig = require('./src/lint/tslint');
var gr = require('./gulp-reporters');
// client -> client_build_tmp -> client_build -> public
// server -> build
var STYLE_NAME = 'pivot.css';
gulp.task('style', function() {
var errorTexts = [];
return gulp.src('./src/client/**/*.scss')
.pipe(scsslint({
config: './src/lint/sass-lint.yml',
customReport: gr.sassLintReporterFactory({
errorTexts: errorTexts
})
}))
.pipe(sass().on('error', gr.sassErrorFactory({
errorTexts: errorTexts
})))
.pipe(postcss([
autoprefixer({
browsers: ['> 1%', 'last 3 versions', 'Firefox ESR', 'Opera 12.1'],
remove: false // If you have no legacy code, this option will make Autoprefixer about 10% faster.
})
]))
.pipe(concat(STYLE_NAME))
.pipe(gulp.dest('./build/public'))
.on('finish', function() {
gr.writeErrors('./webstorm/style-errors', errorTexts);
});
});
// TypeScript ------------------------------------------
gulp.task('client:tsc', function() {
var errorTexts = [];
function fixPath(str) {
return str.replace('/build/client_tmp/', '/src/client/');
}
var sourceFiles = gulp.src(['./src/client/**/*.ts'])
.pipe(gr.jsxFixerFactory())
.pipe(gulp.dest('./build/client_tmp/')) // typescript requires actual files on disk, not just in memory
.pipe(tslint({
configuration: tsLintConfig
}))
.pipe(tslint.report(
gr.tscLintReporterFactory({
errorTexts: errorTexts,
fixPath: fixPath
}),
{ emitError: false }
));
var typeFiles = gulp.src(['./typings/**/*.d.ts']);
return merge(sourceFiles, typeFiles)
//.pipe(sourcemaps.init())
.pipe(tsc(
{
typescript: typescript,
noImplicitAny: true,
noEmitOnError: true,
target: 'ES5',
module: 'commonjs'
},
undefined,
gr.tscReporterFactory({
errorTexts: errorTexts,
fixPath: fixPath,
onFinish: function() { gr.writeErrors('./webstorm/tsc-client-errors', errorTexts); }
})
))
//.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '../client' }))
.pipe(gulp.dest('./build/client/'));
});
gulp.task('server:tsc', function() {
var errorTexts = [];
var sourceFiles = gulp.src(['./src/server/**/*.ts'])
.pipe(tslint({
configuration: tsLintConfig
}))
.pipe(tslint.report(
gr.tscLintReporterFactory({
errorTexts: errorTexts
}),
{ emitError: false }
));
var typeFiles = gulp.src(['./typings/**/*.d.ts']);
return merge(sourceFiles, typeFiles)
.pipe(sourcemaps.init())
.pipe(tsc(
{
typescript: typescript,
noImplicitAny: true,
noEmitOnError: true,
target: 'ES5',
module: 'commonjs'
},
undefined,
gr.tscReporterFactory({
errorTexts: errorTexts,
onFinish: function() { gr.writeErrors('./webstorm/tsc-server-errors', errorTexts); }
})
))
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: '../../src/server'
}))
.pipe(gulp.dest('./build/server'));
});
// ----------------------------------------------------------------
gulp.task('client:test', function() {
return gulp.src('./build/client/**/*.mocha.js', {read: false})
// gulp-mocha needs filepaths so you can't have any plugins before it
.pipe(mocha({
reporter: 'spec'
}));
});
gulp.task('server:test', function() {
return gulp.src('./build/server/**/*.mocha.js', {read: false})
// gulp-mocha needs filepaths so you can't have any plugins before it
.pipe(mocha({
reporter: 'spec'
}));
});
gulp.task('client:bundle', ['client:tsc'], function() {
return gulp.src('./build/client/*.js')
.pipe(foreach(function(stream, file) {
// From: https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-uglify-sourcemap.md
var b = browserify({
//debug: true,
entries: file.path
});
return b.bundle()
.pipe(source(path.basename(file.path)))
.pipe(buffer());
}))
.pipe(gulp.dest('./build/public'));
});
gulp.task('clean', function(cb) {
del(['./build/**'], cb);
});
gulp.task('all', ['style', 'server:tsc', 'client:tsc', 'client:bundle']);
gulp.task('watch', ['all'], function() {
watch('./src/client/**/*.scss', function() {
gulp.start('style');
});
watch(['./src/client/**/*.ts', './assets/icons/**'], function() {
gulp.start('client:bundle');
});
watch('./src/server/**', function() {
gulp.start('server:tsc');
});
});