crocess v1.0.22
Crocess
Make your command-line programs be easily called by externals.
Links
Requirements
- Node.js >= 6.0.0
Installation
$ npm install crocess
Quick Start
Create an application instance and return data to console:
var Application = require('crocess').Application;
new Application().boot(function () {
console.log('Hello world!');
return { 'foo': 'bar' };
});
You will see this on console:
Hello world!
>>>>>BEGIN_RESULT>>>>>{"foo":"bar"}
You can also return a Promise.
new Application().boot(function () {
return Promise.resolve({"foo":"bar"});
});
// or using 'async/await'.
new Application().boot(async function () {
return await Promise.resolve({"foo":"bar"});
});
// => >>>>>BEGIN_RESULT>>>>>{"foo":"bar"}
Get Parameters
You can pass the parameters as a json formatted string with the --parameters
argument.
node example.js --parameters='{"name":"World"}'
Example:
new Application().boot(function () {
return 'Hello ' + this.parameters.name;
});
// => >>>>>BEGIN_RESULT>>>>>Hello World
The
parameters
property will be empty when the--parameters
argument not given.
Using Suite
An example suite class:
var Application = require('crocess').Application;
var BaseSuite = require('crocess').Suite;
class Example extends BaseSuite
{
/**
* Start handle the suite.
*/
handle() {
console.log('Hello suite!');
return 'foobar';
}
}
Now, boot the suite:
new Application().boot(new Example);
You will see this on console:
Hello suite!
>>>>>BEGIN_RESULT>>>>>foobar
Another way to boot suites:
new Application().boot(function () {
return new Example().boot(this);
});
If you need to passing something to the suite, a very straightforward way is override the constructor:
class Example extends BaseSuite
{
constructor(foo) {
super();
this.foo = foo;
}
}
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago