forked from bougiebatz/bougiebatz
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gulpfile.js
148 lines (126 loc) · 4.11 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var gulp = require('gulp');
var sass = require('gulp-sass');
var clean = require('gulp-clean');
var nodemon = require('gulp-nodemon');
var babel = require('gulp-babel');
var browserSync = require('browser-sync').create();
var KarmaServer = require('karma').Server;
var gutil = require('gulp-util');
// The paths to our app files
var paths = {
src: {
scripts: ['client/app/**/*.js'],
html: ['client/app/**/*.html', 'client/index.html'],
styles: ['client/styles/style.scss']
},
compiled: {
scripts: ['compiled/app/**/*.js'],
html: ['compiled/app/**/*.html', 'compiled/index.html'],
styles: ['compiled/styles/style.css']
},
server: 'server/server.js'
};
// gulp.task('default', function() {
// return gutil.log('Gulp is running!')
// });
/***************************************
* ES5
***************************************/
// Start our node server using nodemon
gulp.task('serve', function () {
nodemon({
script: paths.server,
ignore: 'node_modules/**/*.js'
});
});
// Any changes made to your client side code will
// automagically refresh your page with the new changes
gulp.task('start', ['serve'], function () {
browserSync.init({
notify: true,
injectChanges: true,
files: paths.src.scripts.concat(paths.src.html, paths.src.style),
proxy: 'localhost:9000'
});
});
gulp.task('karma', function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js'
}, done).start();
});
/***************************************
* Gulp-Sass
***************************************/
gulp.task('styles', function () {
gulp.src('./client/sass/**/*.scss')
.pipe(sass().on('error', sass.logError)) /**if there is an error parsing your sass by default it will just kill the gulp process, but with this option it will tell us where the error is**/
.pipe(gulp.dest('./client/css/'));
});
//Watch task, it will sit and wait for files to be saved and then run our task
gulp.task('watch', function () {
gulp.watch('./client/sass/**/*.scss', ['styles']);
});
/***************************************
* Task Default Start
***************************************/
// Use ES5 by default
gulp.task('default', ['start', 'styles', 'watch']);
/***************************************
* ES6
***************************************/
// Remove previously transpiled code
gulp.task('clean', function () {
return gulp.src(paths.compiled.scripts)
.pipe(clean({read: false}));
});
// Transpile our client scripts
gulp.task('babel', ['clean'], function () {
return gulp.src('client/**/*')
.pipe(babel({
presets: ['es2015'],
only: paths.src.scripts
}))
.pipe(gulp.dest('compiled'));
});
// Start a babel-node server using nodemon
gulp.task('serve:es6', ['babel'], function () {
nodemon({
exec: 'babel-node --presets es2015',
script: paths.server,
ignore: 'node_modules/**/*.js'
});
});
// Any changes made to your client side code will still
// automagically refresh your page with the new changes,
// after transpiling again with babel
gulp.task('start:es6', ['serve:es6'], function () {
browserSync.init({
notify: true,
injectChanges: true,
files: paths.compiled.scripts.concat(paths.compiled.html, paths.compiled.style),
proxy: 'localhost:9000'
});
gulp.watch(paths.scripts, ['babel']);
});
// Tests can be written in ES6 too!
gulp.task('karma:es6', function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
preprocessors: {
[paths.src.scripts]: ['babel'],
[paths.test]: ['babel']
},
babelPreprocessor: {
options: {
presets: ['es2015'],
sourceMap: 'inline'
},
filename: function (file) {
return file.originalPath;
},
sourceFileName: function (file) {
return file.originalPath;
}
}
}, done).start();
});