-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Run specific task(s) with force option #810
Comments
I second this request. |
Sounds great. I might have an alias for other tasks, some of which are allowed to fail without failing the mother task. Something like this would be good for me. There probably is a better syntax though. grunt.registerTask('test', ['jshint --force', 'karma:test']); The karma task would have force off unless I run the mother task with --force
|
+1 btw, @explunit a bit of an improvement to the hack while we wait for this to land: var previous_force_state = grunt.option("force");
grunt.registerTask("force",function(set){
if (set === "on") {
grunt.option("force",true);
}
else if (set === "off") {
grunt.option("force",false);
}
else if (set === "restore") {
grunt.option("force",previous_force_state);
}
});
// .....
grunt.registerTask("foobar",[
"task1",
"task2",
"force:on", // temporarily turn on --force
"task3", // will run with --force in effect
"force:restore",// restore previous --force state
"task4"
]); |
+1 |
Proposed solutions don't work in |
There is also https://npmjs.org/package/grunt-continue. |
May be grunt.initConfig({
concat: {
foo: {
files: {
'dest/a.js': ['src/aa.js', 'src/aaa.js'],
'dest/a1.js': ['src/aa1.js', 'src/aaa1.js'],
},
force: true,
},
bar: {
files: {
'dest/b.js': ['src/bb.js', 'src/bbb.js'],
'dest/b1.js': ['src/bb1.js', 'src/bbb1.js'],
},
force: false,
},
},
}); |
Issue was opened 7 months ago, and the pull request (yaymukund/grunt-simple-mocha#36) addresses it. Has this been considered by the core contributors? |
Currently set milestone target is 0.4.3. Which is the next release, so we shall look at this. |
Outstanding. Thanks for getting eyes on this @vladikoff |
We have looked at this and discussed some syntax options. |
Can you elaborate on why that's not an option? Something like What about the inverse, like grunt.registerTask("force",function(task){
var previous_force_state = grunt.option("force");
grunt.option("force",true);
grunt.runTask(task); // ??? is that how you run tasks?
grunt.option("force",previous_force_state)
}); That way, wherever you have the ability to specify a task, if you want to force it, you just say "force: ..." to force it, or "..." to not force it. Would that work? |
@getify unfortunately, task names can be any arbitrary string. By giving the substring Either way, it feels more like a band-aid than a real solution, because I can think of scenarios where the For example, what if you have tasks a, b and c and you want b to not run if a fails, but you want c to run, regardless of the success of a or b. I dunno. |
To expand on that, we were talking about syntax solutions for this: |
oh please don't add a custom set of syntax where none is needed. there's already a convention in Javascript which could be used for that kind of notation:
That would only require the introduction of a config option to force, or not to force. Or what to force, specifically. If you wanted to get nuts:
|
+1 I agree with @shellscape on the nesting thing. And I still think
what use cases would that be missing? |
@getify that misses 1 use case: if 'a' fails, do we even want to try running 'b', same with e/f I think I prefer @shellscape's idea (disclaimer: @shellscape is a coworker). Anything in a sub-group is essentially, a sub-grunt that succeeds or fails atomically, and doesn't affect the parent group. |
I like the prepending format, but what about using something like |
@shellscape could you explain all four "force" options? By "default" do you mean the current behavior? |
Yeah "(default)" got put in the wrong place. Thanks for catching that. By no means set in stone, but off the cuff was thinking:
This was just off the cuff, to add to the discussion. The primary concern was logical grouping over syntax annotations. |
If you want b to only run if a succeeds, then:
If you want the group |
@getify ok... real use case (please sign NDA here, here, and here, and submit in triplicate...) In our legacy system (that we're converting over to grunt) we have some tasks that have Soft dependencies. A specific example would be linting. Linting is very nice, and we scream loudly if you fail linting... but we don't actually Stop anything that has a soft dependency on linting. We have a couple other things that are soft dependencies, like code coverage, complexity analysis, generating docs, etc. All things that are non-Essential. Other things ARE essential. Like syntax checking, compilation, specs, etc. Sometimes, the soft deps are interspersed with the hard deps. Example: When we run our spec task, it also runs npm install, compilation, docs, linting, syntax checking.
|
wouldn't this be the same thing (unless I'm missing something)? grunt.registerTask('spec', [
'check-syntax',
'force:jshint',
'force:gilt-special-linting',
'force:complexity',
'force:groc'
'compile',
'npm-install',
'karma'
]); To put it more succinctly, I am having trouble imagining a scenario (in the real world) like:
|
@getify yes, essentially they're two ways to say the same thing. I was going with the array-grouping notation because of the proposal for additional custom syntax and concerns earlier in the thread about using 'force' as a keyword in any sense. (eg. imagine someone silly writing a starwars grunt task named 'force' -> 'force:use') We're all in agreement about the gist of the need and seemingly how it should be roughly notated. What we need now is weigh in from the people who make the decisions (@cowboy, @vladikoff) on what sits best with them. I'm good with either array grouping or making 'force:' a reserved word. I believe we are monkey-patching my proposal soonish here, and will likely submit a pull request to add to the conversation. |
@shellscape agreed, for the most part. We're inventing new "syntax" to patch a gap in functionality, not inventing a new syntax to cover every possible niche use-case. IMO the former dictates a minimal syntax for covering demonstrable/common use-cases, not a sugared syntax that is broadly capable. That's the only reason why I was urging a simpler option than the one your proposed, to see if the simpler option (usually better) covered enough of the real-world stuff and restrained itself on the theoretically "nice" stuff which won't really get much bang for the buck. |
I'm definitely not going to build-in a I am, however, very interested in a more general solution, like what @shellscape suggests, as long as we can't poke any big holes in it. |
👍 to a |
Whatever the solution here, I'd like you to consider a related, pretty important aspect: The exit code. Currently, setting the force option on tasks that support it will cause grunt to exit with a zero status code, even when one or more forced tasks had errors. My usecase is pretty simple: Run all tasks, but exit with non-zero status code if anything failed. That way I'd get the most out of Travis builds, where a trailing comma can be printed as an error in the jshint task and causes the build to fail, but it would still run the unit tests. |
fwiw we've been using the solution that @kmdavis outlined for four months now and it's been easy as all hell to use and grok, and haven't run into any negative side effects given heavy use of the construct. |
I agree with @jzaefferer, forcing the task should still make the whole process exit with code different than 0. |
@shellscape what solution are you referring to there? |
@gausie this one #810 (comment) however, we've since moved onto gulp as it made more sense for our needs. |
but isn't that comment just a recommendation for a syntax? |
I have published a grunt task which enable the force mode for a specific task: grunt-force-task. It's easy to use and doesn't need any configuration. For example At the moment I have one untested use case: Some tasks are executed parallel. |
@jzaefferer @mzgol Agreed, there needs to be an option continue build (with grouping or |
Thanks @floriangosse. Your force-task works like a champ. |
@floriangosse +1 grunt-force-task |
@floriangosse +1 grunt-force-task works great!! |
@getify @floriangosse Another +1 for grunt-force-task ... worked as expected. Found it easier to understand than the grouped arrays. Seems more explicit in its use than having force implicitly called based on array structure. |
@getify thanks for the workaround. plus one with the others. |
+1 |
1 similar comment
+1 |
I see that several plug-ins have added a force option, for example:
https://github.com/gruntjs/grunt-contrib-jshint#force
https://github.com/gruntjs/grunt-contrib-clean#force
But it would be useful to have a general-purpose way of doing this at the grunt level. Here's what I'm currently doing for a workaround:
Is there a better workaround? If not, would you consider adding a feature for this?
The text was updated successfully, but these errors were encountered: