Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New concat option to add to concat config automatically #17

Merged
merged 3 commits into from
May 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `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: {
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'
}
```


## Changelog
Expand Down
27 changes: 26 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,37 @@ 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.updatetask){
if (!options.updatetask.task || !options.updatetask.target){
grunt.log.error('Incorrect configuration. updatetask is missing \'task\' or \'target\'.');
done(false);
return;
}
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 {
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();
}
});
Expand Down