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

Question: Why task rules vs. concrete tasks? #25

Open
dougborg opened this issue Sep 29, 2014 · 3 comments
Open

Question: Why task rules vs. concrete tasks? #25

dougborg opened this issue Sep 29, 2014 · 3 comments
Labels

Comments

@dougborg
Copy link
Contributor

I was just wondering what your take on this was. I was initially very attracted to task rules in a lot of my Gradle work. I later found that I usually already knew exactly what tasks I needed to create so it was pretty easy to adjust the rule to actually create a concrete task. This is nice from a user perspective because then gradle tasks gives you more info, you can use the short-hand camel-casing stuff, etc.

Specifically related to the gradle-node-plugin, I could see creating concrete tasks based on the output of npm --help or even a static list maintained in the plugin. This concept would also apply to the gradle-grunt-plugin you maintain. Let me know what you think.

@srs
Copy link
Owner

srs commented Sep 29, 2014

Hi.
I'm a fan of concrete tasks and have not used task rules that much. Concrete tasks could be created using NodeTask and NpmTask right now, but do you suggest creating them using a list of some sort? If you have some ideas on how that would look I would be very interested.

BR,
Sten Roger

@dougborg
Copy link
Contributor Author

dougborg commented Nov 9, 2014

Yeah I have a couple ideas on this, but after thinking about it for a while, I am not really sure how much value it will end up providing. I'll outline what I was thinking though for anyone else who thinks it may be useful. Or maybe I will just end up talking myself into thinking it is a good idea after all.

My basic thought on approach was to create tasks automatically by use the output of npm completion or npm --help to generate a list of tasks for npm. For the grunt plugin, we would load up a list of tasks by either analyzing the Gruntfile, invoking grunt -h, or running some javascript to grab a task list from grunt some other way. It may even make sense to just have a list of tasks we know would be useful and maintain it as we see fit.

You could then loop through the list to create your tasks:

def npmCommands = [ "npm update", "npm cache clean", "npm config set" ]

npmCommands.each { String npmCommand ->

  def npmArgs = (npmCommand - "npm").tokenize()
  def taskName = "npm" + npmArgs*.capitalize().join()

  project.task(taskName, type: NpmTask) {
    group = 'Node'
    description = "Run \'${npmCommand}\'."
    args = npmArgs
  }
}

Concrete tasks may be easier for users to reason about and are a bit more discoverable than task rules. The show up nicely when you run gradle tasks:

...

Node tasks
----------
nodeSetup - Download and install a local node/npm version.
npmCacheClean - Run 'npm cache clean'.
npmConfigSet - Run 'npm config set'.
npmInstall - Install node packages from package.json.
npmSetup - Setup a specific version of npm to be used by the build.
npmUpdate - Run 'npm update'.

...

@srs
Copy link
Owner

srs commented Nov 10, 2014

That's pretty nice. I like the idea that you could specify something like this:

node {
  npmCommands = [ "npm update", "npm cache clean", "npm config set" ]
}

And then it will automatically create the task definitions for you. But not sure if that's a feature that is really needed. Just looks nice :-)

@srs srs added the question label Jun 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants