@mgutz/task
no configruation task runner
Last updated 2 years ago by mgutz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mgutz/task 
SYNC missed versions from official npm registry.

task

task is a no configuration async task runner from plain es6 files

  • .env support
  • babel out of the box
  • dependent tasks
  • respawn daemons gracefully
  • shell autocompletion
  • watch

Install

npm install -g @mgutz/task@1.0.0-alpha.10

Running Tasks

Edit Taskfile.js. Does not need to be inside a node project

export async function hello({argv}) {
  console.log(`Hello, ${argv.name}!`)
}

Run hello task from terminal with a name

task hello --name world

Each task receives context with packages already used by task

prop desc
_ lodash
argv minimist
contrib contrib functions {shawn}
event Watch event
glob globby
sh shelljs

Export Meta for More Options

export function build() {}
export function clean() {}
export function generate() {}

export default {
  build: {desc: 'builds project', deps: [clean, generate]},
}

Alternatively,

export default {
  build: {desc: 'builds project', run: () => {}, deps: ['clean', 'generate']},
  clean: {desc: 'cleans project', run: () => {}},
  generate: {desc: 'generates code', run: () => {}},
}

Metadata props

prop desc
deps Functions which must run before task
desc Description to display in task list
once Task must only run once
run The function to run. May be ignored if key is exported function name
watch Glob patterns to watch

Set a Default Task

export default build

Or create a pseudo-task named default

export default {
  default: {deps: [build]},
}

Watch Tasks

Watching requires defining glob patterns for a task

export default {
  build: {
    watch: ['src/**/*.js'],
  },
}

Run a task in watch mode with --watch, -w flag

task build -w

NOTE: task can gracefully restart a process (and subprocesses) if a task returns a ChildProcess. task provides contrib.shawn to run a literal script and return a ChildProcess

To properly restart a go http server listening on a port whenever a go file changes

export function server({contrib}) {
  return contrib.shawn(`
    cd cmd/server
    go install
    server
  `)
}

export default {
  server: {watch: ['server/**/*.go']},
}
task server -w

Running Multiple Tasks

task only runs a single task to be consistent with args. To run multiple tasks, call them directly within a task or add tasks to deps prop.

contrib.shawn

shawn is short for shell spawn. shawn executes /bin/bash -c [script] by default. The shell and arguments can be overriden

export function server({contrib}) {
  // shawn accepts any child_process.spawn option
  return contrib.shawn(`node index.js`, {
    shell: '/bin/bash',
    shellArgs: ['-c'],
    env: process.env,
  })
}

Auto Completion

Shell auto completion requires editing your shell's rc files. The easiest solution is by running

task --setup-completion

If you want more control, read omelette to manually integrate autocompletion.

LICENSE

MIT

Current Tags

  • 1.0.0-alpha.11                                ...           latest (2 years ago)
  • 1.0.7-alpha.0                                ...           matcherino (5 months ago)
  • 1.0.0-alpha.24                                ...           next (2 years ago)

21 Versions

  • 1.0.7-alpha.0                                ...           5 months ago
  • 1.0.6-alpha.0                                ...           8 months ago
  • 1.0.5-alpha.0                                ...           8 months ago
  • 1.0.4-alpha.0                                ...           8 months ago
  • 1.0.3-alpha.0                                ...           8 months ago
  • 1.0.2-alpha.0                                ...           8 months ago
  • 1.0.1-alpha.0                                ...           8 months ago
  • 1.0.0-alpha.24                                ...           2 years ago
  • 1.0.0-alpha.23                                ...           2 years ago
  • 1.0.0-alpha.20                                ...           2 years ago
  • 1.0.0-alpha.19                                ...           2 years ago
  • 1.0.0-alpha.18                                ...           2 years ago
  • 1.0.0-alpha.17                                ...           2 years ago
  • 1.0.0-alpha.16                                ...           2 years ago
  • 1.0.0-alpha.15                                ...           2 years ago
  • 1.0.0-alpha.14                                ...           2 years ago
  • 1.0.0-alpha.13                                ...           2 years ago
  • 1.0.0-alpha.12                                ...           2 years ago
  • 1.0.0-alpha.11                                ...           2 years ago
  • 1.0.0-alpha.10                                ...           2 years ago
  • 1.0.0-alpha.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 1
This Week 4
This Month 6
Last Day 0
Last Week 1
Last Month 25
Dependencies (14)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |