-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Gruntfile.js
396 lines (381 loc) · 11.7 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
385
386
387
388
389
390
391
392
393
394
395
396
/**
* Assemble <http://assemble.io>
*
* Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
* Licensed under the MIT License (MIT).
*/
module.exports = function(grunt) {
// Report elapsed execution time of grunt tasks.
require('time-grunt')(grunt);
// Project configuration.
grunt.initConfig({
// Metadata for tests
pkg: grunt.file.readJSON('package.json'),
config: grunt.file.readJSON('test/fixtures/data/config.json'),
site: grunt.file.readYAML('test/fixtures/data/_site.yml'),
/**
* Lint all JavaScript
*/
eslint: {
src: [
'Gruntfile.js',
'lib/**/*.js',
'tasks/**/*.js',
'test/**/*.js'
]
},
/**
* Run mocha tests.
*/
mochaTest: {
tests: {
options: {
reporter: 'progress'
},
src: ['test/**/*_test.js']
}
},
/**
* Assemble examples/tests
*/
assemble: {
options: {
assets: 'test/assets',
helpers: ['test/helpers/*.js', 'handlebars-helper-eachitems'],
layoutdir: 'test/fixtures/layouts',
layout: 'default.hbs',
flatten: true,
data: {
global1: 'globalData1',
global2: 'globalData2'
}
},
// Should render pages with `layout: false` or `layout: none` defined
no_layout: {
files: {
'test/actual/no_layout/': ['test/fixtures/pages/nolayout/*.hbs']
}
},
// Should allow Layouts defined in YFM to be defined without an extension.
layout_ext: {
options: {
layout: 'none', // override default, layout is redefined in YFM
layoutext: '.hbs'
},
files: {
'test/actual/layout_ext/': ['test/fixtures/pages/layoutext/layoutext.hbs']
}
},
// Should flatten nested layouts
nested_layouts: {
options: {
partials: 'test/fixtures/partials/*.hbs',
data: 'test/fixtures/data/*.{json,yml}',
layout: 'one.hbs'
},
files: {
'test/actual/nested_layouts/': ['test/fixtures/pages/nested/*.hbs']
}
},
// Should register locally-defined custom helpers
custom_helpers: {
options: {
helpers: ['test/helpers/*.js'],
name: '<%= pkg.name %>'
},
files: {
'test/actual/custom_helpers/': ['test/fixtures/helpers/{foo,bar,opt}.hbs']
}
},
// Should register and use custom plugins, without a stage defined
plugin_untitled: {
options: {
plugins: ['./test/plugins/untitled.js']
},
files: {
'test/actual/plugin_untitled.html': 'test/fixtures/plugins/untitled.hbs'
}
},
// Should use custom plugins with 'render:pre:pages' stage defined
plugin_before: {
options: {
plugins: ['./test/plugins/plugin_before.js']
},
files: {
'test/actual/plugin_before.html': 'test/fixtures/plugins/before.hbs'
}
},
// Should use custom plugins with 'render:post:pages' stage defined
plugin_after: {
options: {
plugins: ['./test/plugins/plugin_after.js']
},
files: {
'test/actual/plugin_after.html': 'test/fixtures/plugins/after.hbs'
}
},
// Should use custom plugins with 'render:pre:page' stage defined
plugin_pre_page: {
options: {
plugins: ['./test/plugins/plugin_pre_page.js']
},
files: {
'test/actual/plugin_pre_page.html': 'test/fixtures/plugins/after.hbs'
}
},
// Should do nothing for a non-existant plugin
plugin_none: {
options: {
plugins: ['./test/plugins/not_real.js']
},
files: {
'test/actual/not_real.html': 'test/fixtures/plugins/after.hbs'
}
},
// should add isCurrentPage and relativeLink to each page
// in the pages collection
plugin_preprocess_page_collection: {
options: {
partials: ['test/fixtures/partials/*.hbs'],
data: 'test/fixtures/data/*.{json,yml}',
layout: 'preprocess.hbs',
pageCollection: {
preprocess: require('./test/plugins/page_collection_preprocessing.js')
}
},
files: {
'test/actual/plugin_preprocess/': ['test/fixtures/pages/*.hbs']
}
},
// Path construction based on built-in variables
// Should automatically calculate relative paths correctly
paths: {
options: {
partials: 'test/fixtures/partials/*.hbs',
data: 'test/fixtures/data/*.{json,yml}'
},
files: {
'test/actual/paths/': ['test/fixtures/pages/*.hbs']
}
},
// Should build a single page, with explicit dest page name defined
single_page: {
files: {
'test/actual/single_page.html': ['test/fixtures/pages/example.hbs']
}
},
// Should process and add complex YAML front matter to context
yfm: {
options: {
data: 'test/fixtures/data/*.{json,yml}'
},
files: {
'test/actual/yfm/': ['test/fixtures/pages/yfm/*.hbs']
}
},
// Should process pages no YAML front matter defined
noyfm: {
options: {
data: 'test/fixtures/data/*.{json,yml}'
},
files: {
'test/actual/noyfm/': ['test/fixtures/pages/no-yfm.hbs']
}
},
// Should properly calculate relative paths from nested pages
// to `assets` directory
assets_base: {
options: {assets: 'test/assets', assets_base: true},
files: {
'test/actual/assets_base.html': ['test/fixtures/assets_path/assets.hbs']
}
},
// Should properly calculate relative paths from pages to `assets` directory
assets_nested: {
options: {assets: 'test/assets/nested', assets_nested: true},
files: {
'test/actual/assets_nested.html': ['test/fixtures/assets_path/assets.hbs']
}
},
// Should properly calculate path to `assets` directory when defined
// with a trailing slash
assets_trailing_slash: {
options: {assets: 'test/assets/', assets_trailing_slash: true},
files: {
'test/actual/assets_trailing_slash.html': ['test/fixtures/assets_path/assets.hbs']
}
},
// Should properly calculate path to `assets` directory when the path
// begins with `./`
assets_dot_slash: {
options: {assets: './test/assets', assets_dot_slash: true},
files: {
'test/actual/assets_dot_slash.html': ['test/fixtures/assets_path/assets.hbs']
}
},
// Should properly calculate path to `assets` directory when the
// assets path is blank
assets_blank_path: {
options: {assets: '', assets_blank_path: true},
files: {
'test/actual/assets_blank_path.html': ['test/fixtures/assets_path/assets.hbs']
}
},
// Should add collections to context, sorted in descending order.
collections_desc: {
options: {
collections: [
{name: 'pages', inflection: 'page', sortorder: 'DESC'},
{name: 'tags', inflection: 'tag', sortorder: 'DESC'},
{name: 'categories', inflection: 'category', sortorder: 'DESC'}
]
},
files: {
'test/actual/collections/desc/': ['test/fixtures/pages/*.hbs']
}
},
// Should add collections to context, sorted in ascending order.
collections_asc: {
options: {
collections: [
{name: 'pages', inflection: 'page', sortorder: 'ASC'},
{name: 'tags', inflection: 'tag', sortorder: 'ASC'},
{name: 'categories', inflection: 'category', sortorder: 'ASC'}
]
},
files: {
'test/actual/collections/asc/': ['test/fixtures/pages/*.hbs']
}
},
// Should
collections_custom: {
options: {
collections: [
{name: 'items', inflection: 'item', sortorder: 'DESC'}
]
},
files: {
'test/actual/collections/custom/': ['test/fixtures/pages/*.hbs']
}
},
// Should add complex collections and related pages to context
collections_complex: {
options: {
data: ['test/fixtures/data/collections/*.json']
},
files: {
'test/actual/collections/complex/': ['test/fixtures/pages/*.hbs']
}
},
// Pages collections
pages_array: {
options: {
layout: 'post.hbs',
site: {
title: 'A Blog',
author: 'Jon Schlinkert'
},
pages: '<%= config.pages.one %>'
},
files: {
'test/actual/pages_array/': ['test/fixtures/pages/blog/index.hbs']
}
},
pages_object: {
options: {
layout: 'post.hbs',
site: {
title: 'Another Blog',
author: 'Brian Woodward'
},
pages: '<%= config.pages.two %>'
},
files: {
'test/actual/pages_object/': ['test/fixtures/pages/blog/index.hbs']
}
},
pages_metadata: {
options: {
layout: 'post.hbs',
site: {
title: 'Another Blog with Meta',
author: 'Brian Woodward'
},
pages: '<%= config.pages.three %>'
},
files: {
'test/actual/pages_metadata/': ['test/fixtures/pages/blog/index.hbs']
}
},
// Using glob pattern for layouts
glob_layout: {
options: {
layouts: 'test/fixtures/layouts/**/*.hbs',
layoutdir: undefined
},
files: {
'test/actual/globlayout/simple': ['test/fixtures/pages/globlayout/globlayout.hbs']
}
},
// Using glob pattern for layouts
glob_layout_multi: {
options: {
layouts: ['test/fixtures/layouts/*.hbs', 'test/fixtures/layouts/globlayout/**/*.hbs']
},
files: {
'test/actual/globlayout/multi': ['test/fixtures/pages/globlayout/globlayout.hbs']
}
},
// Should process pages no YAML front matter defined
noyfmdata: {
options: {
data: {
one: '1-one',
two: '2-two',
three: '3-three',
global1: 'override global1 data via task option'
}
},
files: {
'test/actual/noyfm/no-yfm-data.html': ['test/fixtures/pages/no-yfm-data.hbs']
}
},
// Should process pages no YAML front matter defined
noyfmdatafile: {
options: {
data: 'test/fixtures/data/data.yml'
},
files: {
'test/actual/noyfm/no-yfm-datafile.html': ['test/fixtures/pages/no-yfm-data.hbs']
}
}
},
// Example config data for 'pages_array' and 'pages_object' targets
component: {
one: 'alert'
},
/**
* Before generating any new files,
* remove files from the previous build
*/
clean: {
tests: ['test/actual/**/*']
}
});
// Load NPM plugins to provide the necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('gruntify-eslint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-sync-pkg');
grunt.loadNpmTasks('grunt-verb');
// Load this plugin.
grunt.loadTasks('tasks');
// Lint
grunt.registerTask('lint', ['eslint']);
// Build
grunt.registerTask('docs', ['verb', 'sync']);
// Tests to be run.
grunt.registerTask('test', ['assemble', 'mochaTest']);
// Default task.
grunt.registerTask('default', ['lint', 'clean', 'test', 'docs']);
};