This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
269 lines (237 loc) · 7.69 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*jslint node: true */
"use strict";
var $ = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var merge = require('merge-stream');
var sequence = require('run-sequence');
var colors = require('colors');
var dateFormat = require('dateformat');
var del = require('del');
var cleanCSS = require('gulp-clean-css');
// Enter URL of your local server here
// Example: 'http://localwebsite.dev'
var URL = '';
// Check for --production flag
var isProduction = !!(argv.production);
// Browsers to target when prefixing CSS.
var COMPATIBILITY = [
'last 2 versions',
'ie >= 9',
'Android >= 2.3'
];
// File paths to various assets are defined here.
var PATHS = {
sass: [
'assets/components/foundation-sites/scss',
'assets/components/motion-ui/src',
'assets/components/fontawesome/scss',
],
javascript: [
'assets/components/what-input/what-input.js',
'assets/components/foundation-sites/js/foundation.core.js',
'assets/components/foundation-sites/js/foundation.util.*.js',
// Paths to individual JS components defined below
'assets/components/foundation-sites/js/foundation.abide.js',
'assets/components/foundation-sites/js/foundation.accordion.js',
'assets/components/foundation-sites/js/foundation.accordionMenu.js',
'assets/components/foundation-sites/js/foundation.drilldown.js',
'assets/components/foundation-sites/js/foundation.dropdown.js',
'assets/components/foundation-sites/js/foundation.dropdownMenu.js',
'assets/components/foundation-sites/js/foundation.equalizer.js',
'assets/components/foundation-sites/js/foundation.interchange.js',
'assets/components/foundation-sites/js/foundation.magellan.js',
'assets/components/foundation-sites/js/foundation.offcanvas.js',
'assets/components/foundation-sites/js/foundation.orbit.js',
'assets/components/foundation-sites/js/foundation.responsiveMenu.js',
'assets/components/foundation-sites/js/foundation.responsiveToggle.js',
'assets/components/foundation-sites/js/foundation.reveal.js',
'assets/components/foundation-sites/js/foundation.slider.js',
'assets/components/foundation-sites/js/foundation.sticky.js',
'assets/components/foundation-sites/js/foundation.tabs.js',
'assets/components/foundation-sites/js/foundation.toggler.js',
'assets/components/foundation-sites/js/foundation.tooltip.js',
// Motion UI
'assets/components/motion-ui/motion-ui.js',
// Include your own custom scripts (located in the custom folder)
'assets/javascript/custom/*.js',
],
phpcs: [
'**/*.php',
'!wpcs',
'!wpcs/**',
],
pkg: [
'**/*',
'!**/node_modules/**',
'!**/components/**',
'!**/scss/**',
'!**/bower.json',
'!**/gulpfile.js',
'!**/package.json',
'!**/composer.json',
'!**/composer.lock',
'!**/codesniffer.ruleset.xml',
'!**/packaged/*',
]
};
// Browsersync task
gulp.task('browser-sync', ['build'], function() {
var files = [
'**/*.php',
'assets/images/**/*.{png,jpg,gif}',
];
browserSync.init(files, {
// Proxy address
proxy: URL,
// Port #
// port: PORT
});
});
// Compile Sass into CSS
// In production, the CSS is compressed
gulp.task('sass', function() {
return gulp.src('assets/scss/foundation.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
}))
.on('error', $.notify.onError({
message: "<%= error.message %>",
title: "Sass Error"
}))
.pipe($.autoprefixer({
browsers: COMPATIBILITY
}))
// Minify CSS if run with --production flag
.pipe($.if(isProduction, cleanCSS()))
.pipe($.if(!isProduction, $.sourcemaps.write('.')))
.pipe(gulp.dest('assets/stylesheets'))
.pipe(browserSync.stream({match: '**/*.css'}));
});
// Lint all JS files in custom directory
gulp.task('lint', function() {
return gulp.src('assets/javascript/custom/*.js')
.pipe($.jshint())
.pipe($.notify(function (file) {
if (file.jshint.success) {
return false;
}
var errors = file.jshint.results.map(function (data) {
if (data.error) {
return "(" + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
}
}).join("\n");
return file.relative + " (" + file.jshint.results.length + " errors)\n" + errors;
}));
});
// Combine JavaScript into one file
// In production, the file is minified
gulp.task('javascript', function() {
var uglify = $.uglify()
.on('error', $.notify.onError({
message: "<%= error.message %>",
title: "Uglify JS Error"
}));
return gulp.src(PATHS.javascript)
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.concat('foundation.js', {
newLine:'\n;'
}))
.pipe($.if(isProduction, uglify))
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest('assets/javascript'))
.pipe(browserSync.stream());
});
// Copy task
gulp.task('copy', function() {
// Motion UI
var motionUi = gulp.src('assets/components/motion-ui/**/*.*')
.pipe($.flatten())
.pipe(gulp.dest('assets/javascript/vendor/motion-ui'));
// What Input
var whatInput = gulp.src('assets/components/what-input/**/*.*')
.pipe($.flatten())
.pipe(gulp.dest('assets/javascript/vendor/what-input'));
// Font Awesome
var fontAwesome = gulp.src('assets/components/fontawesome/fonts/**/*.*')
.pipe(gulp.dest('assets/fonts'));
return merge(motionUi, whatInput, fontAwesome);
});
// Package task
gulp.task('package', ['build'], function() {
var fs = require('fs');
var time = dateFormat(new Date(), "yyyy-mm-dd_HH-MM");
var pkg = JSON.parse(fs.readFileSync('./package.json'));
var title = pkg.name + '_' + time + '.zip';
return gulp.src(PATHS.pkg)
.pipe($.zip(title))
.pipe(gulp.dest('packaged'));
});
// Build task
// Runs copy then runs sass & javascript in parallel
gulp.task('build', ['clean'], function(done) {
sequence('copy',
['sass', 'javascript', 'lint'],
done);
});
// PHP Code Sniffer task
gulp.task('phpcs', function() {
return gulp.src(PATHS.phpcs)
.pipe($.phpcs({
bin: 'wpcs/vendor/bin/phpcs',
standard: './codesniffer.ruleset.xml',
showSniffCode: true,
}))
.pipe($.phpcs.reporter('log'));
});
// PHP Code Beautifier task
gulp.task('phpcbf', function () {
return gulp.src(PATHS.phpcs)
.pipe($.phpcbf({
bin: 'wpcs/vendor/bin/phpcbf',
standard: './codesniffer.ruleset.xml',
warningSeverity: 0
}))
.on('error', $.util.log)
.pipe(gulp.dest('.'));
});
// Clean task
gulp.task('clean', function(done) {
sequence(['clean:javascript', 'clean:css'],
done);
});
// Clean JS
gulp.task('clean:javascript', function() {
return del([
'assets/javascript/foundation.js'
]);
});
// Clean CSS
gulp.task('clean:css', function() {
return del([
'assets/stylesheets/foundation.css',
'assets/stylesheets/foundation.css.map'
]);
});
// Default gulp task
// Run build task and watch for file changes
gulp.task('default', ['build', 'browser-sync'], function() {
// Log file changes to console
function logFileChange(event) {
var fileName = require('path').relative(__dirname, event.path);
console.log('[' + 'WATCH'.green + '] ' + fileName.magenta + ' was ' + event.type + ', running tasks...');
}
// Sass Watch
gulp.watch(['assets/scss/**/*.scss'], ['clean:css', 'sass'])
.on('change', function(event) {
logFileChange(event);
});
// JS Watch
gulp.watch(['assets/javascript/custom/**/*.js'], ['clean:javascript', 'javascript', 'lint'])
.on('change', function(event) {
logFileChange(event);
});
});