A task runner modeled after npm scripts, but with a task dependency graph, easy parallel/serial execution, and up to date checking.
Install locally ina project, then the global cli will use the local version.
npm install casker --save-dev && npm install -g casker
{
"scripts": {
"compile": "tsc",
"lint": "jshint",
"test": "jest",
"build": "npm run compile && npm run lint && npm run test"
}
}
import {casker} from 'casker';
const {task, tasksParallel, tasksSeries} = casker();
const srcFiles= './src/**/*.*';
const install = task('install', 'npm install', { inputs: ['package.json', 'yarn.lock'], description: 'Install dependencies' });
const lint = task('lint', 'tslint', {dependsOn: install, inputs: [srcFiles, './tslintconfig.json'], description: 'Run linter' });
const test = task('test', 'jest', {dependsOn: install, inputs: [srcFiles, './jest.config.json'], description: 'Run tests' });
const compile = task('compile', 'tsc', {dependsOn: install, inputs: [srcFiles, './tsconfig.json'], description: 'Compile typescript' });
tasksParallel('buildParallel', compile, lint, test);
tasksSeries('buildSeries', compile, lint, test);
With a bit more effort we now have tasks that will (if needed) install dependencies before executing tasks and only re-run when a file actually changes. We can also easily parallelize tasks instead of just running them sequentially. As the build grows in complexity the benefits increase.
casker test
install started
install output
...
install finished (4.933s)
test started
test output
...
test finished (13.313s)
casker
Tasks
install - Install dependencies
lint - Run jshint
test - Run tests
compile - Compile typescript
buildParallel - Execute tasks compile, lint, test in parallel
buildSeries - Execute tasks compile, lint, test in series
- Simple script execution just like npm 'scripts'
- Will look for globally installed modules and in the local node_modules/.bin
- Create task dependencies
- Run tasks in series or parallel
- Multi-Project support
- Typescript support
- Logs are aggregated by task
- With option for streaming logs
- Run tasks in the background
- Will be automatically killed once build is finished
- Up to date checking of inputs
NOTE: The examples include casker from the dist directory whereas a normal project would just import 'casker'.
See examples of different features and setups here.
They are also used for full functional testing of features.
Typescript definitions can be found here.
The name of this task used for running from the command line.
The command the task will run, the same as if creating a task with npm scripts.
Override environment variables.
Casker will start this task process then immediately continue on to the next task while allowing this one to run in the background. When all tasks have executed tasks run in the background will be killed automatically. Good for starting servers to run tests against.
Task description that will show up when listing tasks.
Sets a dependency for this task that will execute before this task.
Sets a task to run after this task exits regardless of exit code. Good for dropping databases after tests.
When the array value is a string it is treated as a glob of files, and the modified timestamp (mtime from fs.stat) is used to determine if any matching file has changed. Otherwise a promise that returns a string or number array can also be defined for custom checking.
Normally task output is grouped together for easier reading, but when this is set to true the logs will be streamed as they are sent from the child process. This is useful for tasks that start a dev server for local development or run tests in a watch mode.
The name of this task used for running from the command line.
Each argument after the name must be a task and will be run in parallel. This task will not complete until all the defined tasks complete.
The name of this task used for running from the command line.
Each argument after the name must be a task and will be run in the order they are passed. This task will not complete until all the defined tasks complete.