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

v0.5.5

Published

Configuration and helpers for modular gulp tasks.

Downloads

8

Readme

Features

  • Configure base paths globally
  • Per task configuration for paths and globs
  • Separate 'main' and 'watch' files
  • Custom configuration settings
  • Dynamic configuration using npm modules and references to other setting values (uses node-expander and lodash templates)
  • Dynamic configuration using command-line flasg (uses gulp-util's env property)
  • automatically load gulp plugins (uses gulp-load-plugins)
  • Define default options for gulp plugins in separate files
  • Write your tasks as separate CommonJS modules (exports the task function)
  • Reference globs, paths and files using task-names
  • Create globs and retrieve files dynamically using task-names
  • MonkeyPatch gulp.src, gulp.watch and gulp.dest to accept task-names and use the file-globs and paths as defined in global configuration
  • Automatically load and register tasks from the tasks folder
  • Automatically watch task src files using the --watch flag

Coming Soon:

  • Multipe src => dest directory mapping
  • More stream helpers ('rename', etc.)
  • Store data in memory to use across tasks

API

Working with tasks

var wires = require('gulp-wires')([ config, options ]);

wires.getTask('task-name');
wires.getTask('task-name', fn);
wires.loadTask('task-name');
wires.loadTask('task-name', deps);
wires.loadTask('task-name', deps, fn);
wires.loadTask('task-name', fn);

When run with the '--watch' flag, gulp-wires automatically starts watching for file changes to re-run the task's function. The files that are observed are determined by the task's files.watch setting. You can disable this behaviour on a per-task basis, by setting autoWatch to false in the task's configuration hash.

Working with gulp plugins

Gulp plugins are automatically loaded using gulp-load-plugins, and plugin options can be set in separate files.

Plugin option files are loaded from the options directory, configured with the optionsPath setting. They need to share the plugin's name (without the 'gulp-'/'gulp.' prefix).

You can pass options to gulp-load-plugins with the loadPlugins setting. Please note that by default the gulp-load-plugins' camelize option is set to false.

wires.options('pluginName'[, overrides ]);
wires.plugin('pluginName'[, optionOverrides ]);

Working with files and globs

wires.glob('task-name', target);
wires.glob(['**/*.txt', 'task-name'], target);
wires.glob(['**/*.txt', '!task-name'], target);

wires.mainGlob('task-name'); // @alias wires.glob('task-name', 'main');
wires.mainGlob(['**/*.txt', 'task-name']);
wires.mainGlob(['**/*.txt', '!task-name']);

wires.main('task-name'); // @alias wires.glob('task-name', 'main');

wires.watchGlob('task-name'); // @alias wires.glob('task-name', 'watch');
wires.watchGlob(['**/*.txt', 'task-name']);
wires.watchGlob(['**/*.txt', '!task-name']);

wires.watch('task-name'); // @alias wires.glob('task-name', 'watch');

wires.files('task-name', target);
wires.mainFiles('task-name'); // @alias wires.files('task-name', 'main');
wires.watchFiles('task-name'); // @alias wires.files('task-name', 'watch');

Working with paths

wires.path('task-name', target);

wires.base('task-name'); // @alias wires.path('task-name', 'src');
wires.dest('task-name'); // @alias wires.path('task-name', 'dest');

Gulp Monkeypatching

gulp.task('task-name');
gulp.src('task-name');
gulp.src(['/**/*.txt', 'task-name']);
gulp.src(['/**/*.txt', '!task-name']);
gulp.watch('task-name');
gulp.watch(['/**/*.txt', 'task-name']);
gulp.watch(['/**/*.txt', '!task-name']);
gulp.dest('task-name');

Writing tasks

wires.util; // @alias require('gulp-util')
wires.env; // @alias require('gulp-util').env
wires.config // configuration hash, resolved and with defaults

wires.if(condition, true[, false]); // @alias require('gulpif')(condition, true, false);
wires.unless(condition, false[, true]); // @alias require('gulpif')(condition, true, false);
wires.debug(title); // prints out the files currently in the stream

coming soon:

wires.data('namespace', data);

Debugging tasks

When running your gulp tasks, you can pass the --debug flag to debug your tasks. This enables gulp-plumber and sets gulp-load-plugins's debug option to true.

Configuration

The configuration object may contain lodash templates to cross-reference settings. By default, these templates have access to node's 'path' module, and 'lodash' (referenced by the _). Additional modules can be made available via the imports setting.

As an example, here is the default configuration file, with all configuration settings available;

module.exports = {
    // modules/globals that are accessible inside lodash templates
    // inside this configuration object. Keys are the variables names
    // used to reference the modules/globals inside lodash templates.
    // Note that these defaults will always be imported. If you redefine
    // the `imports` setting below, it will merge your imports to it,
    // so that `path`, `_` and `env` are always available.
    imports: {
        'path': require('path'),
        '_': require('lodash'),
        'env': require('gulp-util').env
    },
    
    // base path for `tasksPath` and `optionsPath` settings
    // will be normalized to an absolute path
    buildPath: __dirname,
    
    // path to the tasks folder
    // relative to `buildPath`
    tasksPath: "./tasks",
    
    // path to the options folder
    // relative to `buildPath`
    optionsPath: "./options",
    
    // how task and option files are named
    // - 'kebab-case' => runs the task/plugin name through `_.kebabCase()`
    // - 'camel-case' => runs the task/plugin name through `_.camelCase()`
    // - 'snake-case' => runs the task/plugin name through `_.snakeCase()`
    // - {function} => accepts task/plugin name and returns the file name
    filename: 'kebab-case',
    
    // how to transform task and option filenames to their names as
    // referenced in config and API.
    keyname: 'kebab-case',
    
    // how task and options are named in config and API
    keyname: 'kebab-case',
    
    // activate debug mode to show warnings and notices
    debug: '<%= env.debug %>',
    
    // whether to monkey path the gulp api methods or not
    monkeyPath: true,
    
    // whether to automatically load all tasks in the tasks folder
    loadTasks: true,
    
    // options passed to 'gulp-load-plugins'
    loadPlugins: {
        debug: '<%= debug %>'
    },
    
    // default base path for tasks' source and destination directories
    // relative to `process.cwd()`
    root: {
        src: './src',
        dest: './dest',
    },
    
    // configuration settings for tasks inside the tasks folder
    // Keys are used to reference tasks in wires' API
    tasks: {}
};

Configuring Tasks

Tasks are configured via wires global tasks configuration setting. This is a hash, where each key/value pair defines a task's name/settings.

If no configuration settings are defined for a given task, it will use the following defaults:

{
    // override the root setting, used as base path for the task's
    // base and dest directories
    root: {
        src: '<%= root.src  %>',
        dest: '<%= root.dest %>'
    },
    dir: {
        src: './',
        dest: './'
    },
    files: {
        main: './**/*',
        watch: './**/*'
    },
    deps: []
}

Compact configuration:

gulp-wires defaults and normalizes task settings, so you don't have to be that prosaic when writing them:

  • No need to give a root setting, it defaults to wires' global root setting
  • The dir setting can be given as a simple string, which will be mapped to both dir.src and dir.dest
  • The files setting can be given as a simple string, which will be mapped to files.main and files.watch

This means you can write minimal task settings like these:

'my-task': {
    dir: './',
    files: './**/*.js'
},

'my-other-task': {
    files: './**/*.txt'
}

Group Tasks

Group tasks, are tasks that simply run other tasks. The only configuration setting that these tasks need is the deps setting. Therefore, they can be defined as an array of dependency tasks:

'my-group-task': ['my-task', 'my-other-task']