Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

New concat option to add to concat config automatically #17

Merged
merged 3 commits into from 12 months ago

3 participants

Chris Gross Eric Clemmons Jedidiah Hurt
Chris Gross

If you use a task like grunt-usemin to pull your concat config from your html file, then its not possible to just add a new line to your concat config. Instead you want this to happen automatically.

So this adds a new option for ngtemplates to automatically have the dest file added to an existing concat config.

Eric Clemmons
Owner
Chris Gross
Eric Clemmons
Owner

This is how I'm using it:

HTML: https://github.com/ericclemmons/genesis-skeleton/blob/master/src/public/index.html#L45
concat: https://github.com/ericclemmons/genesis-skeleton/blob/master/Gruntfile.coffee#L132
ngtemplates: https://github.com/ericclemmons/genesis-skeleton/blob/master/Gruntfile.coffee#L124

In short, I'm creating a single app.js file that contains all of my angular app (otherwise, my HTML would be littered with dozens of tags!). Then, usemin combines all of the script tags, the last of which is my previously-concated app.js.

If your case, the PR-less fix would be to use a simple concat task that combines your app with ngtemplates.app.dest (as seen above). The output would be all you'd need in your HTML.

Will this PR work with the gruntfile I have linked above? Where I have concat: { app: { src: [...] } }?

Chris Gross
Eric Clemmons
Owner
Chris Gross
Eric Clemmons
Owner

@cgross Just letting you know I didn't forget about this :) I'm finishing my vacation today and will be back home this weekend to address this PR.

Eric Clemmons ericclemmons referenced this pull request in ericclemmons/genesis-skeleton
Merged

[WIP] Starter App Cleanup #83

4 of 4 tasks complete
Jedidiah Hurt

Thanks @cgross! This is exactly what I needed! I've pinned my package.json to your fork for now. Hoping this gets merged.

Eric Clemmons
Owner
Jedidiah Hurt
Eric Clemmons
Owner

I was just working on the PR for this (cleaning up the README examples to use the same paths & what not) and was wondering, is there any reason for this to be generic to modify any task?

For example, I cannot use this with my watch or regarde tasks because I'm using the expanded options (e.g. cwd, expand, src, dest, etc.) for locating files vs. useminPrepare's format, which is a simple dest: [ files ] format.

With that in mind, I was going to just make the option obvious & simple:

options: {
  base: ...
  prepend: ...
  usemin: 'path/to/build.js`
}

Sound good guys?

Eric Clemmons
Owner

It would also support usemin: [ 'first/build.js', 'second/build.js' ].

I don't want to change things up on you @cgross if you're modifying tasks besides usemin.

Chris Gross
cgross commented

Hey guys - yea thats ok with me. I've actually moved away from usemin so I'm not even using this feature anymore. Still I do believe anyone continuing to use usemin would benefit by it.

I created grunt-dom-munger to do all the stuff usemin was doing while also being much more flexible (for ex, I needed to be able to exclude certain scripts from minification). https://github.com/cgross/grunt-dom-munger

Eric Clemmons ericclemmons merged commit 8f84769 into from
Eric Clemmons ericclemmons closed this
Eric Clemmons
Owner

Just published v0.3.3! @cgross I was sure to use your commits so that you get credit. Would you like me to add you to the README as a contributor, or the package.json? (I haven't had very many contributors on projects, so not sure the best practice here :D)

I decided to make it simple: just specify the new option concat: 'target' and it adds it. Seems to work for both 'dest': ['files'] and src: ['files'] formats!

Thanks again fro the input fellas!

Chris Gross
cgross commented
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Mar 29, 2013
New concat option to support automatic concat config addition f072795
Apr 02, 2013
Made options more generic so tasks other than concat can be provided …
…(e.g. uglify)
a6ae2fa
Forgot to update read me 8f84769
This page is out of date. Refresh to see the latest.
11  README.md
Source Rendered
@@ -76,6 +76,17 @@ concat: {
76 76
   }
77 77
 }
78 78
 ```
  79
+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).
  80
+
  81
+```js
  82
+myapp:        {
  83
+  options:    {
  84
+    updatetask:{task: 'concat', target: 'dist/app.js'} //Will append 'dist/template.js' to a concat config for 'dist/app.js'
  85
+  },
  86
+  src:        [ 'src/views/**.html' ],
  87
+  dest:       'dist/templates.js'
  88
+}
  89
+```
79 90
 
80 91
 
81 92
 ## Changelog
27  tasks/angular-templates.js
@@ -9,6 +9,7 @@
9 9
 'use strict';
10 10
 
11 11
 var path = require('path');
  12
+var util = require('util');
12 13
 
13 14
 module.exports = function(grunt) {
14 15
 
@@ -19,13 +20,37 @@ module.exports = function(grunt) {
19 20
     var files     = grunt.file.expand(this.files[0].src);
20 21
     var dest      = path.normalize(this.files[0].dest);
21 22
     var done      = this.async();
  23
+    var options   = this.options();
22 24
 
23  
-    compiler.compile(id, this.options(), files, function(err, compiled) {
  25
+    compiler.compile(id, options, files, function(err, compiled) {
24 26
       if (err) {
25 27
         done(false);
26 28
       } else {
27 29
         grunt.file.write(dest, compiled);
28 30
         grunt.log.writeln('File ' + dest.cyan + ' created.');
  31
+
  32
+        if (options.updatetask){
  33
+          if (!options.updatetask.task || !options.updatetask.target){
  34
+            grunt.log.error('Incorrect configuration. updatetask is missing \'task\' or \'target\'.');
  35
+            done(false);
  36
+            return;
  37
+          }
  38
+          var task = grunt.config(options.updatetask.task) || {};
  39
+          var target = task[options.updatetask.target];
  40
+          if (grunt.util.kindOf(target) === 'object'){
  41
+            target = target.src;
  42
+          }
  43
+          if (grunt.util.kindOf(target) !== 'array'){
  44
+            grunt.log.error('Unable to update '+options.updatetask.task+' config. Unable to find valid config for ' + options.updatetask.target.cyan + '.');
  45
+            done(false);
  46
+            return;
  47
+          } else {
  48
+            target.push(dest);
  49
+            grunt.config(options.updatetask.task,task);
  50
+            grunt.log.subhead('Updating '+options.updatetask.task+' config. Config is now:').writeln('   ' + util.inspect(target,false,4,true));
  51
+          }
  52
+        }
  53
+
29 54
         done();
30 55
       }
31 56
     });
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.