0.10.0 • Published 5 years ago

taskfile v0.10.0

Weekly downloads
6
License
GPL-3.0
Repository
github
Last release
5 years ago

Taskfile

npm i taskfile --save-dev Yet another attempt at a simple task runner for npm with parallelisation support using bash commands via YAML. Based on the Taskfile article by Adrian Cooney.

Travis   Coveralls   npm   License MIT

  • Specify pure Bash commands in YAML
  • Run tasks concurrently and consecutively
  • Compatible with Windows based systems
  • Filter by NODE_ENV and os.platform() conditionals
  • Avoid wrapper bloat such as with Gulp
  • Automatic help page with taskfile help
  • Choice of tasks with taskfile
  • Use npm run [task] commands as usual

Getting Started

By creating a file named .taskfile.yml in your project's root directory, you're able to define the various tasks that Taskfile will respond to.

- name: build
  tasks:
    - webpack
    - - prepend bin/index.js '#!/usr/bin/env node\n\n'

- name: test
  tasks:
    - nyc ava
    - - nyc report --reporter=html

We have setup two tasks: taskfile build and taskfile test that will run through their associated tasks consecutively we also get taskfile which will present users with a list of available tasks.

Taskfile should not be installed globally, and as such you're encouraged to place the tasks in your package.json.

{
    "scripts": {
      "build": "taskfile build",
      "test": "taskfile test"
    }
}

We've specified the tasks consecutively in the .taskfile.yml file by utilising nested arrays, however we could quite easily set the tasks up concurrently if each tasks doesn't depend on the finishing of the previous. For instance, we could augment our test task to spec and lint at the same time.

- name: test
  tasks:
    - xo **/*.js
    - nyc ava
    - - nyc report --reporter=html

Using the above approach our xo and nyc tasks run concurrently, and once the nyc task finishes, it produces a HTML report of test coverage.

Conditional Tasks

It's a common requirement to be able to run tasks conditionally based on an environment variable. With Taskfile we have a simple implementation using the env key which is validated against the current NODE_ENV value.

- name: build
  env: development
  task: webpack -d
  
- name: build
  env: production
  task: webpack -p

Note: We're using task as a more semantic way to run a single task.

Using the above configuration Taskfile will run the relevant task based on the NODE_ENV value. However you're also able to set a default for if NODE_ENV is empty by omitting the env entirely if there is a more specific task that matches the NODE_ENV then that will be preferred over the default that doesn't specify an env.

- name: build
  task: webpack
  
- name: build
  env: development
  task: webpack -d
  
- name: build
  env: production
  task: webpack -p

In cases where the NODE_ENV is empty, the third task will be preferred. However if NODE_ENV is either development or production then the more specific tasks those with env defined will be chosen rather than the default irrespective of the ordering of the tasks.

Taskfile also supports filtering tasks by the platform you're on we use the Node.js os module's list to filter. You can specify the platform by using the os option:

- name: build
  os: darwin
  task: webpack

In the above the build task will only be available on darwin (MacOS) platforms. If you specify both env and os then the conditional has greater priority than just specifying one of them. For instance in the below case, the second build would take precendence because it matches more conditions than the first one when NODE_ENV=development and os.platform() === 'darwin':

- name: build
  os: darwin
  task: webpack

- name: build
  os: darwin
  env: development
  task: webpack

It's worth noting that the os field also accepts a list of platforms to match against, such as:

- name: build
  os:
    - freebsd
    - openbsd
  env: development
  task: webpack

Task Enumeration

By executing the taskfile command from the terminal all tasks in the .taskfile.yml file will be enumerated, and runnable using the arrow keys followed by enter. In some cases however you may wish to omit tasks from the enumeration, which you can do by specifying the hide key in the configuration.

- name: test
  tasks:
    - taskfile spec
    - taskfile lint
  
- name: spec
  hide: true
  task: nyc ava
  
- name: lint
  hide: true
  task: xo **/*.js

Both spec and lint will be hidden from the enumeration, although still runnable with taskfile spec and taskfile lint respectively.

0.10.0

5 years ago

0.9.0

5 years ago

0.8.5

6 years ago

0.8.4

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.17

6 years ago

0.5.16

6 years ago

0.5.15

6 years ago

0.5.14

6 years ago

0.5.13

6 years ago

0.5.12

6 years ago

0.5.11

7 years ago

0.5.10

7 years ago

0.5.9

7 years ago

0.5.8

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago