-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
135 lines (112 loc) · 3.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
'use strict';
var gulp = require('gulp');
var runSequence = require('run-sequence').use(gulp);
var wrench = require('wrench');
var del = require('del');
var environments = require('gulp-environments');
var gutil = require('gulp-util');
var shell = require('gulp-shell');
var connect = require('gulp-connect');
var livereload = require('gulp-livereload');
var config = require('./gulp/config');
// build tasks
var build = function(callback) {
runSequence(
'clean:everything',
'markup',
'styles',
'scripts',
'assets',
'pagelist',
callback
);
};
var prodBuild = function(callback) {
runSequence(
'clean:everything',
'markup',
'styles',
'minify-css',
'scripts',
'assets',
'pagelist',
callback
);
};
/**
* This will load all js files in the gulp directory
* in order to load all gulp tasks
*/
wrench.readdirSyncRecursive('./gulp').filter(function(file) {
return (/\.(js)$/i).test(file);
}).map(function(file) {
require('./gulp/' + file);
});
gulp.task('clean:everything', function() {
return del('dist');
});
gulp.task('run_backstop_refs', shell.task([
'backstop reference'
]));
gulp.task('run_backstop_test', shell.task([
'backstop test'
]));
gulp.task('open_port', function() {
var open = require('open');
var serverPort = 4000;
var localhost = 'http://localhost:' + serverPort;
connect.server({
host: 'localhost',
port: serverPort,
livereload: false,
root: 'dist/'
});
});
gulp.task('backstop-ref', ['open_port', 'run_backstop_refs'], function (callback) {
connect.serverClose();
});
gulp.task('backstop-test', ['open_port', 'run_backstop_test'], function (callback) {
connect.serverClose();
});
// DEV build
gulp.task('build', function(callback) {
environments.current(environments.development);
build(callback);
});
// PROD build
gulp.task('production', function(callback) {
environments.current(environments.production);
prodBuild(callback);
});
// WATCH TASK
gulp.task('watch', ['build'], function() {
livereload.listen();
gulp.watch(config.paths.styles.src + '**/*.scss', ['styles', 'assets']);
gulp.watch(config.paths.styles.src + '**/**/*.scss', ['styles', 'assets']);
gulp.watch(config.paths.temp.src + '**/*', ['assets']);
gulp.watch(config.paths.images.src + '**/*', ['assets']);
gulp.watch(config.paths.scripts.src + '**/*.js', ['scripts']);
gulp.watch([
config.paths.views.src + '**/*',
config.paths.views.pages + '**/*',
config.paths.data.src + '**/*'
], ['build']);
});
// SERVE TASK
gulp.task('serve', ['watch'], function(callback) {
var open = require('open');
var serverPort = Math.floor((Math.random() * 1000) + 3000);
var localhost = 'http://localhost:' + serverPort;
connect.server({
host: 'localhost',
port: serverPort,
livereload: true,
root: config.basePaths.dist
});
open(localhost, 'google chrome');
});
/**
* Default task clean temporaries directories and launch the
* main optimization build task
*/
gulp.task('default', ['build']);