f08fef4d by Adam Heath

wip

1 parent 3c798b39
...@@ -9,8 +9,54 @@ module.exports = function (grunt) { ...@@ -9,8 +9,54 @@ module.exports = function (grunt) {
9 var _ = require('lodash'); 9 var _ = require('lodash');
10 function createConfig(mpConfig) { 10 function createConfig(mpConfig) {
11 11
12 var initConfig = {}; 12 var holyGrailTmp = '.grunt/holygrail';
13 var initConfig = {
14 clean: {
15 dist: {
16 files: [{
17 dot: true,
18 src: [
19 holyGrailTmp,
20 'dist/*',
21 '!dist/.git*'
22 ]
23 }]
24 },
25 },
26 };
13 var checkList = []; 27 var checkList = [];
28 var buildList = [
29 'check',
30 'clean:dist',
31 ];
32
33 function externalMultiTask(name, desc, command, updateOptions) {
34 grunt.log.writeln('registering multiTask', name);
35 grunt.registerMultiTask(name, desc, function() {
36 grunt.log.writeln('foobar', name);
37 grunt.log.writeln('foobar', name);
38 var done = this.async();
39 var options = this.options();
40 var target = this.target;
41 var configFile = holyGrailTmp + '/configs/' + name + '-' + target + '.json';
42 var commandArgs = updateOptions.apply(this, [target, options, configFile]);
43 grunt.file.write(configFile, JSON.stringify(options) + '\n');
44 grunt.log.writeln(JSON.stringify(commandArgs) + '\n');
45 require('child_process').execFile(command, commandArgs, function (error, stdout, stderr) {
46 stdout = stdout.split('\n').map(function(v) {
47 return name + ':' + target + ': ' + v;
48 }).join('\n');
49 grunt.log.writeln(stdout);
50 if (error) {
51 stderr = stderr.split('\n').map(function(v) {
52 return name + ':' + target + ': ' + v;
53 }).join('\n');
54 grunt.log.writeln(stderr);
55 }
56 done(error);
57 });
58 });
59 }
14 60
15 grunt.loadNpmTasks('grunt-monty-python'); 61 grunt.loadNpmTasks('grunt-monty-python');
16 if (mpConfig.jshint) { 62 if (mpConfig.jshint) {
...@@ -48,6 +94,78 @@ module.exports = function (grunt) { ...@@ -48,6 +94,78 @@ module.exports = function (grunt) {
48 checkList.push('htmlmin'); 94 checkList.push('htmlmin');
49 } 95 }
50 96
97 if (common.punch) {
98 grunt.registerMultiTask('punch', 'run punch externally to create html files', function() {
99 var done = this.async();
100 var options = this.options();
101 var target = this.target;
102
103 //var PunchConfigHandler = require('punch/lib/config_handler');
104 var PunchSiteGenerator = require('punch/lib/site_generator');
105 var punchConfig = _.clone(require('punch/lib/default_config'));
106 _.merge(punchConfig, options);
107 punchConfig.output_dir = holyGrailTmp + '/punch/output-' + target;
108 punchConfig.generator.blank = false;
109
110 PunchSiteGenerator.setup(punchConfig);
111 grunt.log.write('foo', punchConfig);
112 try {
113 PunchSiteGenerator.generate(function() {
114 grunt.log.writeln('done generator', arguments);
115 done(true);
116 });
117 } catch (e) {
118 grunt.log.writeln('fail', e);
119 done(false);
120 }
121 });
122
123 initConfig.punch = {
124 options: {
125 'template_dir': 'src/punch/templates',
126 'content_dir': 'src/punch/contents',
127 plugins: {
128 parsers: {
129 '.html': 'punch-html-fragment-content-parser',
130 },
131 },
132 bundles: {
133 },
134 },
135 generate: {
136 },
137 };
138 buildList.push('punch:generate');
139 }
140
141
142 buildList.push('useminPrepare'); // html
143 //buildList.push('usemin:views'
144 buildList.push('requirejs'); // script
145 buildList.push('copy:css'); // css
146 buildList.push('imagemin'); // image
147 buildList.push('svgmin'); // image
148 buildList.push('rev:img'); // image
149 buildList.push('autoprefixer'); // css
150 /*
151 'concat:requirejs', // montyPython
152 'concat:generated', // montyPython
153 'cssmin', // montyPython
154 //'uglify:dist',
155 'copy:dist',
156 //'modernizr',
157 'uglify:generated', // montyPython
158 //'rev:dist', // montyPython
159 'rev:css', // montyPython
160 'revconfig', // montyPython
161 'uglify:bower', // montyPython
162 'uglify:requireconfig', // montyPython
163 'rev:requireconfig', // montyPython
164 'usemin:html', // montyPython
165 'usemin:css', // montyPython
166 'htmlmin', // montyPython
167 */
168
51 grunt.initConfig(initConfig); 169 grunt.initConfig(initConfig);
52 170
53 grunt.registerTask('check', checkList); 171 grunt.registerTask('check', checkList);
...@@ -56,6 +174,7 @@ module.exports = function (grunt) { ...@@ -56,6 +174,7 @@ module.exports = function (grunt) {
56 'check', 174 'check',
57 ]); 175 ]);
58 176
177 grunt.registerTask('build', buildList);
59 } 178 }
60 179
61 return { 180 return {
......
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
16 "main": "grunt-monty-python", 16 "main": "grunt-monty-python",
17 "dependencies": { 17 "dependencies": {
18 "grunt": "~0", 18 "grunt": "~0",
19 "grunt-contrib-clean": "~0",
19 "grunt-contrib-csslint": "~0", 20 "grunt-contrib-csslint": "~0",
20 "grunt-contrib-jshint": "~0", 21 "grunt-contrib-jshint": "~0",
21 "grunt-contrib-htmlmin": "~0", 22 "grunt-contrib-htmlmin": "~0",
22 "lodash": "~2" 23 "lodash": "~2",
24 "punch": "~0.5.46",
25 "punch-html-fragment-content-parser": "^0.5.1"
23 }, 26 },
24 "devDependencies": { 27 "devDependencies": {
25 } 28 }
......