tooljs-tool
Version:
Composible Tooling for JavaScript
73 lines (51 loc) • 1.55 kB
Markdown
# tooljs
Composable Tooling for JavaScript.
## API
### .exec(fn)
Execute a tool instance manually, which recursively executes any sub-tools.
```js
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.
```js
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:
```js
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:
```js
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;
};
```