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

Invoke a task multiple times with different arguments #315

Closed
evanworley opened this Issue Jul 26, 2012 · 10 comments

Comments

Projects
None yet
3 participants
@evanworley

evanworley commented Jul 26, 2012

Hello,

I'm wondering how I can invoke a task multiple times in my default build. For example, I have two distinct bundles of coffeescript that I would like to compile and concatenate into bundle1.js and bundle2.js. A tweaked version of https://gist.github.com/3072343 works quite well, but because the configuration is in grunt.initConfig, I can't see how I can reconfigure the task and run it again with different arguments.

Thanks for any advice,
Evan

@cowboy

This comment has been minimized.

Show comment
Hide comment
@cowboy

cowboy Jul 26, 2012

Member

Have you tried asking the plugin author?

Member

cowboy commented Jul 26, 2012

Have you tried asking the plugin author?

@evanworley

This comment has been minimized.

Show comment
Hide comment
@evanworley

evanworley Jul 26, 2012

Hi Cowboy,

Thanks for the quick reply. I've modified the task so much, that I might as well be the plugin author. The thing is, i want to dynamically pass in the configuration (source directory, output directory, and other options), so that I can invoke the task multiple times in the build. Is there a way to do this, or must the task configuration be static in the grunt.initConfig?

evanworley commented Jul 26, 2012

Hi Cowboy,

Thanks for the quick reply. I've modified the task so much, that I might as well be the plugin author. The thing is, i want to dynamically pass in the configuration (source directory, output directory, and other options), so that I can invoke the task multiple times in the build. Is there a way to do this, or must the task configuration be static in the grunt.initConfig?

@evanworley

This comment has been minimized.

Show comment
Hide comment
@evanworley

evanworley Jul 26, 2012

Another way to ask it, in terms of built-in plugins. How can I run concat multiple times to make discrete bundles, say "bundle1" which concatenates file1.js and file2.js and "bundle2" which concatenates file3.js and file4.js?

evanworley commented Jul 26, 2012

Another way to ask it, in terms of built-in plugins. How can I run concat multiple times to make discrete bundles, say "bundle1" which concatenates file1.js and file2.js and "bundle2" which concatenates file3.js and file4.js?

@cowboy

This comment has been minimized.

Show comment
Hide comment
@cowboy

cowboy Jul 26, 2012

Member

Take a look at the multi task docs.

Member

cowboy commented Jul 26, 2012

Take a look at the multi task docs.

@evanworley

This comment has been minimized.

Show comment
Hide comment
@evanworley

evanworley Jul 26, 2012

Thanks, I saw that but didn't see how to directly apply it. I'd like to define the "default" task to run the task "coffee" with two different sets of arguments. Instead, it sounds like you are suggesting I'll need to invoke grunt twice from the command line and essentially have two builds. Am I understanding correctly?

Thanks for your help,
Evan

evanworley commented Jul 26, 2012

Thanks, I saw that but didn't see how to directly apply it. I'd like to define the "default" task to run the task "coffee" with two different sets of arguments. Instead, it sounds like you are suggesting I'll need to invoke grunt twice from the command line and essentially have two builds. Am I understanding correctly?

Thanks for your help,
Evan

@cowboy

This comment has been minimized.

Show comment
Hide comment
@cowboy

cowboy Jul 27, 2012

Member
grunt.initConfig({
  coffee: {
    foo: {dir: 'foo-src', dest: 'foo-built'},
    bar: {dir: 'bar-src', dest: 'bar-built'},
    baz: {dir: 'baz-src', dest: 'baz-built'},
  }
});

grunt.registerTask('default', 'coffee:foo coffee:bar');

Running grunt will run coffee:foo then coffee:bar.

Running grunt coffee will run coffee:foo then coffee:bar then coffee:baz.

Running grunt coffee:bar will run just coffee:bar.

(etc)

This is standard multi task behavior.

Member

cowboy commented Jul 27, 2012

grunt.initConfig({
  coffee: {
    foo: {dir: 'foo-src', dest: 'foo-built'},
    bar: {dir: 'bar-src', dest: 'bar-built'},
    baz: {dir: 'baz-src', dest: 'baz-built'},
  }
});

grunt.registerTask('default', 'coffee:foo coffee:bar');

Running grunt will run coffee:foo then coffee:bar.

Running grunt coffee will run coffee:foo then coffee:bar then coffee:baz.

Running grunt coffee:bar will run just coffee:bar.

(etc)

This is standard multi task behavior.

@cowboy cowboy closed this Jul 27, 2012

@evanworley

This comment has been minimized.

Show comment
Hide comment
@evanworley

evanworley Jul 27, 2012

Great, thanks for the help!

evanworley commented Jul 27, 2012

Great, thanks for the help!

@iancrowther

This comment has been minimized.

Show comment
Hide comment
@iancrowther

iancrowther Sep 4, 2012

can i use coffee:foo to trigger some tasks?

eg

grunt.initConfig({
coffee: {
foo: 'execute:generate',
bar: 'bar',
baz: 'baz'
}
});

grunt.registerTask('default', 'coffee');

grunt.registerTask('generate', 'generate', function() {
console.log("generate");
});

iancrowther commented Sep 4, 2012

can i use coffee:foo to trigger some tasks?

eg

grunt.initConfig({
coffee: {
foo: 'execute:generate',
bar: 'bar',
baz: 'baz'
}
});

grunt.registerTask('default', 'coffee');

grunt.registerTask('generate', 'generate', function() {
console.log("generate");
});

@cowboy

This comment has been minimized.

Show comment
Hide comment
@cowboy

cowboy Sep 4, 2012

Member

@iancrowther you can if the task is written to do that. This task probably isn't, but you can always ask the plugin author.

Member

cowboy commented Sep 4, 2012

@iancrowther you can if the task is written to do that. This task probably isn't, but you can always ask the plugin author.

@iancrowther

This comment has been minimized.

Show comment
Hide comment
@iancrowther

iancrowther Sep 4, 2012

thanks for getting back to me, I kinda got that picture from the code. Nice work on the build script btw..

iancrowther commented Sep 4, 2012

thanks for getting back to me, I kinda got that picture from the code. Nice work on the build script btw..

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