forked from pattern-lab/patternlab-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
339 lines (306 loc) · 7.63 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
module.exports = function(grunt) {
var os=require('os');
var ifaces=os.networkInterfaces();
var lookupIpAddress = null;
for (var dev in ifaces) {
if(dev !== "en1" && dev !== "en0") {
continue;
}
ifaces[dev].forEach(function(details){
if (details.family==='IPv4') {
lookupIpAddress = details.address;
}
});
}
//If an IP Address is passed
//we're going to use the ip/host from the param
//passed over the command line
//over the ip addressed that was looked up
var ipAddress = grunt.option('host') || lookupIpAddress;
// Project configuration.
grunt.initConfig({
// Task configuration.
shell: {
patternlab: { // Core Patternlab build script
command: "php core/builder.php -gp"
},
wraith: { // Visual Regression Testing
command: [
"cd tests/wraith",
"wraith capture config",
"../../"
].join('&&')
}
},
/*
CSS
*/
less: {
build: {
options: {
sourceMap: true
},
files: {
"public/css/style.css": "source/less/style.less"
}
}
},
sass: {
dist: {
options: { // Target options
sourcemap: true
},
files: {
'public/css/style.css': 'source/css/style.scss'
}
}
},
cssmin: {
minify: {
expand: true,
cwd: 'public/css/',
src: ['style.css'],
dest: 'public/css/',
ext: '.min.css'
}
},
uncss : { // Removes unused css
dist : {
options : {
stylesheets : ['/css/style.css'],
htmlroot : 'public'
},
files : {
'public/css/style.css' : ['public/patterns/**/*.html']
}
}
},
/*
Images
*/
svgmin: { // Task
options: { // Configuration that will be passed directly to SVGO
plugins: [{
removeViewBox: false
}, {
removeUselessStrokeAndFill: false
}, {
convertPathData: {
straightCurves: false // advanced SVGO plugin option
}
}]
},
dist: { // Target
files: [{ // Dictionary of files
expand: true, // Enable dynamic expansion.
cwd: 'source/images/', // Src matches are relative to this path.
src: ['**/*.svg'], // Actual pattern(s) to match.
dest: 'public/images/', // Destination path prefix.
ext: '.svg' // Dest filepaths will have this extension.
// ie: optimise img/src/branding/logo.svg and store it in img/branding/logo.min.svg
}]
}
},
"svg-sprites": {
"svg-sprite": {
options: {
spriteElementPath: "public/images/",
spritePath: "public/images/",
cssPath: "public/css/",
cssSuffix: "scss",
cssPrefix: "_",
sizes: {
std: 18
},
refSize: 17,
unit: 20
}
}
},
imagemin: { // Task
dynamic: {
files: [{
expand: true, // Enable dynamic expansion
cwd: 'source/images', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: 'public/images' // Destination path prefix
}]
}
},
responsive_images: {
myTask: {
options: {
files: [{
expand: true,
src: ['source/images/**/*.{jpg,gif,png}'],
dest: 'source/images/responsive'
}]
}
}
},
/*
Performance & Testing
*/
'html-inspector': {
all: {
src: ['public/patterns/**/*.html', '!public/patterns/**/*escaped.html']
}
},
csscss: {
dist: {
src: ['source/css/style.scss']
}
},
cssmetrics: {
dev: {
src: [
'public/css/style.css'
]
},
prod: {
src: [
'public/css/style.min.css'
]
}
},
/*
Server Related
*/
watch: {
html: {
files: [
'source/_patterns/**/*.mustache',
'source/_patterns/**/*.json',
'source/_data/*.json',
],
tasks: [ 'shell:patternlab' ],
options: {
spawn: false,
livereload: true
}
},
styles: {
files: [ 'source/css/**/*.scss' ],
tasks: [ 'sass' ],
options: {
spawn: false
}
},
svgs: {
files: [ 'source/images/**/*.svg' ],
tasks: [ 'shell:patternlab', 'svgmin', "svg-sprites" ],
options: {
spawn: false,
livereload: true
}
},
imgs: {
files: [ 'source/images/**/*.{png,jpg,gif}' ],
tasks: [ 'responsive_images', 'imagemin' ],
options: {
spawn: false,
livereload: true
}
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'public/*.html',
'{.tmp,public}/css/{,*/}*.css',
'{.tmp,public}/js/{,*/}*.js',
'public/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outsideres
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'public'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'public'
]
}
},
dist: {
options: {
base: 'source'
}
}
},
browserSync: {
bsFiles: {
src: 'public/css/style.css'
},
options: {
host: ipAddress,
watchTask: true
}
},
/*
Misc
*/
replace: {
ip: {
src: ['public/**/*.html'], // source files array (supports minimatch)
overwrite:true, // destination directory or file
replacements: [{
from: '0.0.0.0', // string replacement
to: ipAddress
}]
}
},
concurrent: {
dist: [
'shell:patternlab', 'sass'
]
}
});
/*
Tasks
*/
// These plugins provide necessary tasks.
require('load-grunt-tasks')(grunt);
grunt.registerTask('serve', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'concurrent',
'shell:patternlab',
'replace',
'connect:livereload',
'browserSync',
'watch'
]);
});
grunt.registerTask('server', function () {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve']);
});
grunt.registerTask('default', ['build']);
grunt.registerTask('wraith', ['shell:wraith']);
grunt.registerTask('test', ['csscss', 'cssmetrics:dev']);
grunt.registerTask('build', ['concurrent', 'uncss', 'cssmin', 'cssmetrics:prod']);
};