From f0727954ebe48b65221083f8481ab3194acab279 Mon Sep 17 00:00:00 2001 From: Chris Gross Date: Fri, 29 Mar 2013 10:19:59 -0400 Subject: [PATCH 1/3] New concat option to support automatic concat config addition --- README.md | 11 +++++++++++ tasks/angular-templates.js | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82fad25..41cd311 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,17 @@ concat: { } } ``` +or let `ngtemplates` do it dynamically via the `concat` options. This is particularly useful if you're using a task that dynamically populates your concat configuration like [grunt-usemin](https://github.com/yeoman/grunt-usemin). + +```js +myapp: { + options: { + concat: 'dist/app.js' //Will append 'dist/template.js' to an existing concat config for 'dist/app.js' + }, + src: [ 'src/views/**.html' ], + dest: 'dist/templates.js' +} +``` ## Changelog diff --git a/tasks/angular-templates.js b/tasks/angular-templates.js index bbce07c..7c8a510 100644 --- a/tasks/angular-templates.js +++ b/tasks/angular-templates.js @@ -9,6 +9,7 @@ 'use strict'; var path = require('path'); +var util = require('util'); module.exports = function(grunt) { @@ -19,13 +20,31 @@ module.exports = function(grunt) { var files = grunt.file.expand(this.files[0].src); var dest = path.normalize(this.files[0].dest); var done = this.async(); + var options = this.options(); - compiler.compile(id, this.options(), files, function(err, compiled) { + compiler.compile(id, options, files, function(err, compiled) { if (err) { done(false); } else { grunt.file.write(dest, compiled); grunt.log.writeln('File ' + dest.cyan + ' created.'); + + if (options.concat){ + var concat = grunt.config('concat') || {}; + var concatSrc = concat[options.concat]; + if (grunt.util.kindOf(concatSrc) === 'object'){ + concatSrc = concat[options.concat].src; + } + if (grunt.util.kindOf(concatSrc) !== 'array'){ + grunt.log.error('Unable to update concat config. Unable to find valid concat config for ' + options.concat.cyan + '.'); + done(false); + return; + } else { + concatSrc.push(dest); + grunt.config('concat',concat); + grunt.log.subhead('Updating concat config. Config is now:').writeln(' ' + util.inspect(concat,false,4,true)); + } + } done(); } }); From a6ae2fac15579e14583e140cca1805e861ba0708 Mon Sep 17 00:00:00 2001 From: Chris Gross Date: Tue, 2 Apr 2013 09:33:35 -0400 Subject: [PATCH 2/3] Made options more generic so tasks other than concat can be provided (e.g. uglify) --- tasks/angular-templates.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tasks/angular-templates.js b/tasks/angular-templates.js index 7c8a510..45e87ec 100644 --- a/tasks/angular-templates.js +++ b/tasks/angular-templates.js @@ -29,22 +29,28 @@ module.exports = function(grunt) { grunt.file.write(dest, compiled); grunt.log.writeln('File ' + dest.cyan + ' created.'); - if (options.concat){ - var concat = grunt.config('concat') || {}; - var concatSrc = concat[options.concat]; - if (grunt.util.kindOf(concatSrc) === 'object'){ - concatSrc = concat[options.concat].src; + if (options.updatetask){ + if (!options.updatetask.task || !options.updatetask.target){ + grunt.log.error('Incorrect configuration. updatetask is missing \'task\' or \'target\'.'); + done(false); + return; } - if (grunt.util.kindOf(concatSrc) !== 'array'){ - grunt.log.error('Unable to update concat config. Unable to find valid concat config for ' + options.concat.cyan + '.'); + var task = grunt.config(options.updatetask.task) || {}; + var target = task[options.updatetask.target]; + if (grunt.util.kindOf(target) === 'object'){ + target = target.src; + } + if (grunt.util.kindOf(target) !== 'array'){ + grunt.log.error('Unable to update '+options.updatetask.task+' config. Unable to find valid config for ' + options.updatetask.target.cyan + '.'); done(false); return; } else { - concatSrc.push(dest); - grunt.config('concat',concat); - grunt.log.subhead('Updating concat config. Config is now:').writeln(' ' + util.inspect(concat,false,4,true)); + target.push(dest); + grunt.config(options.updatetask.task,task); + grunt.log.subhead('Updating '+options.updatetask.task+' config. Config is now:').writeln(' ' + util.inspect(target,false,4,true)); } } + done(); } }); From 8f84769c1ddf89dc95bfbf3b281a8d4a35fa0b25 Mon Sep 17 00:00:00 2001 From: Chris Gross Date: Tue, 2 Apr 2013 10:12:43 -0400 Subject: [PATCH 3/3] Forgot to update read me --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41cd311..6e9d144 100644 --- a/README.md +++ b/README.md @@ -76,12 +76,12 @@ concat: { } } ``` -or let `ngtemplates` do it dynamically via the `concat` options. This is particularly useful if you're using a task that dynamically populates your concat configuration like [grunt-usemin](https://github.com/yeoman/grunt-usemin). +or let `ngtemplates` do it dynamically via the `updatetask` options. This is particularly useful if you're using a task that dynamically populates your concat configuration like [grunt-usemin](https://github.com/yeoman/grunt-usemin). ```js myapp: { options: { - concat: 'dist/app.js' //Will append 'dist/template.js' to an existing concat config for 'dist/app.js' + updatetask:{task: 'concat', target: 'dist/app.js'} //Will append 'dist/template.js' to a concat config for 'dist/app.js' }, src: [ 'src/views/**.html' ], dest: 'dist/templates.js'