0.0.4 • Published 10 years ago

tooljs-tool v0.0.4

Weekly downloads
14
License
-
Repository
github
Last release
10 years ago

tooljs

Composable Tooling for JavaScript.

API

.exec(fn)

Execute a tool instance manually, which recursively executes any sub-tools.

var tool = require('tooljs-tool');

var Example = tool('my-tool');
var example = new Example;
example.exec(function(){
  console.log('done.');
});

Tool.option

Create options for your tool.

var tool = require('tooljs-tool');

var Example = tool('my-tool')
  .option('a', { type: 'string' })
  .option('b', { type: 'string' });

var example = new Example({ a: 'hello', b: 'world' });
example.exec(function(){
  console.log('done.');
});

Examples

Composing tools

How you might build a generator:

var template = require('tooljs-template');
var tool = require('tooljs-tool');
var source = __dirname + '/templates';

var Generator = tool('generator')
  .set('template:source', source) // still figuring out the API for this type of thing, setting defaults on nestd tools.
  .use(template('.gitignore'))
  .use(template('Readme.md'));

Making tools into modules

This way you can easily compose them. To do this, it seems this type of pattern should work:

var template = require('tooljs-template');
var tool = require('tooljs-tool');
var source = __dirname + '/templates';

var Generator = tool('generator')
  .set('template:source', source) // still figuring out the API for this type of thing, setting defaults on nestd tools.
  .use(template('.gitignore'))
  .use(template('Readme.md'));

module.exports = function(){
  return Generator;
};