forked from drawbackwards/Forward-Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
236 lines (190 loc) · 7.26 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
// ===========================================================================
// Setup
// ===========================================================================
// Project Variables
// ---------------------------------------------------------------------------
var project = 'forward';
var build = 'build/';
var dist = 'dist/'+project+'/';
var source = 'src/';
var lang = 'languages/';
var bower = 'bower_components/';
var url = 'forward.local';
// Plugins
// ---------------------------------------------------------------------------
var gulp = require('gulp');
var del = require('del');
var plugins = require('gulp-load-plugins')({ camelize: true }); // This loads all modules prefixed with "gulp-" to plugins.moduleName
var browserSync = require('browser-sync').create();
// PostCSS Processors
// ---------------------------------------------------------------------------
var postcss = require('gulp-postcss');
var perfectionist = require('perfectionist');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var combinemq = require("css-mqpacker");
// ===========================================================================
// Styles
// ===========================================================================
// Main Styles
// ---------------------------------------------------------------------------
gulp.task('styles', function() {
gulp.src(source + 'scss/style.scss')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass({
sourcemap: true,
includePaths: [bower]
}).on('error', plugins.sass.logError))
.pipe(postcss([autoprefixer, combinemq({
sort: true
}), cssnano, perfectionist({
format: 'compact'
})]))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest(build))
.pipe(browserSync.stream({match: '**/*.css'}));
});
// ===========================================================================
// Scripts
// ===========================================================================
// Scripts; broken out into different tasks to create specific bundles which are then compressed in place
//
gulp.task('scripts', ['scripts-lint', 'scripts-core', 'scripts-extras'], function(){
return gulp.src([build+'js/**/*.js', '!'+build+'js/**/*.min.js']) // Avoid recursive min.min.min.js
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.uglify())
.pipe(gulp.dest(build+'js/'));
});
// Lint scripts for errors and sub-optimal formatting
//
gulp.task('scripts-lint', function() {
return gulp.src(source+'js/**/*.js')
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter('default'));
});
// These are the core custom scripts loaded on every page; pass an array to bundle several scripts in order
//
gulp.task('scripts-core', function() {
return gulp.src([
source+'js/core.js'
//, source+'js/navigation.js' // An example of how to add files to a bundle
])
.pipe(plugins.concat('core.js'))
.pipe(gulp.dest(build+'js/'));
});
// An example task for extra scripts that aren't loaded on every page
//
gulp.task('scripts-extras', function() {
return gulp.src([
// You can also add dependencies from Bower components e.g.: bower+'dependency/dependency.js',
source+'js/extras.js'
])
.pipe(plugins.concat('extras.js'))
.pipe(gulp.dest(build+'js/'));
});
// ===========================================================================
// Images
// ===========================================================================
// Copy images; minification occurs during packaging
//
gulp.task('images', function() {
return gulp.src(source+'**/*(*.png|*.jpg|*.jpeg|*.gif)')
.pipe(gulp.dest(build));
});
// ===========================================================================
// Languages
// ===========================================================================
// Copy everything under `src/languages` indiscriminately
//
gulp.task('languages', function() {
return gulp.src(source+lang+'**/*')
.pipe(gulp.dest(build+lang));
});
// ===========================================================================
// PHP
// ===========================================================================
// Copy PHP source files to the build directory
//
gulp.task('php', function() {
return gulp.src(source+'**/*.php')
.pipe(gulp.dest(build));
});
// ===========================================================================
// Distribution
// ===========================================================================
// Prepare a distribution, the properly minified, uglified, and sanitized version of the theme ready for installation
//
// Clean out junk files after build
//
gulp.task('clean', ['build'], function(cb) {
del([build+'**/.DS_Store'], cb)
});
// Totally wipe the contents of the distribution folder after doing a clean build
//
gulp.task('dist-wipe', ['clean'], function(cb) {
del([dist], cb)
});
// Copy everything in the build folder (except previously minified stylesheets) to the `dist/project` folder
//
gulp.task('dist-copy', ['dist-wipe'], function() {
return gulp.src([build+'**/*', '!'+build+'**/*.min.css'])
.pipe(gulp.dest(dist));
});
// Minify stylesheets in place
//
gulp.task('dist-styles', ['dist-copy'], function() {
return gulp.src([dist+'**/*.css', '!'+dist+'**/*.min.css'])
.pipe(postcss([cssnano]))
.pipe(gulp.dest(dist));
});
// Optimize images in place
//
// Use the line below if you wish to compress the styles to a single line.
// gulp.task('dist-images', ['dist-styles'], function() {
gulp.task('dist-images', ['dist-copy'], function() {
return gulp.src([dist+'**/*.png', dist+'**/*.jpg', dist+'**/*.jpeg', dist+'**/*.gif', '!'+dist+'screenshot.png'])
.pipe(plugins.imagemin({
optimizationLevel: 7
, progressive: true
, interlaced: true
}))
.pipe(gulp.dest(dist));
});
// ===========================================================================
// Bower
// ===========================================================================
// Executed on `bower update` which is in turn triggered by `npm update`; use this to manually copy front-end dependencies into your working source folder
//
gulp.task('bower', ['bower-normalize']);
// Used to get around Sass's inability to properly @import vanilla CSS
//
gulp.task('bower-normalize', function() {
return gulp.src(bower+'normalize.css/normalize.css')
.pipe(plugins.rename('_normalize.scss'))
.pipe(gulp.dest(source+'scss/base'));
});
// ===========================================================================
// Tasks
// ===========================================================================
// Build styles and scripts; copy PHP files
//
gulp.task('build', ['styles', 'scripts', 'images', 'languages', 'php']);
// Release creates a clean distribution package under `dist` after running build, clean, and wipe in sequence
//
gulp.task('dist', ['dist-images']);
// Watch Task
//
gulp.task('watch', ['styles'], function(gulpCallback) {
browserSync.init({
proxy: url
}, function callback() {
gulp.watch(source+'scss/**/*.scss', ['styles']);
gulp.watch([source+'js/**/*.js', bower+'**/*.js'], ['scripts']);
gulp.watch(source+'**/*(*.png|*.jpg|*.jpeg|*.gif)', ['images']);
gulp.watch(source+'**/*.php', ['php']);
gulpCallback();
});
});
// Default Task (Watch)
//
gulp.task('default', ['watch']);