🛠 Status: In Development
Tsundere is currently under heavy development. Feedback is always welcome, but be careful with
using it in production. API is not ready yet and can receive large changes.
Tsundere
![downloads](https://badgen.net/npm/dm/tsundere)
![ubuntu](https://img.shields.io/github/workflow/status/tommywalkie/tsundere/macos?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAABrUlEQVRIS92Wi03DQBBEZyoAOiAdhAoIFUAqACoAKgAqgA6ACiAVEDqgA0IFQAWDBp2R49z5bHwBiZUsRcr63u2s90P8kbEUV9I2gH0AryQfcucWAUu6AHAeYGckr9cOlnQL4LAG2iH5vFawpAMA9zXIE8lJDur/B0ktaQ5gN4A+AEy6RFsCrJ9AS4CdX0f9QPK9i8SVT6vUkjYBnFjC8CxqoJkPCWVkH+fbJWWr/C5J+veKJcHhw7kBYHjMHKGfCpbycXlZmSWLgiU5wsc+0mV8t5qpWAEHeV9aIu17n+NOEUs6BXDV9/SEv3PsrpbPcaM2h/Dds5P5j0ld1eYQqN+9I3mUOmSd4KTMvsy/BM9IuqlELRaxm8LG0ASH90edO5ckbw/eJEqYe/i0azmVrGMz3S7dNpeGSKpzvZUIt3bGguSofmaqV5eU27yVD+23hsQeSc/tb2sbi6WijpZVG9hz2EN8SGl5DxvHSiq3gTS3yL7f3DS13Ge3TElu9N5E6uZInDPvz+OwFjWVic7h6pAs2I5hr/IFLP88FkVYlXyJr9pNdaxe4L76dvH/BL1gpR+vRyf1AAAAAElFTkSuQmCC&label=MacOS)
Tsundere is a modern, lightweight and type-safe task runner for the stubborn ones.
Install
Install Tsundere for Node, using NPM or Yarn.
npm install --save-dev tsundere
Tsundere can also be used inside a browser, as an ES Module.
<script type="module">
import * as tsundere from 'https://esm.run/tsundere'
import * as tsundere from 'https://cdn.skypack.dev/tsundere'
import * as tsundere from 'https://unpkg.com/tsundere?module'
</script>
Browser compatibility
![IE / Edge](https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png) IE / Edge | ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) Firefox | ![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) Chrome | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png) Safari | ![iOS Safari](https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari-ios/safari-ios_48x48.png) iOS Safari | ![Opera](https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png) Opera |
---|
IE10+ / Edge 12 | Firefox 15 | Chrome 20 | Safari 8 | iOS Safari 9 | Opera 15 |
Tsundere is able to support up to Internet Explorer 10 and any browser with High Resolution Time API, using a few polyfills.
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6%2CReflect%2CSymbol%2CObject.defineProperty"></script>
<script src="https://unpkg.com/tsundere/dist/legacy"></script>
Usage
The following section will soon provide the Tsundere CLI usage guide, once it's ready.
API
A task is defined by a callback
function. Nameless tasks an be constructed via new TsundereTask(callback)
or task(callback)
. A provided Jest-inspired describe
function can help you label your tasks.
import { describe } from 'tsundere'
const job = describe('my-task', async () => await somePromiseWhichReturn(true))
You can subscribe to task events, using <TsundereTask>.on
or <TsundereTask>.once
.
job.once('start', () => console.log('it started.'))
job.once('end', () => console.log('it ended.'))
job.on('error', (e) => console.log(`Oops! Something went wrong..\n${e}`))
Using <TsundereTask>.run
method, the task will run and return a report, including relevant data as well as the duration in milliseconds.
job.run().then(report => { console.log(report); })
Nameless or labelled tasks can be grouped and run concurrently, using parallel
or in sequence, using series
methods.
import { parallel, series } from 'tsundere'
parallel([]).run().then(report => { console.log(report); })
series([]]).run().then(report => { console.log(report); })
Using describeParallel
or describeSeries
allows you to create and label your task group.
import { describeParallel, describeSeries } from 'tsundere'
describeParallel('parallel-tasks', []).run()
describeSeries('sequence-tasks', []).run()
You can also set up a TsundereRunner
task runner to run and chain tasks under a same context and reduce boilerplate code (e.g. events, formatting). Registered tasks will be run in parallel when using <TsundereRunner>.run
.
Under the hood, when relying on <TsundereRunner>.parallel
, <TsundereRunner>.series
, <TsundereRunner>.describeParallel
or <TsundereRunner>.describeSeries
methods, the task runner is explicitly aware of the related sub-tasks and will correctly format the final report.
import { TsundereRunner, describe, task } from 'tsundere'
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve(true), ms));
}
const tsundere = new TsundereRunner()
tsundere.task(async () => await timeout(300))
tsundere.describe('A', async () => await timeout(400))
tsundere.series([
describe('B', async () => await timeout(700)),
describe('C', async () => await timeout(450)),
])
tsundere.describeParallel('D', [
describe('E', async () => await timeout(750)),
task(async () => await timeout(600)),
])
tsundere.run().then(report => { console.log(report); })
Contributing
npm install
npm run build
npm run test
License
Tsundere is licensed under Apache License, Version 2.0.
© Copyright 2020 Tom Bazarnik.