forked from markbain/wp-project-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
384 lines (331 loc) · 11.3 KB
/
Gruntfile.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
'use strict';
module.exports = function(grunt) {
// auto-load all grunt tasks matching the `grunt-*` pattern in package.json
// no need for grunt.loadNpmTasks!
require('load-grunt-tasks')(grunt);
var mozjpeg = require('imagemin-mozjpeg');
grunt.initConfig({
/**
*
* Variables
*
*/
// Variables from package.json
pkg: grunt.file.readJSON( 'package.json' ),
// Global variables
vars: grunt.file.readJSON( 'gruntVars.json' ),
// README
rdm: 'README.md',
/**
*
* Grunt plugin configuration
*
*/
// autoprefixer
autoprefixer: {
options: {
browsers: ['last 2 versions', 'ie 9'],
map: true
},
target_file: {
src: '<%= vars.theme_path %>/<%= vars.theme_name %>/style.css',
},
},
// Increment the version number in package.json
bump: {
options: {
updateConfigs: ['pkg'], // make sure to check updated pkg variables
push: false,
commitFiles: ['-a'], // Commit all files
createTag: false, // Branch is tagged by git flow
commitMessage: 'Bump the version to %VERSION%',
prereleaseName: 'rc',
}
},
// Delete temporary files
clean: {
dir_release: ['release/**/*'], // Clean out the release dir
copy_theme: ['release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.theme_name %>.<%= pkg.version %>'],
copy_plugin: ['release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.plugin_name %>.<%= pkg.version %>']
},
// Create an archive
compress: {
plugin: {
options: {
mode: 'zip',
archive: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.plugin_name %>.<%= pkg.version %>.zip'
},
expand: true,
cwd: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.plugin_name %>.<%= pkg.version %>',
src: ['**/*']
},
theme: {
options: {
mode: 'zip',
archive: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.theme_name %>.<%= pkg.version %>.zip'
},
expand: true,
cwd: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.theme_name %>.<%= pkg.version %>',
src: ['**/*']
}
},
copy: {
theme: {
files: [
{
expand: true, // includes files within path and its sub-directories
cwd: '<%= vars.theme_path %>/<%= vars.theme_name %>/', // Target dir
src: [
'**',
'!style.css.map',
'!**/*.*.orig' // Don't copy .orig copies
],
dest: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.theme_name %>.<%= pkg.version %>'
},
],
},
plugin: {
files: [
// includes files within path and its sub-directories
{expand: true,
cwd: '<%= vars.plugin_path %>/<%= vars.plugin_name %>', // Target dir
src: [
'**',
'!**/*.*.orig' // Don't copy .orig copies
],
dest: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.plugin_name %>.<%= pkg.version %>'},
],
},
mu_plugins: {
files: [
// includes files within path and its sub-directories
{expand: true,
cwd: 'httpdocs/wp-content/mu-plugins/',
src: [
'**',
],
dest: 'release/<%= pkg.name %>.<%= pkg.version %>/<%= vars.mu_plugin_path %>'},
],
},
font_awesome: {
expand: true,
flatten: true,
src: ['bower_components/fontawesome/fonts/*'],
dest: '<%= vars.theme_path %>/<%= vars.theme_name %>/assets/fonts'
},
deploy_scripts: {
expand: true,
flatten: true,
src: ['node_modules/mbd-wp-deploy-scripts/scripts/*'],
dest: 'scripts'
}
},
// Optimize images
imagemin: {
dist: {
options: {
optimizationLevel: 7,
progressive: true,
interlaced: true,
use: [mozjpeg()],
},
files: [{
expand: true,
cwd: '<%= vars.theme_path %>/<%= vars.theme_name %>/assets/images/src',
src: ['**/*.{png,jpg,jpeg,gif}'],
dest: '<%= vars.theme_path %>/<%= vars.theme_name %>/assets/images/dist'
}]
}
},
// javascript linting with jshint
jshint: {
options: {
jshintrc: '.jshintrc',
"force": true
},
all: [
'Gruntfile.js',
'<%= vars.theme_path %>/<%= vars.theme_name %>/assets/js/src/custom/**/*.js',
'<%= vars.plugin_path %>/<%= vars.plugin_name %>/assets/js/src/custom/**/*.js',
]
},
// Modernizr
modernizr: {
dist: {
// [REQUIRED] Path to the build you're using for development.
"devFile" : "bower_components/modernizr/modernizr.js",
// Path to save out the built file.
"outputFile" : "<%= vars.theme_path %>/<%= vars.theme_name %>/assets/js/dist/custom/modernizr-custom.js",
}
},
// Sass
sass: {
dist: {
options: {
style: 'expanded',
sourceMap: true
},
files: {
'<%= vars.theme_path %>/<%= vars.theme_name %>/style.css': 'sass/styles.scss',
// '<%= vars.theme_path %>/<%= vars.theme_name %>/style-custom-login.css': 'sass/custom-login-styles.scss',
}
}
},
// Shell
shell: {
exp: {
command: [
'cd bin/scripts',
'./local-export.sh',
'cd ../..'
].join('&&')
},
imp: {
command: [
'cd bin/scripts',
'./local-import.sh',
'cd ../..'
].join('&&')
}
},
// Version
version: {
bower: {
options: {
prefix: '"version"\\:\\s"'
},
src: [ 'bower.json' ],
},
css: {
options: {
prefix: 'Version\\:\\s'
},
src: [
'sass/styles.scss',
// Edit the version directly in the generated CSS file.
// Avoids having to run the Sass task just for this.
'<%= vars.theme_path %>/<%= vars.theme_name %>/style.css',
],
},
theme: {
options: {
prefix: 'Version\\:\\s'
},
src: [
'<%= vars.theme_path %>/<%= vars.theme_name %>/theme-version.php',
],
},
readme: {
options: {
prefix: 'Version\ \s*'
},
src: [ '<%= rdm %>' ],
},
plugin: {
options: {
prefix: 'Version\\:\\s'
},
src: [ '<%= vars.plugin_path %>/<%= vars.plugin_name %>/<%= vars.plugin_name %>.php' ],
},
},
// watch for changes and trigger sass, jshint, uglify and livereload
watch: {
sass: {
files: ['sass/**/*.{scss,sass}'],
tasks: [
'sass',
'autoprefixer'
]
},
js: {
files: '<%= jshint.all %>',
tasks: ['jshint']
},
img: {
files: ['<%= vars.theme_path %>/<%= vars.theme_name %>/assets/images/src/*.{png,jpg,jpeg,gif,webp,svg}'],
tasks: [
'newer:imagemin:dist'
]
},
livereload: {
options: { livereload: true },
files: [
// Gruntfile
'Gruntfile.js',
// Theme files
'<%= vars.theme_path %>/<%= vars.theme_name %>/**/*.php',
'<%= vars.theme_path %>/<%= vars.theme_name %>/lib/**/*.php',
'<%= vars.theme_path %>/<%= vars.theme_name %>/style.css',
'<%= vars.theme_path %>/<%= vars.theme_name %>/assets/js/src/**/*.js',
'<%= vars.theme_path %>/<%= vars.theme_name %>/assets/images/dist/**/*.{png,jpg,jpeg,gif,webp,svg}',
// Plugin files
'<%= vars.plugin_path %>/<%= vars.plugin_name %>/**/*',
]
}
}
});
/**
*
* Register tasks
*
*/
grunt.registerTask('default', [
'sass',
'imagemin:dist',
'autoprefixer',
'modernizr',
// 'jshint',
'watch',
]);
grunt.registerTask( 'bump-minor', [
'bump-only:minor',
'version',
'bump-commit',
]);
grunt.registerTask( 'bump-patch', [
'bump-only:patch',
'version',
'bump-commit',
]);
// Build Task
grunt.registerTask('build', [
// Start with a clean release dir
// If required, legacy releases can be rebuild based on their git tag
// and running this task
'clean:dir_release',
// NOTE
// This task does not automatically bump the version
// Precede with grunt bump-{minor|patch} to change the version across the project
// Compile styles
// Do this because if you haven't run grunt after switching to this branch,
// the CSS won't have been updated!
'sass',
// Make a copy of files for upload to the server
/***
*
* We copy the dirs first so we can add the version to the zipped dir and
* remove some files we don't want.
*
*/
'copy:theme',
'copy:plugin',
// Create an archive from the copies
'compress',
// Delete the uncompressed copies
'clean:copy_plugin',
'clean:copy_theme',
]);
// Copy assets
grunt.registerTask('copyassets', [
'copy:font_awesome',
'copy:deploy_scripts'
]);
// Export entire WP site for deployment
grunt.registerTask('export', [
'shell:exp'
]);
// Import entire WP site for local development
grunt.registerTask('import', [
'shell:imp'
]);
};