This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·277 lines (255 loc) · 5.47 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
const webpackConfig = require('./webpack.config');
const postCssPresetEnvOptions = {
stage: 4,
features: {
'custom-media-queries': {
preserve: false,
importFrom: './build/css/vars/_media-queries.css',
},
'custom-properties': {
preserve: true,
importFrom: './build/css/vars.css',
},
'nesting-rules': true,
},
};
module.exports = function (grunt) {
// measures the time each task takes
require('time-grunt')(grunt);
// Get the needed modules just in time
require('jit-grunt')(grunt, {
// Define private modules
postcss: '@lodder/grunt-postcss',
});
// Define the initial config for grunt
grunt.initConfig({
// Define variables
pkg: grunt.file.readJSON('package.json'),
// OPTIMIZE CSS - Take the created CSS files and run some plugins on it
postcss: {
default: {
options: {
map: false,
processors: [
require('postcss-import')(),
require('postcss-preset-env')(postCssPresetEnvOptions),
],
},
files: [
{
expand: true,
cwd: 'build/css',
src: '*.css',
dest: 'trunk/css/',
},
{
expand: true,
cwd: 'build/blocks',
src: 'blocks.css',
dest: 'trunk/css/',
},
{
expand: true,
cwd: 'build/blocks',
src: 'blocks-editor.css',
dest: 'trunk/css/',
},
],
},
minify: {
options: {
map: false,
processors: [require('cssnano')()],
},
files: [
{
expand: true,
cwd: 'trunk/css',
src: ['*.css', '!*.min.css'],
dest: 'trunk/css',
ext: '.min.css',
},
],
},
},
// LINT CSS - Lint the css we wrote
stylelint: {
all: ['build/**/*.css', '!build/vendor/**/*.css'],
},
// PROCESS JS - Use webpack to process the needed js files
webpack: {
prod: webpackConfig,
},
// // SHELL - Run needed shell commands
shell: {
lintPHP: 'composer run lint',
},
// // ESLINT - Make sure our JS follows coding standards
eslint: {
target: ['build/**/*.js', '!build/vendor/**/*.js'],
},
// COPY FILES - Copy needed files from build to trunk
copy: {
options: {
process(content) {
if (typeof content !== 'string') {
return content;
}
return grunt.template.process(content);
},
},
build: {
expand: true,
cwd: 'build',
src: [
'style.css',
'**/*.txt',
'**/*.svg',
'**/*.po',
'**/*.pot',
'**/*.tmpl.html',
'**/*.php',
'**/*.json',
],
dest: 'trunk/',
filter: 'isFile',
},
build_css: {
expand: true,
cwd: 'dist/css',
src: ['*.min.css'],
dest: 'trunk/css/',
filter: 'isFile',
},
build_stream: {
expand: true,
options: { encoding: null },
cwd: 'build',
src: ['**/*.mo', 'img/**/*', 'screenshot.png', 'fonts/**/*'],
dest: 'trunk/',
filter: 'isFile',
},
update_acf_json: {
expand: true,
cwd: 'trunk',
src: ['acf-json/*.json'],
dest: 'build/',
},
},
// CLEAN FOLDERS - Before we compile freshly, we want to delete old folder contents
clean: {
options: { force: true },
dist_css: {
expand: true,
force: true,
cwd: 'dist/css/',
src: ['**/*'],
},
trunk: {
expand: true,
force: true,
cwd: 'trunk/',
src: ['**/*'],
},
zip: {
expand: true,
force: true,
cwd: '<%= pkg.slug %>/',
src: ['**/*'],
},
acf: {
expand: true,
force: true,
cwd: 'build/acf-json',
src: ['*.json'],
},
},
// COMPRESS - Create a zip file from a new trunk
compress: {
main: {
options: {
archive: 'update/<%= pkg.slug %>.zip',
},
files: [
{
src: ['**'],
cwd: 'trunk',
expand: true,
dest: '<%= pkg.slug %>',
},
],
},
},
// WATCHER - Watch for changes in files and process those when a change is detected
watch: {
options: {
event: ['changed', 'added', 'deleted'],
},
js: {
files: [
'build/**/*.js',
'!build/**/*.min.js',
'!build/**/*.bundle.js',
],
tasks: ['handle_js'],
options: { livereload: true },
},
css: {
files: ['build/**/*.css'], // which files to watch
tasks: ['newer_handle_css'],
options: { livereload: true },
},
php: {
files: ['build/**/*.php'], // which files to watch
tasks: ['newer_handle_static'],
options: { livereload: true },
},
static: {
files: ['build/**/*.html', 'build/**/*.txt', 'build/**/*.json'], // Watch all files
tasks: ['newer_handle_static'],
options: { livereload: true },
},
acf: {
files: ['trunk/acf-json/*.json'],
tasks: ['clean:acf', 'copy:update_acf_json'],
},
},
});
// Handle certain file groups
grunt.registerTask('newer_handle_css', [
'postcss:default',
'postcss:minify',
]);
grunt.registerTask('handle_css', [
'clean:dist_css',
'postcss:default',
'postcss:minify',
]);
grunt.registerTask('handle_js', ['webpack']);
grunt.registerTask('newer_handle_static', [
'newer:copy:build',
'newer:copy:build_css',
'newer:copy:build_stream',
]);
grunt.registerTask('handle_static', [
'copy:build',
'copy:build_css',
'copy:build_stream',
]);
// Deployment strategies
grunt.registerTask('dev_deploy', [
'newer_handle_css',
'handle_js',
'newer_handle_static',
]);
grunt.registerTask('deploy', [
'clean:trunk',
'handle_css',
'handle_js',
'handle_static',
]);
// Linting
grunt.registerTask('lint', ['shell:lintPHP', 'eslint', 'stylelint']);
// Releasing
grunt.registerTask('release', ['lint', 'deploy', 'compress']);
};