Skip to content

Commit

Permalink
Realizing that "basic" tasks were poorly named, I have changed the na…
Browse files Browse the repository at this point in the history
…me to "multi" tasks. You'll thank me later.
  • Loading branch information
cowboy committed Mar 12, 2012
1 parent 697020b commit a0dfb40
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ config.init({
});
```

_Note: you can run all targets of any [basic task](tasks_builtin.md) by just specifying the name of the task. In this case, running `grunt lint` would automatically run the `all` target and any others that might exist under `lint`._
_Note: you can run all targets of any [multi task](tasks_builtin.md) by just specifying the name of the task. In this case, running `grunt lint` would automatically run the `all` target and any others that might exist under `lint`._

In another example, this very simple configuration saved in the root of a [jQuery repository](https://github.com/jquery/jquery) clone allows the jQuery QUnit unit tests to be run via grunt with `grunt qunit:index`.

Expand Down
8 changes: 4 additions & 4 deletions docs/task_concat.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Concatenate one or more input files (and/or [directives](helpers_directives.md)

## About

This task is a [basic task](tasks_creating.md), meaning that grunt will automatically iterate over all `concat` targets if no specific target is specified.
This task is a [multi task](tasks_creating.md), meaning that grunt will automatically iterate over all `concat` targets if no specific target is specified.

For more information on general configuration options, see the [configuring grunt](configuring.md) page.

## Usage examples

### Concatenating multiple files

In this example, `grunt concat:dist` (or `grunt concat` because it's a [basic task](tasks_creating.md)) will simply concatenate three source files, in order, writing the output to `dist/built.js`.
In this example, `grunt concat:dist` (or `grunt concat` because it's a [multi task](tasks_creating.md)) will simply concatenate three source files, in order, writing the output to `dist/built.js`.

```javascript
/*global config:true, task:true*/
Expand All @@ -29,7 +29,7 @@ config.init({

### Banner comments

In this example, `grunt concat:dist` (or `grunt concat` because it's a [basic task](tasks_creating.md)) will first strip any pre-existing banner comment from the `src/project.js` file, then concatenate that with a newly-generated banner comment, writing the output to `dist/built.js`.
In this example, `grunt concat:dist` (or `grunt concat` because it's a [multi task](tasks_creating.md)) will first strip any pre-existing banner comment from the `src/project.js` file, then concatenate that with a newly-generated banner comment, writing the output to `dist/built.js`.

This generated banner will be the contents of the `meta.banner` underscore template string interpolated (in this case) with values imported from the `package.json` file (which are available via the `pkg` config property) plus today's date.

Expand All @@ -55,7 +55,7 @@ config.init({

In this example, `grunt concat` will build two separate files. One "basic" version, with the main file essentially just copied to `dist/basic.js`, and another "with_extras" concatenated version written to `dist/with_extras.js`.

While each concat target can be built individually by running `grunt concat:basic` or `grunt concat:extras`, running `grunt concat` will build all concat targets. This is because concat is a [basic task](tasks_creating.md).
While each concat target can be built individually by running `grunt concat:basic` or `grunt concat:extras`, running `grunt concat` will build all concat targets. This is because concat is a [multi task](tasks_creating.md).

```javascript
/*global config:true, task:true*/
Expand Down
4 changes: 2 additions & 2 deletions docs/task_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Validate one or more input files with JSHint.

## About

This task is a [basic task](tasks_creating.md), meaning that grunt will automatically iterate over all `lint` targets if no specific target is specified.
This task is a [multi task](tasks_creating.md), meaning that grunt will automatically iterate over all `lint` targets if no specific target is specified.

For more information on general configuration options, see the [configuring grunt](configuring.md) page.

Expand Down Expand Up @@ -37,7 +37,7 @@ config.init({

### Linting before and after concat

In this example, `grunt lint` will lint two separate sets of files using the default JSHint `options` and `globals`, one "beforeconcat" set, and one "afterconcat" set. Running `grunt lint` will lint both sets of files all at once, because lint is a [basic task](tasks_creating.md). This is not ideal, because `dist/output.js` might get linted before it gets created!
In this example, `grunt lint` will lint two separate sets of files using the default JSHint `options` and `globals`, one "beforeconcat" set, and one "afterconcat" set. Running `grunt lint` will lint both sets of files all at once, because lint is a [multi task](tasks_creating.md). This is not ideal, because `dist/output.js` might get linted before it gets created!

You really need to lint the "beforeconcat" set first, then concat, then lint the "afterconcat" set, by doing `grunt lint:beforeconcat concat lint:afterconcat`.

Expand Down
2 changes: 1 addition & 1 deletion docs/task_qunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Run [QUnit][qunit] unit tests in a headless [PhantomJS][phantom] instance.

## About

This task is a [basic task](tasks_creating.md), meaning that grunt will automatically iterate over all `qunit` targets if no specific target is specified.
This task is a [multi task](tasks_creating.md), meaning that grunt will automatically iterate over all `qunit` targets if no specific target is specified.

For more information on general configuration options, see the [configuring grunt](configuring.md) page.

Expand Down
12 changes: 6 additions & 6 deletions docs/tasks_creating.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ task.registerTask('default', 'lint qunit concat min');

_In case it's not obvious, defining a `default` task is helpful because it runs by default, whenever you run `grunt` without explicitly specifying tasks._

## Basic tasks
A basic task is a task that implicitly iterates over all of its targets if no target is specified. For example, in the following, while `grunt lint:test` or `grunt lint:lib` will lint only those specific sets of files, `grunt lint` will automatically run the `test`, `lib` and `grunt` targets for you. It's super convenient.
## Multi tasks
A multi task is a task that implicitly iterates over all of its targets if no target is specified. For example, in the following, while `grunt lint:test` or `grunt lint:lib` will lint only those specific sets of files, `grunt lint` will automatically run the `test`, `lib` and `grunt` targets for you. It's super convenient.

_Note: basic tasks will ignore any config sub-properties beginning with `_` (underscore)._
_Note: multi tasks will ignore any config sub-properties beginning with `_` (underscore)._

```javascript
/*global config:true, task:true*/
Expand All @@ -46,7 +46,7 @@ config.init({
});
```

While it's probably most useful for you to check out the JavaScript source of the [built-in tasks](https://github.com/cowboy/grunt/tree/master/tasks), this example shows how you might define your own Basic task:
While it's probably most useful for you to check out the JavaScript source of the [built-in tasks](https://github.com/cowboy/grunt/tree/master/tasks), this example shows how you might define your own multi task:

```javascript
/*global config:true, task:true*/
Expand All @@ -58,7 +58,7 @@ config.init({
}
});

task.registerBasicTask('logstuff', 'This task logs stuff.', function(target) {
task.registerMultiTask('logstuff', 'This task logs stuff.', function(target) {
// target === the name of the target
// this.data === the target's value in the config object
// this.name === the task name
Expand Down Expand Up @@ -120,7 +120,7 @@ Aborted due to warnings.
```

## Custom tasks
You can go crazy with tasks. They don't have to be basic. If your tasks don't follow the "basic task" structure, use a custom task.
You can go crazy with tasks. If your tasks don't follow the "multi task" structure, use a custom task.

```javascript
task.registerTask('default', 'My "default" task description.', function() {
Expand Down
4 changes: 2 additions & 2 deletions lib/grunt/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var opts = Object.keys(optlist).map(function(long) {
var tasks = Object.keys(task._tasks).map(function(name) {
col1len = Math.max(col1len, name.length);
var info = task._tasks[name].info;
if (task._tasks[name].basic) {
if (task._tasks[name].multi) {
info += ' *';
}
return [name, info];
Expand All @@ -47,7 +47,7 @@ tasks.forEach(function(a) { log.writetableln(widths, ['', utils._.pad(a[0], col1
log.writeln().writelns(
'Tasks run in the order specified. Arguments may be passed to tasks that ' +
'accept them by using semicolons, like "lint:files". Tasks marked with * ' +
'are "basic tasks" and will iterate over all sub-targets if no argument is ' +
'are "multi tasks" and will iterate over all sub-targets if no argument is ' +
'specified.' +
'\n\n' +
'The list of available tasks may change based on tasks directories or ' +
Expand Down
10 changes: 5 additions & 5 deletions lib/grunt/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ exports.registerTask = function(name, info, fn) {
this.extraspaths = file.taskpaths.bind(file, this.name);
// Initialize the errorcount for this task.
errorcount = fail.errorcount;
// If this task was an alias or a basic task called without a target,
// If this task was an alias or a multi task called without a target,
// only log if in verbose mode.
var logger = _fn.alias || (task.basic && (!arg || arg === '*')) ? verbose : log;
var logger = _fn.alias || (task.multi && (!arg || arg === '*')) ? verbose : log;
// Actually log.
logger.header('Running "' + this.nameArgs + '"' +
(this.name !== this.nameArgs ? ' (' + this.name + ')' : '') + ' task');
Expand All @@ -50,8 +50,8 @@ exports.registerTask = function(name, info, fn) {
return this;
};

// This is the most common "basic task" pattern.
exports.registerBasicTask = function(name, info, fn) {
// This is the most common "multi task" pattern.
exports.registerMultiTask = function(name, info, fn) {
exports.registerTask(name, info, function(target) {
// If a target wasn't specified, run this task once for each target.
if (!target || target === '*') {
Expand Down Expand Up @@ -88,7 +88,7 @@ exports.registerBasicTask = function(name, info, fn) {
// Call original task function, passing in the target and any other args.
return fn.apply(this, arguments);
});
this._tasks[name].basic = true;
this._tasks[name].multi = true;
};

// Init tasks don't require properties in config, and as such will preempt
Expand Down
2 changes: 1 addition & 1 deletion tasks/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// TASKS
// ============================================================================

task.registerBasicTask('concat', 'Concatenate files.', function(target) {
task.registerMultiTask('concat', 'Concatenate files.', function(target) {
// Concat specified files.
var files = file.expand(this.file.src);
file.write(this.file.dest, task.helper('concat', files));
Expand Down
2 changes: 1 addition & 1 deletion tasks/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var jshint = require('jshint').JSHINT;
// TASKS
// ============================================================================

task.registerBasicTask('lint', 'Validate files with JSHint.', function(target) {
task.registerMultiTask('lint', 'Validate files with JSHint.', function(target) {
// Get flags and globals, allowing target-specific options and globals to
// override the default options and globals.
var options, globals, tmp;
Expand Down
2 changes: 1 addition & 1 deletion tasks/min.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var gzip = require('gzip-js');
// TASKS
// ============================================================================

task.registerBasicTask('min', 'Minify files with UglifyJS.', function(target) {
task.registerMultiTask('min', 'Minify files with UglifyJS.', function(target) {
var files = file.expand(this.file.src);
// Get banner, if specified. It would be nice if UglifyJS supported ignoring
// all comments matching a certain pattern, like /*!...*/, but it doesn't.
Expand Down
2 changes: 1 addition & 1 deletion tasks/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var phantomHandlers = {
// TASKS
// ============================================================================

task.registerBasicTask('qunit', 'Run QUnit unit tests in a headless PhantomJS instance.', function(target) {
task.registerMultiTask('qunit', 'Run QUnit unit tests in a headless PhantomJS instance.', function(target) {
// Get files as URLs.
var urls = file.expandToUrls(this.file.src);

Expand Down
2 changes: 1 addition & 1 deletion tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ nodeunit.reporters.grunt = {
// TASKS
// ============================================================================

task.registerBasicTask('test', 'Run unit tests with nodeunit.', function(target) {
task.registerMultiTask('test', 'Run unit tests with nodeunit.', function(target) {
// File paths.
var filepaths = file.expand(this.file.src);
// Clear all tests' cached require data, in case this task is run inside a
Expand Down

0 comments on commit a0dfb40

Please sign in to comment.