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

gulp-simple-task-loader

v1.3.11

Published

A simple task loader for gulp

Downloads

151

Readme

Gulp Simple Task Loader

NPM

npm version Coverage Status Build Status Dependency Status Codacy Badge

Pull Requests Status Issues Status

Easily modularize gulp tasks and minify your gulpfile. Works well with gulp-load-plugins.

$ npm install gulp-simple-task-loader --save-dev

To test this package clone it and run the following commands:

$ npm install
$ npm test
var taskLoader = require('gulp-simple-task-loader');
taskLoader(options);

This will load and register tasks for all files defined in your taskDirectory.

If your tasks aren't registering (they are, but to the wrong gulp package) you can optionally specify a gulp to register the tasks to.

var gulp = require('gulp');
var taskLoader = require('gulp-simple-task-loader');
taskLoader(options, gulp);

You can pass in an options object as shown below. The values shown below are the defaults.

taskLoader({
  taskDirectory: 'gulp-tasks', // the directory your tasks are stored in (relative and absolute paths accepted)
  plugins: {},                 // the plugins to expose to your tasks
  filenameDelimiter: '',       // a character or string of characters to replace in task filenames
  tasknameDelimiter: '',       // a character or string of characters to insert in place of removed filenameDelimiter
  config: {},                  // an object to store configuration for use in tasks
  configFile: ''               // the relative path to your task configuration file from your task directory
});

Only put gulp tasks in your taskDirectory. All .js files in this directory, unless the configFile option is being used, will be attempted to be read as gulp tasks. Nested directories are supported as of v1.0.29.

The purpose of the delimiters is to allow flexibility in task naming. A common convention for task names is to delimit using the : character, however :'s are not generally used or allowed in file names. A common usage of the delimiters is as follows:

taskLoader({
  filenameDelimiter: '-',
  tasknameDelimiter: ':'
});

These options would convert a filename such as move-all.js to a task with the name move:all.

You can use gulp-load-plugins to easily lazy-load your gulp plugins. Use gulp-load-plugins in conjunction with gulp-simple-task-loader to minimize your gulpfile.

'use strict';

var taskLoader = require('gulp-simple-task-loader');
var plugins = require('gulp-load-plugins')();

taskLoader({ plugins: plugins });

If not using gulp-load-plugins you must specify which plugins you want made available to your tasks.

(gulpfile.js)
'use strict';

var taskLoader = require('gulp-simple-task-loader');
var plugins = {
  bump: require('gulp-bump'),
  mocha: require('gulp-mocha')
};

taskLoader({ plugins: plugins });

You have the option of passing in the location of a configuration file from within your task directory. Please note that the configuration file takes precedence over the config option that you may also pass in, meaning that any key in config is overwritten if the same key exists in the config file.

(gulpfile.js)
'use strict';

var taskLoader = require('gulp-simple-task-loader');
var config = { env: 'production' };

taskLoader({ config: config, configFile: 'config.js' });
(config.js)
'use strict';

module.exports = {
  // insert configuration options here
};

All tasks should be functions that receive the parameters gulp, config, and plugins.

There are 2 ways to structure a task -- returning a function that executes the task, or returning an object that contains dependencies, parameters, and the function that executes the task.

This is a typical function as you are used to with gulp.

'use strict';

module.exports = function(gulp, config, plugins) {
  return function([callback]) {}; // the task functionality -- callback optional
};

All 3 object keys (deps, params, and fn) are optional. This allows you to create a task that strictly calls other tasks, a task that is parameterized, or a task that just acts like a normal task.

If there are no dependencies or parameters for the task you can use the above "Basic task" format for creating a basic task.

The values shown below are the defaults.

'use strict';

module.exports = function(gulp, config, plugins) {
  return {
    deps: [],                   // an array of task names to execute before this task
    params: [],                 // an array of parameters to send to `fn`
    fn: function([callback]) {} // the task functionality -- callback optional
  };
};

Please note that if you use the params key your fn must be of the following form:

params: [ 'a', 'b' ],
fn: function(param, cb) {} // where param is an item from the params array,
                           // and cb is a callback to be called at the end of your function
(gulpfile.js)

'use strict';

var taskLoader = require('gulp-simple-task-loader');
var plugins = require('gulp-load-plugins');

taskLoader({
  filenameDelimiter: '-',
  tasknameDelimiter: ':',
  plugins: plugins
});
(tasks/lint-all.js)

'use strict';

module.exports = function(gulp, config, plugins) {
  return {
    deps: [ 'lint:client', 'lint:server' ]
  };
};
(tasks/lint-client.js)

'use strict';

module.exports = function(gulp, config, plugins) {
  return function() {
    return gulp.src('./client/**/*.js')
      .pipe(plugins.jshint);
  };
};
(tasks/lint-server.js)

'use strict';

module.exports = function(gulp, config, plugins) {
  return function() {
    return gulp.src('./server/**/*.js')
      .pipe(plugins.jshint);
  };
};
(gulpfile.js)

'use strict';

var taskLoader = require('gulp-simple-task-loader');
var plugins = require('gulp-load-plugins');

taskLoader({
  filenameDelimiter: '-',
  tasknameDelimiter: ':',
  plugins: plugins
});
(tasks/parameterized.js)

'use strict';

module.exports = function(gulp, config, plugins) {
  return {
    params: [ '1', '2' ],
    fn: function(param, cb) {
      console.log(param);
      cb();  // note that the callback must be called in order for the task
             // to finish iterating through your params array
    }
  };
};

The task in parameterized.js would produce the following output:

1
2

Documented below are any significant changes to the package.

  • 1.x.x
    • 1.3.x
      • 1.3.0 - added feature for passing in configuration file github issue #6; restructured test suite to section out functionality
    • 1.2.x
      • 1.2.4 - added table of contents and changelog to README.md
      • 1.2.1 - added testing for plugins and config options
      • 1.2.0 - restructured package to be more modular
    • 1.1.x
      • 1.1.6 - added documentation for testing the package
      • 1.1.4 - improved documentation for parameterized tasks
      • 1.1.0 - added functionality to parameterize tasks - github issue #9
    • 1.0.x
      • 1.0.35 - added support for coffeescript - @chafnan
      • 1.0.33 - fixed github issue #8
      • 1.0.29 - added functionality to allow for recursive directory task searching
      • 1.0.17 - added documentation for calling the plugin; added documentation for complete examples
      • 1.0.16 - created README.md
      • 1.0.15 - added dependency support for tasks
      • 1.0.14 - implemented first set of tests