forked from samikeijonen/checathlon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
266 lines (220 loc) · 5.9 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
/*
REQUIRED STUFF
==============
*/
var changed = require('gulp-changed');
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var notify = require('gulp-notify');
var prefix = require('gulp-autoprefixer');
var minifycss = require('gulp-clean-css');
var cssnano = require('gulp-cssnano');
var del = require('del');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var cache = require('gulp-cache');
var concat = require('gulp-concat');
var util = require('gulp-util');
var header = require('gulp-header');
var pixrem = require('gulp-pixrem');
var exec = require('child_process').exec;
var wpPot = require('gulp-wp-pot');
var sort = require('gulp-sort');
var zip = require('gulp-zip');
/*
FILE PATHS
==========
*/
var sassSrc = 'assets/sass/**/*.{sass,scss}';
var sassFile = 'assets/sass/style.scss';
var styleFile = 'style.css';
var cssDest = './'; // Create style.css file.
var customjs = 'assets/js/scripts.js';
var jsSrc = ['assets/js/*.js', '!assets/js/*.min.js', '!assets/js/customizer.js'];
var jsDest = 'assets/js';
var phpFiles = ['./*.php', './**/*.php', '!build/*.php'];
var project = 'checathlon'; // Project name.
var build = './build/checathlon/';
var buildInclude = [
'**',
'!node_modules',
'!node_modules/**/',
'!assets/sass/**/*',
'!build',
'!build/**/',
'!.git/**',
'!Gulpfile.js',
'!package.js',
'!package.json',
'!package-lock.json',
'!.gitignore',
'!.gitmodules',
'!.tx/**',
'!**/*~',
'!.DS_Store',
];
/*
ERROR HANDLING
==============
*/
var handleError = function(task) {
return function(err) {
notify.onError({
message: task + ' failed, check the logs..'
})(err);
util.log(util.colors.bgRed(task + ' error:'), util.colors.red(err));
};
};
/*
BROWSERSYNC
===========
Notes:
- Add only file types you are working on - if watching the whole themeDir,
task trigger will be out of sync because of the sourcemap-files etc.
- Adding only part of the files will also make the task faster
*/
gulp.task('browsersync', function() {
var files = [
'**/*.php',
'**/*.css',
jsSrc
];
browserSync.init(files, {
proxy: "localhost/foxland-themes/checathlon",
browser: "Google Chrome",
notify: true
});
});
/*
STYLES
======
*/
gulp.task('sass-styles', function() {
gulp.src(sassFile)
.pipe(sass({
compass: false,
bundleExec: true,
sourcemap: false,
outputStyle: 'expanded',
debugInfo: true,
lineNumbers: true,
errLogToConsole: true
}))
.on('error', handleError('styles'))
.pipe(prefix('last 3 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) // Adds browser prefixes (eg. -webkit, -moz, etc.)
.pipe(pixrem())
/*.pipe(minifycss({
advanced: true,
keepBreaks: false,
keepSpecialComments: 0,
mediaMerging: true,
sourceMap: true
}))*/
.pipe(gulp.dest(cssDest))
.pipe(browserSync.stream());
});
/**
* Prefix style.css rules.
*/
gulp.task('prefix:styles', function() {
gulp.src(styleFile)
.pipe(prefix('last 3 version')) // Adds browser prefixes (eg. -webkit, -moz, etc.)
.pipe(gulp.dest(cssDest))
.pipe(browserSync.stream());
});
/**
* Delete style.min.css before we minify and optimize
*/
gulp.task('clean:styles', function() {
return del(['style.min.css'])
});
/**
* Minify and optimize style.css.
*
* https://www.npmjs.com/package/gulp-cssnano
*/
gulp.task('cssnano', ['clean:styles'], function() {
return gulp.src('style.css')
.pipe(cssnano({
safe: true // Use safe optimizations
}))
.pipe(rename('style.min.css'))
.pipe(gulp.dest('./'))
.pipe(browserSync.stream());
});
/*
SCRIPTS
=======
*/
var currentDate = util.date(new Date(), 'dd-mm-yyyy HH:ss');
var pkg = require('./package.json');
var banner = '/*! <%= pkg.name %> <%= currentDate %> - <%= pkg.author %> */\n';
gulp.task('uglify', function() {
return gulp.src(jsSrc)
.pipe(rename({suffix: '.min'}))
.pipe(uglify({
mangle: false
}))
.pipe(gulp.dest(jsDest));
});
/**
* Scan the theme and create a POT file.
*
* https://www.npmjs.com/package/gulp-wp-pot
*/
gulp.task('wp-pot', function() {
return gulp.src(phpFiles)
//.pipe(plumber({ errorHandler: handleErrors }))
.pipe(sort())
.pipe(wpPot({
domain: 'checathlon',
destFile:'checathlon.pot',
package: 'checathlon',
bugReport: 'https://foxland.fi/contact/',
lastTranslator: 'Sami Keijonen <[email protected]>',
team: 'Sami Keijonen <[email protected]>'
}))
.pipe(gulp.dest('languages/'));
});
/**
* Delete build folder before we proceed.
*/
gulp.task('clean:build', function() {
return del(['build/checathlon/**/*'])
});
/**
* Build task that moves essential theme files for production-ready sites
*
* buildFiles copies all the files in buildInclude to build folder - check variable values at the top
*/
gulp.task('build-folder', ['clean:build'], function() {
return gulp.src(buildInclude)
.pipe(gulp.dest(build))
.pipe(notify({ message: 'Copy from buildFiles complete', onLast: true }));
});
/**
* Delete unneccessary folders from build.
*/
gulp.task('clean:unneccessary', function() {
return del(['./build/checathlon/node_modules/**/*', './build/checathlon/build/**/*'])
});
/*
WATCH
=====
*/
// Run the JS task followed by a reload
gulp.task('js-watch', ['js'], browserSync.reload);
gulp.task('watch', ['browsersync'], function() {
gulp.watch(sassSrc, ['styles']);
gulp.watch(jsSrc, ['js-watch']);
});
/**
* Create indivdual tasks.
*/
gulp.task('i18n', ['wp-pot']);
gulp.task('scripts', ['uglify']);
gulp.task('styles', ['prefix:styles', 'cssnano']);
gulp.task('build', ['build-folder', 'clean:unneccessary']);
gulp.task('default', ['i18n', 'styles', 'scripts', 'build']);