UNPKG

3.85 kBMarkdownView Raw
1# Runna - process based task runner for Node
2
3## Features
4
5* Fast and simple.
6* NPM scripts compatible - there is no need to reinvent the wheel.
7* Process based - failure of one task does not have to bring the whole process down.
8* Watcher included - built-in consistent performant recursive watching.
9
10## Usage
11
12```
13Usage:
14 runna <chain> [options]
15
16Options:
17 -f <flavors> Enable flavors; a comma separated list.
18 -w [<path-to-watch>] Default is current.
19```
20
21## Quck start
22
23### STEP 1: Define your usual NPM scripts
24
25```json
26scripts: {
27 "clean": "rimraf ./dist",
28 "create-dist-dir": "mkdirp ./dist",
29 "build:js": "browserify ./src/index.js -o ./dist/index.js -t [ babelify --presets [ babel-preset-env ] ]",
30 "copy:html": "copyfiles --flat ./src/index.html ./dist",
31 "serve": "runna-webserver -w ./dist",
32 "serve:stop": "runna-webserver -x",
33 "serve:reload": "runna-webserver -r",
34}
35```
36
37### STEP 2: Define your build chain
38
39```json
40scripts: {
41 "build": "runna [ clean - create-dist-dir - build:js copy:html ]",
42}
43```
44
45The above `build` chain translates to:
46```
47clean | npm run clean
48- | wait for all previous scripts to complete
49create-dist-dir | npm run create-dist-dir
50- | wait for all previous scripts to complete
51build:js | npm run build:js
52copy:html | npm run copy:html
53```
54
55### STEP 3: Run your chain:
56
57```
58npm run build
59```
60
61And that's it! The `build` chain executes all scripts as background processes. Note that the `-` symbol allows to wait for all the previous scripts to complete and behaves consistently on all OSes.
62
63## Advanced usage
64
65### Interactive development mode
66
67The development mode allows triggering chain upon a file change. To enable watch mode, simply add `-w` parameter. Let's define `develop` chain like so:
68
69```json
70scripts: {
71 "develop": "runna [ +serve clean - create-dist-dir - build:js copy:html - serve:reload ] -w,
72}
73```
74
75The `+` symbol before a script name indicates, that the script should be run in the backgroud. Waiting for all previous tasks to complete with `-` igonres all background scripts automatically.
76
77Now, let's define our observe rules like so:
78
79```json
80observe: {
81 "build:js - serve:reload": [
82 "src/**/*.js"
83 ],
84 "copy:html - serve:reload": [
85 "src/**/*.html"
86 ]
87}
88```
89
90Each rule is a chain that is executed whenever a file changes that matches one of the patterns in the array. Patterns must be relative to the current working directory, or the location specified as a `-w <path_to_watch>` parameter. The watching leverages `recursive` flag of `fs.watch()`, which greatly improves the performance on Windows and OS X.
91
92## Flavours
93
94Flavours are a concept that allows reusing scripts for different sub-projects. Let's define a flavor based script like so:
95
96```json
97scripts: {
98 "build:js": "browserify ./src/$FLV/index.js -o ./dist/$FLV/index.js -t [ babelify --presets [ babel-preset-env ] ]",
99}
100```
101Note the `$FLV` placeholder - it's presence automatically enables flavor based behavior.
102
103Let's update our `develop` chain to support flavors. To do so, simply add `-f` parameter:
104```json
105scripts: {
106 "develop": "runna [ +serve clean - create-dist-dir - build:js copy:html - serve:reload ] -w -f red,blue,
107}
108```
109
110When running the above chain with `npm run develop`, the `build:js` script will be run twice, once for each flavor. Scripts that do not use `$FLV` placeholder will only run once as per usual. Think of it as of two separate scripts: `build:js::red` and `build:js::blue`.
111
112Let's update our observe rule accordingly:
113
114```json
115observe: {
116 "build:js - serve:reload": [
117 "src/$FLV/*.js"
118 ]
119}
120
121```
122
123Now, when a file changes on a path `src/blue/*.js`, the `build:js` script will be run only in the `blue` flavor. The `$FLV` placeholder will be replaced with the actual folder value.