-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
153 lines (121 loc) · 3.24 KB
/
Copy pathgulpfile.js
File metadata and controls
153 lines (121 loc) · 3.24 KB
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
'use strict';
const browserSync = require('browser-sync');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const historyApi = require('connect-history-api-fallback');
const karma = require('karma');
const tslint = require('gulp-tslint');
const webpack = require('webpack');
const WebpackServer = require('webpack-dev-server');
//=========================================================
// PATHS
//---------------------------------------------------------
const paths = {
src: {
ts: 'src/**/*.ts'
},
target: 'target'
};
//=========================================================
// CONFIG
//---------------------------------------------------------
const config = {
browserSync: {
files: [paths.target + '/**/*'],
notify: false,
open: false,
port: 3000,
reloadDelay: 500,
server: {
baseDir: paths.target
}
},
karma: {
configFile: __dirname + '/karma.conf.js'
},
tslint: {
report: {
options: {emitError: true},
type: 'verbose'
}
},
webpack: {
dev: './webpack.dev',
dist: './webpack.dist'
}
};
//=========================================================
// TASKS
//---------------------------------------------------------
gulp.task('clean.target', () => del(paths.target));
gulp.task('lint', () => {
return gulp.src(paths.src.ts)
.pipe(tslint())
.pipe(tslint.report(
config.tslint.report.type,
config.tslint.report.options
));
});
gulp.task('serve', done => {
config.browserSync.server.middleware = [historyApi()];
browserSync.create()
.init(config.browserSync, done);
});
gulp.task('serve.dev', done => {
let conf = require(config.webpack.dev);
let compiler = webpack(conf);
let server = new WebpackServer(compiler, conf.devServer);
let host = conf.devServer.host;
let port = conf.devServer.port;
server.listen(port, host, () => {
gutil.log(gutil.colors.gray('-------------------------------------------'));
gutil.log('WebpackDevServer:', gutil.colors.magenta(`http://${host}:${port}`));
gutil.log(gutil.colors.gray('-------------------------------------------'));
done();
});
});
gulp.task('ts', done => {
let conf = require(config.webpack.dist);
webpack(conf).run((error, stats) => {
if (error) throw new gutil.PluginError('webpack', error);
gutil.log(stats.toString(conf.stats));
done();
});
});
//===========================
// BUILD
//---------------------------
gulp.task('build', gulp.series(
'clean.target',
'ts'
));
//===========================
// DEVELOP
//---------------------------
gulp.task('default', gulp.task('serve.dev'));
//===========================
// TEST
//---------------------------
function karmaServer(options, done) {
let server = new karma.Server(options, exitCode => {
if (exitCode > 0) process.exit(exitCode);
done();
});
server.start();
}
gulp.task('test', done => {
config.karma.singleRun = true;
karmaServer(config.karma, done);
});
gulp.task('test.watch', done => {
karmaServer(config.karma, done);
});
//===========================
// RELEASE
//---------------------------
gulp.task('dist', gulp.series(
'lint',
'test',
'build'
));