forked from assemble/assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
458 lines (433 loc) · 13.1 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
/*
* Assemble
* Created and maintained by Jon Schlinkert and Brian Woodward
* http://assemble.io
*
* Assemble is a full-featured documentation generator,
* static site generator and component builder. Created
* from the ground up as a plugin for Grunt.js.
*
* Copyright (c) 2013 Upstage
* 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'),
// Translations for `postprocess` tests.
translation: require('./test/fixtures/data/translations'),
// Metadata for banners
meta: {
license: '<%= _.pluck(pkg.licenses, "type").join(", ") %>',
copyright: 'Copyright (c) <%= grunt.template.today("yyyy") %>',
banner: [
'/*',
' * <%= pkg.name %> v<%= pkg.version %>',
' * http://assemble.io',
' *',
' * <%= meta.copyright %>, <%= pkg.author.name %>',
' * Licensed under the <%= meta.license %> License.',
' *',
' */\n'
].join('\n')
},
/**
* Lint all JavaScript
*/
jshint: {
options: {
jshintrc: '.jshintrc'
},
files: [
'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'],
layoutdir: 'test/fixtures/layouts',
layout: 'default.hbs',
flatten: true
},
// 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 post-process content using a custom function
postprocess: {
options: {
postprocess: function(src) {
return require('frep').strWithArr(src, grunt.config.process('<%= translation.patterns %>'));
}
},
files: {
'test/actual/postprocess.html': ['test/fixtures/pages/postprocess/postprocess.hbs']
}
},
// Should post-process content using a custom function
postprocess2: {
options: {
},
files: {
'test/actual/postprocess2.html': ['test/fixtures/pages/postprocess/postprocess2.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']
}
}
},
// Example config data for "pages_array" and "pages_object" targets
component: {
one: "alert"
},
/**
* Beautify generated HTML to make diffs easier
*/
prettify: {
tests: {
options: {ocd: true},
files: [
{expand: true, cwd: 'test/actual', src: ['**/*.html'], dest: 'test/actual/', ext: '.html'}
]
}
},
/**
* Pull down a list of repos from Github, for the docs
*/
repos: {
plugins: {
options: {
username: 'assemble',
include: ['contrib'], exclude: ['grunt', 'example', 'rss']
},
files: {
'docs/plugins.json': ['repos?page=1&per_page=100']
}
}
},
/**
* Build the README using metadata from the repos task.
*/
readme: {
options: {
metadata: ['docs/plugins.json']
}
},
/**
* Before generating any new files,
* remove files from the previous build
*/
clean: {
tests: ['test/actual/**/*']
},
// Automated releases. Bumps packages.json, creates new tag,
// and publishes new release to npm.
release: {
options: {
bump: true,
file: 'package.json',
add: false,
commit: false,
tag: true,
push: true,
pushTags: true,
npm: true,
tagName: '<%= version %>',
commitMessage: 'Bump version to <%= version %>',
tagMessage: 'Bump version to <%= version %>'
}
}
});
// Load NPM plugins to provide the necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-prettify');
grunt.loadNpmTasks('grunt-readme');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-repos');
grunt.loadNpmTasks('grunt-sync-pkg');
// Load this plugin.
grunt.loadTasks('tasks');
// Build
grunt.registerTask('docs', ['repos', 'readme', 'sync']);
// Tests to be run.
grunt.registerTask('test', ['assemble', 'mochaTest']);
// Run default task, then release
grunt.registerTask('bump', ['default', 'release']);
// Default task.
grunt.registerTask('default', ['jshint', 'clean', 'test', 'prettify', 'docs']);
};