Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

run-task

A simple cli task runner. When you would prefer to write code rather than shell scripts in package.json, but would rather not spend a lot of time learning a build tool.

Requires node v4 or newer.

Usage

run-task returns a function that takes an object as an argument. The keys are the names of tasks and the values are functions for those tasks.

  • Write some functions, then pass in the ones you want to be tasks.
// filename: run.js

const tasks = require('run-task')

function foo () {
  console.log('foo')
}

function bar () {
  console.log('bar')
}

function foobar () {
  foo()
  bar()
}

tasks({
  bar,
  foobar
})
  • Execute using node [script] [task].
$ node run foobar
  • If you use JSDoc comments, it will pick up the description. You can also add a description by attaching a description property to the function.
/**
 * This will show up as the task's description on stdout.
 */
function bar () {
  console.log('bar')
}
function bar () {
  console.log('bar')
}

bar.description = "This will show up as the task's description on stdout."
  • You can pass in more than one task.
$ node run bar foobar
  • If you don't provide a task argument, it will list the available tasks.
$ node run
[run] Available tasks:
[run] bar - This will show up as the task's description on stdout.
[run] foobar
  • You can also pass in a -q flag to silence the run-task logging.
$ node run bar -q
bar

That's it. It just runs functions from the command line. There are no assumptions on what kind of tasks you want to run.

Because of this, you'll probably want to require some other modules in your run.js script.

  • There's a lot you can get done with the core api, read the docs
  • Check out a curated list of modules at awesome-nodejs.
  • shelljs is a great tool for tasks (cross-platform *nix commands for node).

Other Suggestions

  • Take advantage of the property shorthand.
  • Name the file containing the tasks run.js so you can use: node run [task].

About

A simple task runner, for when your npm scripts get out of hand.

Resources

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.