-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGulpfile.js
139 lines (119 loc) · 4.16 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
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugin = gulpLoadPlugins();
var browserify = require('browserify');
var vss = require('vinyl-source-stream');
var stylish = require('jshint-stylish');
var gulpHelpers = require('./build-utils/gulpHelpers.js');
var watchFiles = [
'./src/client/**/*',
'!./src/client/assets/css/duel.css',
'!./src/client/assets/js/allScripts.js',
];
var lintFiles = [
'./src/client/**/*.js',
'./src/server/**/*.js',
'!./src/client/assets/js/allScripts.js'
];
var sassFiles = [
'./src/client/assets/sass/**/*.scss'
];
var browserifyFiles = [
'./src/client/app/app.js'
];
//TODO add concat and minify for css / js
//TODO preventy copying files which will be concat/minified during build
var copyFiles = [
'./src/**/*',
'!./src/client/app'
// '!./src/client/assets/css/',
// '!./src/client/assets/lib/',
];
/******************************/
/* DEV TASKS */
/******************************/
//lint
gulp.task('lint', function() {
return gulp.src(lintFiles)
.pipe(plugin.jshint())
.pipe(plugin.jshint.reporter(stylish)).on('error', gulpHelpers.printContinueError);
});
//sass
gulp.task('sass', function () {
return gulp.src(sassFiles)
.pipe(plugin.sass().on('error', plugin.sass.logError))
.pipe(gulp.dest('./src/client/assets/css')).on('error', gulpHelpers.printContinueError);
});
//browserify using vinyl source streams (gulp-browserify no longer maintained)
gulp.task('browserify', function() {
//file to browserify
return browserify({
entries: browserifyFiles,
debug: true
})
.bundle().on('error', gulpHelpers.printContinueError)
//output name
.pipe(vss('allScripts.js')).on('error', gulpHelpers.printContinueError)
//output location
.pipe(gulp.dest('./src/client/assets/js/')).on('error', gulpHelpers.printContinueError);
});
//start dev version using nodemon
gulp.task('nodemon', function(){
return plugin.nodemon(
{script: 'src/server/server.js', watch: ['src/server/**/*','src/server/server.js']}
).on('error', gulpHelpers.printBreakRestartError);
});
//starts build server
gulp.task('start', plugin.shell.task([
'echo Starting the server!',
'node build/server/server.js'
])
);
//watch
gulp.task('watch', function(){
return gulp.watch(watchFiles, ['devBuild']).on('error', gulpHelpers.printBreakRestartError);
});
//dev build
gulp.task('devBuild', ['lint','sass','browserify'], gulpHelpers.printDevComplete);
//dev to launch nodemon and keep an eye on files automatically
gulp.task('dev', ['devBuild','watch','nodemon']);
/******************************/
/* BUILD TASKS */
/* tasks run in series */
/******************************/
//installs bower files
gulp.task('bowerBuild', function() {
return plugin.bower().on('error', gulpHelpers.printBreakError);
});
//lint build - breaks build on error
gulp.task('lintBuild', ['bowerBuild'], function() {
return gulp.src(lintFiles)
.pipe(plugin.jshint())
.pipe(plugin.jshint.reporter(stylish))
.pipe(plugin.jshint.reporter('fail')).on('error', gulpHelpers.printContinueError);
});
//sass build - breaks build on error
gulp.task('sassBuild', ['lintBuild'], function () {
return gulp.src(sassFiles)
.pipe(plugin.sass().on('error', gulpHelpers.printBreakError))
.pipe(gulp.dest('./src/client/assets/css')).on('error', gulpHelpers.printBreakError);
});
//browserify build - breaks build on error
gulp.task('browserifyBuild', ['sassBuild'], function() {
//file to browserify
return browserify(browserifyFiles)
.bundle().on('error', gulpHelpers.printBreakError)
//output name
.pipe(vss('allScripts.js')).on('error', gulpHelpers.printBreakError)
//output location
.pipe(gulp.dest('./src/client/assets/js/')).on('error', gulpHelpers.printBreakError);
});
//build wont copy if any tasks in array throw errors
//need a way to ensure copying doesn't have any errors
gulp.task('build', ['bowerBuild','lintBuild','sassBuild','browserifyBuild'], function(){
gulp.src(copyFiles).pipe(gulp.dest('./build'))
.on('error', gulpHelpers.printBreakError)
.on('end', gulpHelpers.printBuildComplete);
});
//default to dev task
gulp.task('default', ['dev']);