dullard

Let the computers do the boring stuff.

npm install dullard
2 downloads in the last day
19 downloads in the last week
81 downloads in the last month

Dullard

Build Status NPM version Dependency Status devDependency Status

"I have made this longer than usual because I have not had time to make it shorter." - Blaise Pascal

Dullard is a simple NodeJS-powered task runner. It exists because doing the same thing repeatedly is boring. Much better to let the computer do it instead.

Table of Contents

Usage

>dullard --help
dullard v0.4.3
    Let the computers do the boring stuff.

Usage: dullard -d <dir>,...,<dirN> <step1> ... <stepN>

Options:
  --help, -?     Show usage
  --dirs, -d     directories to load task files from
  --list, -l     List available tasks
  --quiet, -q    Minimal output
  --verbose, -v  Verbose logging
  --loglevel     Chattiness, one of: silly, verbose, info, warn, error, & silent  [default: "info"]
  --silent       No output until something goes awry

Config

Dullard will look for a file named .dullfile in the current directory or any parent directories & merge it with the CLI options. It will merge all found results in the current branch of the directory tree with precedence being: CLI > Local > Parent > ... > Root.

Example Config

JSON version

{
    "dirs" : [
        "../../../tasks-a"
    ],

    "steps" : [
        "fooga"
    ]
}

JS version

/*jshint node:true */
"use strict";

module.exports = {
    "dirs" : [
        "../../tasks-a"
    ],

    "steps" : {
        main : [
            "fooga"
        ],

        finish : [
            "wooga"
        ],

        default : [
            "main",
            "finish"
        ]
    }
};

dirs is an array of directories to load tasks from. steps is one of two options: 1) an array of strings/functions or 2) an object containing named step collections that are each an array of strings/functions. Strings should match either the names of files in the task directories stripped of their extension or the name of a step collection.

The config object will be passed as the first argument (config by convention) to tasks.

Customizing Config Values

Dullard tries hard to accept whatever & turn it into something useful. To this end the results of parsing the CLI with optimist are merged into the config object after all the .dullfiles. This allows you to run builds with environment-specific settings easily, as you can override any settings via CLI args.

For example, given the following .dullfile and CLI args

{
    "env" : "dev",
    ...
}

invoking dullard using the command dullard --env=live will set the env value to "live" instead of "dev".

Thanks to optimist's ability to handle dot-notation for arguments you can also set nested object arguments.

dullard --env=live --cdn.static=http://www.cdn.com with the same .dullfile as above gives you a config object like this

{
    "env" : "dev",
    "cdn" : {
        "static" : "http://www.cdn.com"
    }
    ...
}

Warning

This only works for values that are not one of Dullard's CLI options.

Tasks

Tasks are simple modules that should export a single function. Each task function gets passed two arguments, a shared config object for state in the task chain & an optional callback for async tasks. The callback takes two possible arguments, an error object and an optional object to replace the shared config object. If the task is synchronous any return value will be considered an error.

// Passing tasks
function exampleTaskSync(config) {
    ...
}

function exampleTaskAsync(config, done) {
    ...

    process.nextTick(done);
}

// Failing tasks
function exampleTaskFailureSync(config) {
    return "Task failed";
}

function exampleTaskFailureAsync(config, done) {
    done("Task Failed");
}

Logging in a task

Dullard makes a log function available to tasks via config.log, this is a reference to npmlog.log() and you may use it accordingly. It respects loglevel values passed via the CLI, either via --loglevel=<level> or the shorthand --verbose argument.

Install

  1. npm i -g dullard

Develop

  1. git clone git://github.com/tivac/dullard.git
  2. npm i
  3. Make changes
  4. npm test

FAQ

Q: What about file watching?

A: Nothing built-in yet, still trying to figure out if I'm comfortable with cluttering up the .dullfile(s) with watcher config stuff. For now check out this gist.

npm loves you