wakefile
v0.5.1
Published
Task manager
Downloads
24
Readme
Wakefile
Js rules builder inspired by unix make util.
For this module to be useful you need to provide prototype with target(), run() and other methods.
Example
module.exports = class Rules { constructor() { this.map = new Map(); }
// required target(name) { this.entry = {}; this.map.set(name, this.entry);
return this;}
params(params) { this.entry.params = params; return this; // required for chaining }
use(cb) { this.entry.cb = cb; }
// required async run(ctx) { var entry = this.maps.get(ctx.method);
if(entry) {
return await entry.cb(ctx);
}} }
Now you can use it
const Wakefile = require('wakefile'); const rules = new Wakefile(new Rules()); const conf = require('./config/rules');
conf(rules);
async test(ctx) { var result = await rules.run(ctx); }
test({method: 'foo', data: 1234}) test({method: 'bar', data: 4321})
Here is example of config/rules
module.export = function rules($) { $('foo').params({a: 1}).use(async(ctx) => {console.log('foo', ctx.data)}) $('bar').params({b: 2}).use(async(ctx) => {console.log('bar', ctx.data)}) }
TODO
Examples
