-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
108 lines (93 loc) · 3.22 KB
/
gulpfile.js
File metadata and controls
108 lines (93 loc) · 3.22 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
// Gulpfile.js
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');
//const Cache = require('gulp-file-cache');
const mocha = require('gulp-mocha');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
//const cache = new Cache();
const src = './src/**/*.js';
const dest = 'lib';
const test = 'example';
gulp.task('lint', function() {
return gulp.src([src, test])
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('compile', ['lint'], function() {
var stream = gulp.src(src) // your ES2015 code
.pipe(sourcemaps.init())
//.pipe(cache.filter()) // remember files
// leave out presets here, breaks `add-module-exports` plugin
.pipe(babel()) // compile new ones
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: '../src'
}))
//.pipe(cache.cache()) // cache them
.pipe(gulp.dest(dest)); // write them
return stream; // important for gulp-nodemon to wait for completion
});
gulp.task('test', ['compile'], function() {
const stream = gulp.src([dest])
.pipe(mocha({
reporter: 'list',
// prevent from hanging on callback
exit: true
}))
.once('error', (err) => {
process.exit(1);
})
.once('end', () => {
//process.exit();
});
return stream;
});
gulp.task('server', ['test'], function() {
var stream = nodemon({
script: 'example/server', // run ES5 code
ext: 'js, html',
watch: ['src', 'test', 'example'], // watch ES2015 code
tasks: ['test'] // compile synchronously onChange
})
.on('restart', function() {
/* eslint-disable no-console */
console.log('nodemon restarted');
/* eslint-enable no-console */
})
.on('start', function() {
/* eslint-disable no-console */
console.log('nodemon started');
/* eslint-enable no-console */
// use start event to reload browsers
// also: "browser-sync" only works when there is the tag "body"
browserSync.reload();
})
.on('crash', function() {
/* eslint-disable no-console */
console.error('nodemon crashed!\n');
/* eslint-enable no-console */
// emitting causes to run task, crashes nodemon
//stream.emit('restart', 10) // restart the server in 10 seconds
});
return stream;
});
gulp.task('browser-sync', ['server'], function() {
//https://github.com/visionmedia/superagent/issues/980
if (parseInt(process.versions.node.split('.')[0], 10) >= 9) {
console.log('\x1b[41m', 'browser-sync won\'t work if you run `gulp` with HTTP/2 enabled, so use `gulp no-bs` and test manually', '\x1b[0m');
}
browserSync.init({
port: 3003,
proxy: 'https://localhost:3001',
browser: 'firefox',
ui: {
port: 8080
},
reloadDelay: 1000
});
});
gulp.task('no-bs', ['server']);
gulp.task('default', ['browser-sync']);