https://github.com/tfrommen/grunt-delegate
Run a task (and an optional target) while using an arbitrary set of files to run checks against.
https://github.com/tfrommen/grunt-delegate
grunt-plugin
Last synced: 12 months ago
JSON representation
Run a task (and an optional target) while using an arbitrary set of files to run checks against.
- Host: GitHub
- URL: https://github.com/tfrommen/grunt-delegate
- Owner: tfrommen
- License: mit
- Created: 2016-04-09T18:03:37.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-10T09:39:31.000Z (about 10 years ago)
- Last Synced: 2025-07-12T20:15:21.584Z (12 months ago)
- Topics: grunt-plugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/grunt-delegate
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# grunt-delegate [](http://travis-ci.org/tfrommen/grunt-delegate)
> Run a task (and an optional target) while using an arbitrary set of files to run checks against.
## Getting Started
If you haven't used [Grunt](http://gruntjs.com) before, be sure to check out the [Getting started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins.
Once you're familiar with that process, you may install this plugin with this command:
```shell
$ npm i -D grunt-delegate
```
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
```js
grunt.loadNpmTasks( 'grunt-delegate' );
```
## Configuration
There are no options for the `delegate` [multi task](http://gruntjs.com/creating-tasks#multi-tasks) itself.
Each target configuration can have an optional `task` property that holds the name of another task.
If a task is specified, Grunt tries to run it (see ES6 example below).
Otherwise, Grunt tries to run a task with the name of the current target (see SASS example below).
## Usage
_Run this task with the `$ grunt delegate` command._
Task targets and files may be specified according to the Grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
The primary goal of this task is to specify a set of files (e.g., by defining a `src` property) that you can use in the context of another task.
This can be achieved by not running the `delegate` task directly, but indirectly via another task.
Not yet perfectly clear? Let's see some real world examples then...
### Examples
#### Convert `.scss` files if any of them changed since the last run
In this example, running `$ grunt changed:delegate:sass` will run the `sass` task if any `.scss` file changed since the last run.
You cannot just run `$ grunt changed:sass`, because the files specified in the `sass` task are the _root_ files only.
Thus, `grunt-changed` is unaware of changed partials or modules.
By having `grunt-changed` check the files provided by the `delegate` configuration, however, **any** changed `.scss` file (compare `resources/scss/**/*.scss` with `resources/scss/*.scss`) will cause the `sass` task to get run.
```js
grunt.initConfig( {
delegate: {
sass: {
src: [ 'resources/scss/**/*.scss' ]
}
},
sass: {
all: {
expand: true,
cwd: 'resources/scss/',
src: [ '*.scss' ],
dest: 'assets/css/',
ext: '.css'
}
}
} );
```
#### Transpile ES6 `.js` files if any of them is newer than the time of the last run
In this example, running `$ grunt newer:delegate:transpile` will run the `browserify` task with the `admin` target (see the `task` property of the according `delegate` configuration) if any `.js` file is newer than the time of the last run.
You cannot just run `$ grunt newer:browserify:admin`, because the file specified in the `browserify` task is the _main_ file only.
Thus, `grunt-newer` is unaware of newer modules or helper files.
By having `grunt-newer` check the files provided by the `delegate` configuration, however, **any** newer `.js` file (compare `resources/js/**/*.js` with `resources/js/admin.js`) will cause the `browserify` task with the `admin` target to get run.
```js
grunt.initConfig( {
delegate: {
transpile: {
src: [ 'resources/js/**/*.js' ],
task: 'browserify:admin'
}
},
browserify: {
admin: {
options: {
transform: [
[ 'babelify' ]
]
},
src: [ 'resources/js/admin.js' ],
dest: 'assets/js/admin.js'
},
vendor: {
options: {
require: [ 'jquery' ]
},
src: [],
dest: 'public/vendor.js'
},
}
} );
```
#### Test `.php` source files if any of them or one of the tests is newer than the time of the last run
In this example, running `$ grunt newer:delegate:phpunit` will run the `shell` task with the `phpunit` target (see the `task` property of the according `delegate` configuration) if any `.php` source files or tests is newer than the time of the last run.
You cannot just run `$ grunt newer:shell:phpunit`, because in the `shell` task are no files specified.
By having `grunt-newer` check the files provided by the `delegate` configuration, however, **any** newer `.php` source file or test will cause the `shell` task with the `phpunit` target to get run.
```js
grunt.initConfig( {
delegate: {
phpunit: {
src: [ 'src/**/*.php', 'tests/**/*.php' ],
task: 'shell:phpunit'
}
},
shell: {
phpunit: {
command: 'phpunit'
}
},
} );
```
#### Run an alias task when specific files changed since the last run
In this example, running `$ grunt changed:delegate:scripts` will run the `scripts` [alias task](http://gruntjs.com/creating-tasks#alias-tasks) if any `.js` source files changed since the last run.
You cannot just run `$ grunt changed:scripts`, because in the `scripts` task are no files specified.
By having `grunt-changed` check the files provided by the `delegate` configuration, however, **any** changed `.js` source file will cause the `scripts` alias task to get run.
```js
grunt.initConfig( {
delegate: {
scripts: {
src: [ 'resources/js/**/*.js' ],
task: 'scripts'
}
},
// Other task configurations here...
} );
grunt.registerTask( 'scripts', [
'eslint:src',
'shell:tape',
'browserify',
'jsvalidate:dest',
'lineending:scripts',
'uglify'
] );
```
## License
This plugin is licensed under the [MIT license](LICENSE).
## Changelog
See [CHANGELOG.md](CHANGELOG.md).
---
Task submitted by [Thorsten Frommen](https://github.com/tfrommen).