forked from cowboy/grunt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tightening things up. Made banner comments more flexible, hopefully i…
…ntuitive. Added config file directives that can go in place of files. Split banner helper into a separate misc tasks file. Added a preliminary grunt.js template.
- Loading branch information
Showing
9 changed files
with
152 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var handlebars = require('handlebars'); | ||
var dateformat = require('dateformat'); | ||
|
||
// ============================================================================ | ||
// HELPERS | ||
// ============================================================================ | ||
|
||
// Used to run a helper associated with a directive. | ||
task.registerHelper('directive', function(dir) { | ||
// If str is a directive, strip off the surrounding <>. | ||
dir = config.getDirective(dir) || dir; | ||
// Split directive into arguments. | ||
var args = dir.split(':'); | ||
// If the helper exists, pass all args in and return its value, otherwise | ||
// return null. | ||
return task._helpers[args[0]] ? task.helper.apply(task, args) : null; | ||
}); | ||
|
||
// Generate banner from template. | ||
task.registerHelper('banner', function(prop) { | ||
if (!prop) { prop = 'meta.banner'; } | ||
var banner; | ||
if (config(prop)) { | ||
verbose.write('Generating banner...'); | ||
try { | ||
// Compile and run template, passing in config object as the data source. | ||
banner = handlebars.compile(config(prop))(config()) + '\n'; | ||
verbose.ok(); | ||
} catch(e) { | ||
banner = ''; | ||
verbose.error(); | ||
log.error(e.message); | ||
fail.warn('Handlebars found errors.'); | ||
} | ||
} else { | ||
fail.warn('No "' + prop + '" banner template defined.'); | ||
banner = ''; | ||
} | ||
return banner; | ||
}); | ||
|
||
// Banner helpers. | ||
handlebars.registerHelper('today', function(format) { | ||
return dateformat(new Date(), format); | ||
}); | ||
|
||
handlebars.registerHelper('join', function(items, separator) { | ||
return items.join(typeof separator === 'string' ? separator : ', '); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Config. | ||
config.init({ | ||
meta: { | ||
name: 'project_name', | ||
version: '0.1.0', | ||
description: '', | ||
homepage: 'http://github.com/your_name/project', | ||
author: 'your_name', | ||
license: ['MIT', 'GPL'], | ||
copyright: 'Copyright (c) YYYY your_name', | ||
repository: 'git://github.com/your_name/project.git', | ||
banner: '/* {{meta.name}} - v{{meta.version}} - {{today "m/d/yyyy"}}\n' + | ||
' * {{meta.homepage}}\n' + | ||
' * {{{meta.copyright}}}; Licensed {{join meta.license}} */' | ||
}, | ||
concat: { | ||
'dist/project.js': ['<banner>', 'lib/project.js'] | ||
}, | ||
min: { | ||
'dist/project.min.js': ['<banner>', 'dist/project.js'] | ||
}, | ||
test: { | ||
files: ['test/**/*.js'] | ||
}, | ||
lint: { | ||
files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js'], | ||
built: 'dist/project.js' | ||
}, | ||
jshint: { | ||
options: { | ||
curly: true, | ||
eqeqeq: true, | ||
immed: true, | ||
latedef: true, | ||
newcap: true, | ||
noarg: true, | ||
sub: true, | ||
undef: true, | ||
eqnull: true | ||
}, | ||
globals: { | ||
} | ||
}, | ||
uglify: {} | ||
}); | ||
|
||
// Default task. | ||
task.registerTask('default', 'lint:files test:files concat lint:built min'); |