Skip to content

Commit a211792

Browse files
committed
Add init templates for default and rjs configuration
1 parent f72f4f8 commit a211792

File tree

4 files changed

+112
-4
lines changed

4 files changed

+112
-4
lines changed

tasks/init/h5bp.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,41 @@ h5bp.steps = 'project setup files gruntfile'.split(' ');
2121
h5bp.template = function(grunt, init, done) {
2222
h5bp.grunt = grunt;
2323

24+
// --template bypass all the prompts and run the specified template
25+
// a template is simply a json files including answers that otherwise would
26+
// have been prompted
27+
var template = grunt.option('template');
28+
29+
// get the list of template files
30+
var templates = grunt.file.expandFiles(path.join(__dirname, 'templates/*.json'))
31+
// map to only the basename, minus extension
32+
.map(function(filename) {
33+
return path.basename(filename).replace(path.extname(filename), '');
34+
})
35+
// reduce the array down to a single hash object with key mapping the
36+
// template name, value the path to the json template
37+
.reduce(function(o, file) {
38+
o[file] = path.join(__dirname, 'templates', file + '.json');
39+
return o;
40+
}, {});
41+
42+
if(template && templates[template]) return fs.readFile(templates[template], 'utf8', function(err, body) {
43+
if(err) {
44+
grunt.log.error(err);
45+
return done(false);
46+
}
47+
48+
h5bp.end(init, JSON.parse(body), done);
49+
});
50+
2451
// setup custom prompt
2552
h5bp.customPrompt();
2653

2754
(function run(step) {
28-
if(!step) return h5bp.end(init, h5bp.props, done);
55+
if(!step) {
56+
fs.writeFileSync(path.join(__dirname, 'templates/rjs.json'), JSON.stringify(h5bp.props, null, 2));
57+
return h5bp.end(init, h5bp.props, done);
58+
}
2959

3060
h5bp[step](function(err, props) {
3161
if(err) {
@@ -37,7 +67,7 @@ h5bp.template = function(grunt, init, done) {
3767
else h5bp.props[step] = props;
3868
run(h5bp.steps.shift());
3969
});
40-
})(h5bp.steps.shift())
70+
})(h5bp.steps.shift());
4171

4272
};
4373

@@ -108,7 +138,7 @@ h5bp.gruntfile = function(cb) {
108138
},
109139
{
110140
name: 'min_concat',
111-
message: 'Will files be concatenated or minified? (Select no if using require.js to organize and minify your javascript.)',
141+
message: 'Will files be concatenated or minified? (Select no if using require.js to organize and minify your javascript)',
112142
default: 'Y/n',
113143
warning: 'Yes: min + concat tasks. No: nothing to see here.'
114144
},
@@ -118,7 +148,6 @@ h5bp.gruntfile = function(cb) {
118148
default: 'Y/n',
119149
warning: 'This changes how filenames are determined and banners are generated.'
120150
},
121-
122151
{
123152
name: 'staging',
124153
message: 'What is the intermediate/ directory for the build script?',

tasks/init/h5bp/gruntfile.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@ module.exports = function(grunt) {
100100
}{% } %}
101101
});
102102

103+
{% if (require_js) { %}
104+
// in rjs setup, the concat and min task are overriden to use rjs optimizr
105+
grunt.renameTask('concat', '_concat').registerTask('concat', 'rjs (noop)', function() {
106+
grunt.log.writeln('the concat in rjs setup is a noop, rjs optimizer somewhat replace js concatenation');
107+
});
108+
grunt.renameTask('min', '_min').registerTask('min', 'rjs');
109+
{% } %}
110+
111+
{% if (plugin) { %}
112+
grunt.loadNpmTasks('{%= plugin %}');
113+
{% } %}
103114
};

tasks/init/templates/defaults.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "name",
3+
"description": "The best project ever.",
4+
"version": "0.1.0",
5+
"repository": "git://github.com/h5bp/node-build-script.git",
6+
"homepage": "https://github.com/h5bp/node-build-script",
7+
"licenses": [
8+
"MIT"
9+
],
10+
"author_name": "",
11+
"author_email": "",
12+
"author_url": "",
13+
"force_update": "y/N",
14+
"js_safe_name": "name",
15+
"git_user": "h5bp",
16+
"setup": {
17+
"layout": "D"
18+
},
19+
"gruntfile": {
20+
"dom": true,
21+
"min_concat": true,
22+
"package_json": true,
23+
"staging": "intermediate",
24+
"output": "publish",
25+
"css_dir": "css",
26+
"js_dir": "js",
27+
"img_dir": "img",
28+
"require_js": "y/N",
29+
"test_task": "qunit",
30+
"file_name": "<%= pkg.name %>",
31+
"test_dir": "test",
32+
"jquery": true
33+
}
34+
}

tasks/init/templates/rjs.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "name",
3+
"description": "rjs default setup",
4+
"version": "0.1.0",
5+
"repository": "git://github.com/h5bp/node-build-script.git",
6+
"homepage": "https://github.com/h5bp/node-build-script",
7+
"licenses": [
8+
"MIT"
9+
],
10+
"author_name": "",
11+
"author_email": "",
12+
"author_url": "",
13+
"force_update": "y/N",
14+
"js_safe_name": "name",
15+
"git_user": "h5bp",
16+
"setup": {
17+
"layout": "D"
18+
},
19+
"gruntfile": {
20+
"dom": true,
21+
"min_concat": false,
22+
"package_json": true,
23+
"staging": "intermediate",
24+
"output": "publish",
25+
"css_dir": "css",
26+
"js_dir": "js",
27+
"img_dir": "img",
28+
"require_js": "y",
29+
"test_task": "qunit",
30+
"file_name": "<%= pkg.name %>",
31+
"test_dir": "test",
32+
"jquery": true
33+
}
34+
}

0 commit comments

Comments
 (0)