npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-delegate

v1.0.0

Published

Run a task (and an optional target) while using an arbitrary set of files to run checks against.

Downloads

30

Readme

grunt-delegate Build Status

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 before, be sure to check out the Getting started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

$ npm i -D grunt-delegate

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks( 'grunt-delegate' );

Configuration

There are no options for the delegate multi task 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 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.

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.

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.

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 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.

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.

Changelog

See CHANGELOG.md.


Task submitted by Thorsten Frommen.