tasksfile
Minimalistic building tool
From version >= 5 RunJS was renamed to Tasksfile. Link to RunJS version: https://github.com/pawelgalazka/runjs/tree/runjs
Get started
Install tasksfile in your project
npm install tasksfile --save-dev
Create tasksfile.js
in your root project directory:
const sh cli = { console} { }
Create task
entry in your scripts
section in package.json
:
Call in your terminal through npm scripts:
$ npm run task -- hello Tommy$ npm run task -- makedir$ yarn task hello Tommy$ yarn task makedir
or through shorter npx task
alias:
$ npx task hello TommyHello Tommy!$ npx task makedirmkdir somedir
Why tasksfile ?
We have Grunt, Gulp, npm scripts, Makefile. Why another building tool ?
Gulp or Grunt files seem overly complex for what they do and the plugin ecosystem adds a layer of complexity towards the simple command line tools underneath. The documentation is not always up to date and the plugin does not always use the latest version of the tool. After a while customizing the process even with simple things, reconfiguring it becomes time consuming.
Npm scripts are simple but they get out of hand pretty quickly if we need more complex process which make them quite hard to read and manage.
Makefiles are simple, better for more complex processes
but they depend on bash scripting. Within tasksfile
you can use
command line calls as well as JavaScript code and npm
libraries which makes that approach much more flexible.
Features
Executing shell commands
Tasksfile gives an easy way to execute shell commands in your tasks by sh
function
in synchronous and asynchronous way:
const sh cli = { }
$ npx task command
Because ./node_modules/.bin
is included in PATH
when calling shell commands
by sh
function, you can call "bins" from your local project in the same way as
in npm scripts.
Handling arguments
Provided arguments in the command line are passed to the function:
{ console}
$ npx task sayHello worldHello world!
You can also provide dash arguments like -a
or --test
. Order of them doesn't
matter after task name. They will be always available by options
helper
from inside a function.
{ console console}
$ npx task sayHello -a --test=something worldHello world!Given options:
Documenting tasks
To display all available tasks for your tasksfile.js
type task
in your command line
without any arguments:
$ npx task --help
Commands:
echo - echo task description
buildjs - Compile JS files
Use help
utility function for your task to get additional description:
const cli help = { }
$ npx task buildjs --help
Usage: buildjs
Compile JS files
You can provide detailed annotation to give even more info about the task:
const dedent = const sh help = { }
$ npx task test --help
Usage: test [options] [file]
Run unit tests
Options:
--watch run tests in a watch mode
Examples:
task test dummyComponent.js
task test dummyComponent.js --watch
Namespacing
To better organise tasks, it is possible to call them from namespaces:
const test = { console }
$ npx task test:unitDoing unit testing!
This is especially useful if tasksfile.js
gets too large. We can move some tasks
to external modules and import them back to a namespace:
./tasks/test.js
:
{ console} { console} { } moduleexports = unit integration default
tasksfile.js
const test =
$ npx task test:unitDoing unit testing! $ npx task testDoing unit testing!Doing integration testing!
If we don't want to put imported tasks into a namespace, we can always use spread operator:
$ npx task unitDoing unit testing!
With ES6 modules import/export syntax this becomes even simpler:
// export with no namespace // export with namespace
$ npx task unit$ npx task test:unit
Sharing tasks
Because tasksfile.js
is just a node.js module and tasksfile
just calls exported
functions from that module based on cli arguments, nothing stops you to move
some repetitive tasks across your projects to external npm package and
just reuse it.
shared-tasksfile
module:
{ console} { console} moduleexports = shared1 shared2
Local tasksfile.js
const shared = { console}
$ npx task shared1$ npx task shared2$ npx task local
TypeScript support
It's very easy to run your tasks in TypeScript
if you have TypeScript
already
in your project. Just:
- change your
tasksfile.js
totasksfile.ts
and adjust the code - install
ts-node
:npm install --save-dev ts-node
- change command in your
package.json
:
Tasksfile
project already has TypeScript
declaration files in source files.
API
For inside tasksfile.js
usage.
sh(cmd, options)
Run given command as a child process and log the call in the output.
./node_modules/.bin/
is included into PATH
so you can call installed scripts directly.
Function will return output of executed command.
const sh =
Options:
prefixTransform(prefix)
Transform function which can be used as transform
option of sh
function.
It allows to add prefixes to shell output.
Example:
const cli sh prefixTransform = { }
$ npx task testecho "test"[prefix] test
help(func, description, annotation)
Define help annotation for task function, so it will be printed out when calling task with --help
option and when calling run
without any arguments.
const help =
$ npx task build --help
$ npx task test --help
rawArgs()
Returns arguments / options passed to task in a raw, unparsed format.
const cli rawArgs = { console}
$ npx task hello 1 2 3 --testRAW ARGS ['1', '2', '3', '--test']