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-command-handling

v1.0.0

Published

Enhancement for the Gulp CLI application

Downloads

17

Readme

gulp-command-handling

Node.js version gulp-command-handling

Table of contents

  1. Introduction
  2. Installation
  3. Main features
  4. Usage
  5. Example
  6. Thank you!

1. Introduction

The lightweight library is used for Gulp application. It's useful when you want to enhance the Gulp CLI with your own parameters (option, sub option, argument).

The development is using:

  • [x] Plain JavaScript ES6
  • [x] No using other library
  • [x] Simplification , effect and performance

2. Installation

$ npm install gulp-command-handling

System requirements

  • The minimum support for:
    • Node.js version is 8.17.0 (LTS version is a good choice for the stability).
    • Gulp.js version is 4.0.0 (Gulp CLI is installed on global).

3. Main features

  • Enhancement for the Gulp CLI with your own parameters (option, sub option, argument).
  • Using alias for option and sub option.
  • Command combination for many times you need.
  • Using custom regular expression (RegExp) for your reason when needed. (It applies for params validation)

Examples:

  • $ gulp build -s -m FlowerSite (Simple using)
  • $ gulp release --site --minify FlowerSite (Using alias)
  • $ gulp build --site --minify FlowerSite --move-to "/home/dev" (Combination 2 times)
  • $ gulp build -s -m -o FlowerSite -t "/home/dev" -n flowersite-v1.0.0 (Combination 3 times)

4. Usage

Command line structure

The simple command line structure is used in this library:

$ gulp <task> [-option] [-subOptions] [argument]

  • An option has only an alias and it has many sub options.
  • An alias is used as a key in the result object.
  • An argument is the end of a part in the command.

BEWARE! You should not using the options that are already using for Gulp CLI. Example: -h , -v, -f etc. Use the command gulp --help to view more about that.

Methods

| Method | Argument | Description | |---|---|---| |.setting()|Object|Custom definition (Ex: custom RegExp)| |.option()|<task>, <option>, <optionAlias>, [description]|Option definition| |.subOption()|<task>, <optionAlias>, <subOption>, <subOptionAlias>, [description]|Sub option definition| |.getOptions()||It returns an option list that is an object| |.parse()|<process.argv>|Parse the command line (Ex: process.argv.slice(2))|

You can use method chaining with the following order:

|Method|Order|Description| |---|---|---| |.setting()|First|The method must be in the first position of chaining| |.option()|Between|| |.subOption()|Between|| |.parse()|Last|The method must be in the last position of chaining|

Custom definition

Regular Express (RegExp) is used for data validation. You can redefine them for your reason when needed by using the method .setting(). The general regexps are using if you don't use your own.

It just now supports regexps for option, alias and argument validation. You should only change values of the properties: regexOption, regexAlias and regexArgument.

View the example for more detail.

5. Example

View more in the example /gulpfile.js on GitHub repo.

/* gulpfile.js */

const { Command } = require('gulp-command-handling');
const gulpCommand = new Command();

// Using custom RegExp when needed
const customSettings = {
    regexOption: false, //Default is false
    regexAlias: false,
    regexArgument: [a-z]/i,
};

// Command definition
gulpCommand
    .setting(customSettings)
    .option('build', '-s', '--site', 'Building styling for a specific site')
    .subOption('build', '--site', '-m', '--minify', 'Minify files in destination');
    .subOption('build', '--site', '-o', '--overwrite', 'Overwrite files in destination')

// Using in a Gulp task
function build(cb) {
    const result = gulpCommand.parse(process.argv.slice(2));

    if (result.site) {
        if (result.site.minify) {
            console.log('Minification task -> Done!');
        }

        if (result.site.overwrite) {
            console.log('Overwriting task -> Done!');
        }
    } else {
        console.log('Nothing to do');
    }

    cb();
}

exports.build = build;
// Running the commands for testing purpose
$ gulp build -s -m -o FlowerSite
$ gulp build --site --minify --overwrite FlowerSite

6. Thank you!

Many thanks to Commander.js for the inspiration.