-
Notifications
You must be signed in to change notification settings - Fork 71
/
gulpfile.js
134 lines (111 loc) · 2.79 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
const gulp = require('gulp');
const log = require('fancy-log');
const colors = require('ansi-colors');
const uglify = require('gulp-uglify');
const plumber = require('gulp-plumber');
const tslint = require('gulp-tslint');
const size = require('gulp-size');
const rename = require('gulp-rename');
const webpack = require('webpack-stream');
const browserSync = require('browser-sync');
const del = require('del');
const webpackConfig = require('./webpack.config.js');
const reload = browserSync.reload;
var exitOnError = false;
async function help() {
log('\n' +
colors.green('GULP TASKS') + '\n\t' +
// default | help
colors.yellow('default | help') + '\n\t\t' +
'Shows the available tasks\n\n\t' +
// monitor
colors.yellow('monitor') + '\n\t\t' +
'Real time check for changes in js files.\n\t\tIt handles errors and rebuilds the minified and compiled files.\n\n\t' +
// release
colors.yellow('release') + '\n\t\t' +
'Rebuild and concatenate all js files.\n\t\tMinifies and uglifies JS for deploy.\n\t\t'
);
}
function errorHandler(error) {
if (exitOnError === false) {
return this.emit('end');
}
}
function cleanDist() {
return del('dist/**', { force: true });
}
function copyHtml() {
return gulp.src('src/index*.html')
.pipe(gulp.dest('dist/latest/'));
}
function copyTestData() {
return gulp.src('src/testdata/*')
.pipe(gulp.dest('dist/latest/testdata/'));
}
function compileJs() {
return gulp.src('src/*.ts')
.pipe(plumber({
errorHandler: errorHandler
}))
.pipe(tslint({ formatter: 'verbose' }))
.pipe(tslint.report())
.pipe(webpack(webpackConfig))
.pipe(rename('bootstrap-autocomplete.js'))
.pipe(gulp.dest('dist/latest/'));
}
function build(cb) {
return gulp.series(
copyHtml,
copyTestData,
compileJs
)(cb);
}
function watch(cb) {
gulp.watch('src/**/*', gulp.series(
build,
function (done) {
reload();
done();
}), cb)
}
function monitor(cb) {
return gulp.series(
build,
gulp.parallel(watch, devServer)
)(cb);
}
async function devServer() {
browserSync({
server: {
baseDir: 'dist/latest'
},
open: false,
});
gulp.watch(['*.html', '*.js', 'testdata/*'], { cwd: 'dist/latest' }, reload);
}
function minify() {
return gulp.src('dist/latest/bootstrap-autocomplete.js')
.pipe(rename({
extname: '.min.js'
}))
.pipe(size({ title: 'PRE-MINIFY' }))
.pipe(uglify({ mangle: true }))
.pipe(size({ title: 'POST-MINIFY' }))
.pipe(gulp.dest('dist/latest'));
}
function release(cb) {
return gulp.series(
cleanDist,
build, minify
)(cb);
}
function test(cb) {
exitOnError = true;
return gulp.series(
compileJs
)(cb);
}
exports.default = help;
exports.monitor = monitor;
exports.release = release;
exports.test = test;