-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
160 lines (142 loc) · 4.14 KB
/
gulpfile.babel.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
'use strict';
/* eslint-disable import/no-extraneous-dependencies */
import gulp from 'gulp';
import nodemon from 'gulp-nodemon';
import plumber from 'gulp-plumber';
import livereload from 'gulp-livereload';
import sass from 'gulp-sass';
import eslint from 'gulp-eslint';
import excludeGitignore from 'gulp-exclude-gitignore';
import mocha from 'gulp-mocha';
import istanbul from 'gulp-istanbul';
import nsp from 'gulp-nsp';
import coveralls from 'gulp-coveralls';
import isparta from 'isparta';
import browserify from 'browserify';
import uglify from 'gulp-uglify';
import path from 'path';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import sourcemaps from 'gulp-sourcemaps';
import flow from 'gulp-flowtype';
// import gutil from 'gulp-util';
// import path from 'path';
// Paths to libraries
const paths = {
allSrcJs: './app/**/*.js',
gulpFile: 'gulpfile.babel.js',
libDir: 'public/js'
};
// SASS
gulp.task('sass', () => gulp.src('./public/css/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./public/css')));
// JAVASCRIPT
gulp.task('js', () => {
const bundler = browserify({
entries: ['./public/src/app.js'], // main js file and files you wish to bundle
debug: true,
extensions: [' ', 'js', 'jsx']
}).transform(babelify.configure({
presets: ['es2015'] // sets the preset to transpile to es2015 (you can also just define a .babelrc instead)
}));
// bundler is simply browserify with all presets set
bundler.bundle()
.on('error', function onError(err) {
console.error(err);
this.emit('end');
})
.pipe(source('app.js')) // main source file
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true })) // create sourcemap before running edit commands so we know which file to reference
.pipe(uglify()) // minify file
// .pipe(rename("main-min.js")) // rename file
.pipe(sourcemaps.write('./', { sourceRoot: './js' })) // sourcemap gets written and references wherever sourceRoot is specified to be
.pipe(gulp.dest('./public/js'));
});
gulp.task('static', () => {
return gulp.src([
paths.allSrcJs,
paths.gulpFile
])
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(flow({ abort: true }));
});
// gulp.task('static', () => {
// return gulp.src('./app/**/*.js')
// .pipe(excludeGitignore())
// .pipe(eslint())
// .pipe(eslint.format())
// .pipe(eslint.failAfterError());
// });
gulp.task('nsp', cb => {
nsp({package: path.resolve('package.json')}, cb);
});
// TESTING
gulp.task('pre-test', () => {
return gulp.src('app/**/*.js')
.pipe(excludeGitignore())
.pipe(istanbul({
includeUntested: true,
instrumenter: isparta.Instrumenter
}))
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['pre-test'], cb => {
let mochaErr;
gulp.src('test/**/*.test.js')
.pipe(plumber())
.pipe(mocha({reporter: 'spec'}))
.on('error', err => {
mochaErr = err;
})
.pipe(istanbul.writeReports())
.on('end', () => {
cb(mochaErr);
});
});
gulp.task('coveralls', ['test'], () => {
if (!process.env.CI) {
return;
}
return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
.pipe(coveralls());
});
gulp.task('develop', () => {
livereload.listen();
nodemon({
script: 'app.js',
ext: 'js coffee handlebars',
stdout: false
}).on('readable', function read() {
this.stdout.on('data', (chunk) => {
if (/^Express server listening on port/.test(chunk)) {
livereload.changed(__dirname);
}
});
this.stdout.pipe(process.stdout);
this.stderr.pipe(process.stderr);
});
});
// Gulp watch syntax
// gulp.watch('files-to-watch', ['tasks', 'to', 'run']);
gulp.task('watch', () => {
// gulp.watch(['./public/js/**/*.js', 'test/**'], ['test']);
gulp.watch(['./public/src/**/*.js'], ['js']);
gulp.watch('./public/css/*.scss', ['sass']);
});
gulp.task('prepublish', ['nsp']);
// gulp.task('default', ['static', 'test', 'coveralls']);
gulp.task('default', [
'static',
'sass',
'js',
// 'test',
// 'coveralls',
'develop',
'watch'
]);