5 * Copyright (c) 2012 "Cowboy" Ben Alman
6 * Licensed under the MIT license.
7 * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
10 // Basic template description.
11 exports.description = 'Create a basic grunt.js gruntfile.';
13 // Template-specific notes to be displayed before question prompts.
14 exports.notes = 'This template tries to guess file and directory paths, but ' +
15 'you will most likely need to edit the generated grunt.js file before ' +
16 'running grunt. _If you run grunt after generating grunt.js, and grunt ' +
17 'exits with errors, edit the grunt.js file!_';
19 // Any existing file or directory matching this wildcard will cause a warning.
20 exports.warnOn = 'grunt.js';
22 // The actual init template.
23 exports.template = function(grunt, init, done) {
25 grunt.helper('prompt', {}, [
26 // Prompt for these values.
29 message: 'Is the DOM involved in ANY way?',
31 warning: 'Yes: QUnit unit tests + JSHint "browser" globals. No: Nodeunit unit tests.'
35 message: 'Will files be concatenated or minified?',
37 warning: 'Yes: min + concat tasks. No: nothing to see here.'
41 message: 'Will you have a package.json file?',
43 warning: 'This changes how filenames are determined and banners are generated.'
45 ], function(err, props) {
46 props.dom = /y/i.test(props.dom);
47 props.min_concat = /y/i.test(props.min_concat);
48 props.package_json = /y/i.test(props.package_json);
49 props.test_task = props.dom ? 'qunit' : 'test';
50 props.file_name = props.package_json ? '<%= pkg.name %>' : 'FILE_NAME';
52 // Find the first `preferred` item existing in `arr`.
53 function prefer(arr, preferred) {
54 for (var i = 0; i < preferred.length; i++) {
55 if (arr.indexOf(preferred[i]) !== -1) {
62 // Guess at some directories, if they exist.
63 var dirs = grunt.file.expandDirs('*').map(function(d) { return d.slice(0, -1); });
64 props.lib_dir = prefer(dirs, ['lib', 'src']);
65 props.test_dir = prefer(dirs, ['test', 'tests', 'unit', 'spec']);
67 // Maybe this should be extended to support more libraries. Patches welcome!
68 props.jquery = grunt.file.expandFiles('**/jquery*.js').length > 0;
70 // Files to copy (and process).
71 var files = init.filesToCopy(props);
73 // Actually copy (and process) files.
74 init.copyAndProcess(files, props);