1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | exports.description = 'Create a basic grunt.js gruntfile.';
|
12 |
|
13 |
|
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!_';
|
18 |
|
19 |
|
20 | exports.warnOn = 'grunt.js';
|
21 |
|
22 |
|
23 | exports.template = function(grunt, init, done) {
|
24 |
|
25 | var task = grunt.task;
|
26 | var file = grunt.file;
|
27 | var utils = grunt.utils;
|
28 | var log = grunt.log;
|
29 | var verbose = grunt.verbose;
|
30 | var fail = grunt.fail;
|
31 | var option = grunt.option;
|
32 | var config = grunt.config;
|
33 | var template = grunt.template;
|
34 |
|
35 | grunt.helper('prompt', {}, [
|
36 |
|
37 | {
|
38 | name: 'dom',
|
39 | message: 'Is the DOM involved in ANY way?',
|
40 | default: 'Y/n',
|
41 | warning: 'Yes: QUnit unit tests + JSHint "browser" globals. No: Nodeunit unit tests.'
|
42 | },
|
43 | {
|
44 | name: 'min_concat',
|
45 | message: 'Will files be concatenated or minified?',
|
46 | default: 'Y/n',
|
47 | warning: 'Yes: min + concat tasks. No: nothing to see here.'
|
48 | },
|
49 | {
|
50 | name: 'package_json',
|
51 | message: 'Will you have a package.json file?',
|
52 | default: 'Y/n',
|
53 | warning: 'This changes how filenames are determined and banners are generated.'
|
54 | }
|
55 | ], function(err, props) {
|
56 | props.dom = /y/i.test(props.dom);
|
57 | props.min_concat = /y/i.test(props.min_concat);
|
58 | props.package_json = /y/i.test(props.package_json);
|
59 | props.test_task = props.dom ? 'qunit' : 'test';
|
60 | props.file_name = props.package_json ? '<%= pkg.name %>' : 'FILE_NAME';
|
61 |
|
62 |
|
63 | function prefer(arr, preferred) {
|
64 | for (var i = 0; i < preferred.length; i++) {
|
65 | if (arr.indexOf(preferred[i]) !== -1) {
|
66 | return preferred[i];
|
67 | }
|
68 | }
|
69 | return preferred[0];
|
70 | }
|
71 |
|
72 |
|
73 | var dirs = file.expandDirs('*').map(function(d) { return d.slice(0, -1); });
|
74 | props.lib_dir = prefer(dirs, ['lib', 'src']);
|
75 | props.test_dir = prefer(dirs, ['test', 'tests', 'unit', 'spec']);
|
76 |
|
77 |
|
78 | props.jquery = file.expandFiles('**/jquery*.js').length > 0;
|
79 |
|
80 |
|
81 | var files = init.filesToCopy(props);
|
82 |
|
83 |
|
84 | init.copyAndProcess(files, props);
|
85 |
|
86 |
|
87 | done();
|
88 | });
|
89 |
|
90 | };
|