This repository was archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·111 lines (97 loc) · 2.59 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
'use strict';
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const pump = require('pump');
const nodemon = require('gulp-nodemon');
const eslint = require('gulp-eslint');
const istanbul = require('gulp-istanbul');
const jasmine = require('gulp-jasmine');
const coveralls = require('gulp-coveralls');
const reload = browserSync.reload;
const notifier = file => browserSync.notify(`<h4>Changes made to ${file.path.split('/').pop()}.\nRefreshing iDex<h4>`);
gulp.task('browserSync', ['nodemon'], () => {
browserSync.init({
proxy: 'localhost:8080', // local node app address
port: 5000, // use *different* port than above
logLevel: 'debug',
logPrefix: 'iDex',
logFileChanges: true,
logConnections: true,
minify: true,
notify: false,
});
});
browserSync.emitter.on('init', () => {
// eslint-disable-next-line no-console
console.log('iDex have experienced some changes');
});
gulp.task('nodemon', (cb) => {
let called = false;
return nodemon({
script: 'app.js',
ignore: [
'gulpfile.js',
'node_modules/',
],
})
.on('start', () => {
if (!called) {
called = true;
cb();
}
})
.on('restart', () => {
setTimeout(() => {
reload({ stream: false });
}, 1000);
});
});
gulp.task('watch', ['browserSync'], () => {
gulp.watch('public/*.html', reload).on('change', (file) => {
notifier(file);
});
gulp.watch('public/css/*.css', reload).on('change', (file) => {
notifier(file);
});
gulp.watch('public/builds/**/*.js', reload).on('change', (file) => {
notifier(file);
});
gulp.watch('**/*.js', reload).on('change', (file) => {
notifier(file);
});
});
gulp.task('eslint', () => {
gulp.src([
'gulpfile.js',
'public/builds/**/*.js',
'specs/*.js',
'app.js',
])
.pipe(eslint());
});
gulp.task('babel', () => gulp.src(['public/builds/**/*.js'])
.pipe(babel({
presets: ['es2015'],
}))
.pipe(gulp.dest('public/dist/')));
gulp.task('minify', (cb) => {
pump([
gulp.src('public/dist/**/*.js')
.pipe(uglify())
.pipe(rename({ suffix: '.min' })),
gulp.dest('public/lib/'),
], cb);
});
gulp.task('test', () => gulp.src(['specs/InvertedIndexSpec.js'])
.pipe(jasmine()));
gulp.task('coverage', () => gulp.src('specs/*.js')
.pipe(jasmine())
.pipe(istanbul.writeReports())
.on('end', () => {
gulp.src('coverage/lcov.info')
.pipe(coveralls());
}));
gulp.task('default', ['minify', 'watch']);