forked from gruntjs/grunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
87 lines (80 loc) · 2.28 KB
/
grunt.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
/*
* grunt
* https://github.com/cowboy/grunt
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
test: {
all: ['test/**/*.js']
},
lint: {
all: ['grunt.js', 'lib/**/*.js', 'tasks/*.js', 'tasks/*/*.js', 'test/**/*.js']
},
docs: {
all: ['README.md', 'docs/*.md']
},
watch: {
scripts: {
files: '<config:lint.all>',
tasks: 'lint test'
},
docs: {
files: '<config:docs.all>',
tasks: 'docs'
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
node: true,
es5: true
},
globals: {}
}
});
// Default task.
grunt.registerTask('default', 'lint test docs');
// Process markdown documentation to make the world a better place.
grunt.registerMultiTask('docs', 'Tweak markdown documentation.', function() {
var files = grunt.file.expandFiles(this.file.src);
var processed = 0;
files.forEach(function(filepath) {
// Copying the file to itself allows it to be processed in-place.
grunt.file.copy(filepath, filepath, {process: function(src) {
// Add anchor links to all H2+ headers in .md document files.
var newSrc = src.replace(/(##+)\s+(.*?)\s*<a name=.*<\/a>/g, function(_, h, title) {
// Slugify the title text.
var slug = grunt.utils._.slugify(title.replace(/\./g, '-'));
// Put everything back together.
return h + ' ' + title + ' <a name="' + slug + '" href="#' + slug +
'" title="Link to this section">⚑</a>';
});
// Don't copy file if it didn't change.
if (newSrc === src) { return false; }
// Log and copy.
grunt.log.writeln('File "' + filepath + '" updated.');
processed++;
return newSrc;
}});
});
// Fail task if errors were logged.
if (this.errorCount) { return false; }
if (processed === 0) {
grunt.log.writeln('No documents updated.');
}
});
};