wakefile

0.5.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i wakefile

Weekly Downloads

0

Version

0.5.1

License

GPLv3

Unpacked Size

43.1 kB

Total Files

7

Last publish

Collaborators

  • sipware