-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
executable file
·199 lines (167 loc) · 5.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
'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'); // takes variables passed from command line
var livereload = require('gulp-livereload');
var shell = require('gulp-shell');
var rename = require('gulp-rename');
var config = require('./_gulp/config');
var connect = require('gulp-connect');
var cachebust = require('gulp-cache-bust');
var makeListings = function(callback) {
runSequence(
'listings',
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');
});
// build listings
gulp.task('buildListings', function(callback) {
makeListings(callback);
});
// cachebust
gulp.task('cachebust', function() {
gulp.src('dist/**/*.html')
.pipe(cachebust({
type: 'timestamp'
}))
.pipe(gulp.dest('dist'));
});
// run commandline commands
gulp.task('commandline', shell.task([
'node build',
]));
gulp.task('run_backstop_refs', shell.task([
'backstop reference'
]));
gulp.task('run_backstop_test', shell.task([
'backstop test'
]));
// build tasks
gulp.task('build', ['buildListings'], function () {
runSequence(
'clean:everything',
'commandline',
'styles',
// 'scripts-dev',
'scripts-prod',
'assets',
'cachebust'
);
});
gulp.task('build_cached', ['buildListings'], function () {
runSequence(
'clean:everything',
'commandline',
'styles',
// 'scripts-dev',
'scripts-prod',
'assets'
);
});
gulp.task('production', ['buildListings'], function (callback) {
runSequence(
'clean:everything',
'commandline',
'styles',
'minify-css',
'scripts-prod',
'assets',
'cachebust',
callback
);
});
gulp.task('build_watch', ['buildListings'], function (callback) {
runSequence(
'clean:everything',
'commandline',
'styles',
'scripts-dev',
'assets',
'cachebust',
callback
);
livereload.listen();
gulp.watch([config.paths.styles.src + '**/*.scss', '!' + config.paths.styles.src + '**/styles.scss', '!' + config.paths.styles.src + '**/Editor.scss'], ['styles', 'assets','cachebust']);
gulp.watch(config.paths.temp.src + '**/*', ['assets','cachebust']);
gulp.watch(config.paths.images.src + '**/*', ['assets','cachebust']);
gulp.watch(config.paths.scripts.src + '**/*.js', ['scripts-dev','cachebust']);
gulp.watch('_pages/**/*', ['commandline']);
gulp.watch('_layouts/**/*', ['commandline']);
gulp.watch('_master-pages/**/*', ['commandline']);
gulp.watch('_data/**/*', ['commandline']);
gulp.watch('_components/**/*', ['commandline']);
});
// SERVE TASK
gulp.task('open_connection', 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');
});
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: config.basePaths.dist
});
});
// tasks to run from command line
// build and watch files then serve site in chrome
gulp.task('serve', ['build_watch'], function () {
runSequence(
'open_connection'
);
});
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();
});
// build and watch files
gulp.task('default', ['build_watch']);
// just build
gulp.task('dev', ['build']);
// just build but without cache bust
gulp.task('dev-cache', ['build_cached']);
// Backend tasks
// deploy just runs the production build (minification tasks included in this) and then copies over to location specified in commandline
gulp.task('deploy', ['production'], function() {
gulp.src(config.basePaths.dist + '**/*')
.pipe(gulp.dest(gutil.env.dest));
});
// build-sln will run the prod build and then copy files & folders over to the specified backend directory
// local backend build
gulp.task('build-sln', ['production'], function() {
gulp.src(config.paths.scripts.dist + '**/*')
.pipe(gulp.dest(config.paths.sln.web + '/_scripts/'));
gulp.src(config.paths.styles.dist + '**/*')
.pipe(gulp.dest(config.paths.sln.web + '/_styles/'));
gulp.src(config.paths.images.dist + '**/*')
.pipe(gulp.dest(config.paths.sln.web + '/_images/'));
});