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

v0.0.6

Published

Gulp submodules with namespaces and direct execution support.

Downloads

41

Readme

gulp-module

Gulp support for submodules with namespaces and direct submodule execution.

Installation

npm install --save-dev gulp-module

IMPORTANT: gulp-module needs to be installed locally for each module.

Example project structure

project/ -
  gulpfile.js
  (...)
  module/ -
    gulpfile.js
    (...)

Module definition

module.exports = require('gulp-module').define('moduleName', function (gulp, runSequence) {
  // Regular gulpfile here.
  // Do not re-import gulp or runSequence, use the arguments instead.
  // Use regular task names, e.g. default, build, coffee.
};

Returns: {String} module name (namespace).

Task namespacing

All tasks are being automatically namespaced with the module name. E.g. task build becomes moduleName:build.

Importing modules

Modules can be imported in parent gulpfiles using the gulpModule.load to load a specific gulpfile.js or gulpModule.loadAll to recursively load all modules in a specific directory. Both need to be passed a reference to the parent's gulp instance.

var gulp = require('gulp'),
  gulpModule = require('gulp-module');

gulpModule.loadAll('modules', gulp);
// or
gulpModule.load('modules/desktop/gulpfile.js', gulp);

Then, tasks can be introduced in the parent's tasks as dependencies or in runSequence calls.

Getting submodule task names

Tasks from within the submodules are namespaced with the module name and the separator between the namespace and the task name being a :.

However, it is safer to query a child task using the provided gulpModule.tasks function.

The gulpModule.tasks function also provides a minimatch filter so you can even query a group of all loaded tasks.

E.g.

gulpModule.tasks('build', 'desktop');  // returns ['desktop:build']
gulpModule.tasks('clean', '*');  // returns clean task in all loaded namespaces, e.g. ['desktop:clean', 'mobile:clean']
gulpModule.tasks(['coffee', 'sass'], 'mobile');  // returns ['mobile:coffee', 'mobile:sass']

Direct module execution

Modules can be still executed directly with gulp. E.g.

$ cd project/module
gulp module:build

When executed directly, gulp-module adds a non-namespaced default task so you can still run a module with simply gulp. All other tasks need to be run with a correct namespace, i.e. a defined clean task becomes moduleName:clean no matter if the module is run directly or if it is imported.

Example module definition

I.e. project/module/gulpfile.js above.

module.exports = require('gulp-module').define('module', function (gulp, runSequence) {

  gulp.task('coffee', function () {
    // Becomes 'module:coffe'
  });

  gulp.task('compass', function () {
    // Becomes 'module:compass'
  });

  gulp.task('test', function () {
    // Becomes 'module:test'
  });

  gulp.task('build', function (cb) {
    // Becomes 'module:build'
    // runSequence can still use non-namespaced tasks within module definition
    // and will namespace them automatically at runtime.
    runSequence('clean', ['coffee', 'compass'], 'test', cb);
  });

  gulp.task('default', ['build']);  // Becomes 'module:default'.
  // In direct execution additional task 'default' is defined that runs a
  // 'module:default' task as a dependency.

};

License

MIT