Skip to content

Instantly share code, notes, and snippets.

@siygle
Created July 8, 2012 10:00
Show Gist options
  • Select an option

  • Save siygle/3070299 to your computer and use it in GitHub Desktop.

Select an option

Save siygle/3070299 to your computer and use it in GitHub Desktop.
grunt example
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// use test module for testing, QUnit default but support different testing framework using different plugin
test: {
all: ['test/**/*.js']
},
// run jsLint to check your program
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: {}
}
});
// define task 'default', it will run lint -> test -> docs
grunt.registerTask('default', 'lint test docs');
// Implement 'docs' task yourself.
grunt.registerMultiTask('docs', 'Tweak markdown documentation.', function() {
var files = grunt.file.expandFiles(this.file.src);
var processed = 0;
files.forEach(function(filepath) {
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) {
var slug = grunt.utils._.slugify(title.replace(/\./g, '-'));
return h + ' ' + title + ' <a name="' + slug + '" href="#' + slug +
'" title="Link to this section">⚑</a>';
});
if (newSrc === src) { return false; }
grunt.log.writeln('File "' + filepath + '" updated.');
processed++;
return newSrc;
}});
});
if (this.errorCount) { return false; }
if (processed === 0) {
grunt.log.writeln('No documents updated.');
}
});
};
@siygle
Copy link
Author

siygle commented Jul 8, 2012

clone by grunt basic grunt example, just add my own description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment