Skip to content

Commit

Permalink
New concat option to support automatic concat config addition
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Gross committed Mar 29, 2013
1 parent baad256 commit f072795
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion tasks/angular-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'use strict';

var path = require('path');
var util = require('util');

module.exports = function(grunt) {

Expand All @@ -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();
}
});
Expand Down

0 comments on commit f072795

Please sign in to comment.