1.0.4 • Published 8 years ago
@reinjs/rein-loader v1.0.4
rein-loader
The framework loader of rein.
Install
npm i @reinjs/rein-loaderUsage
We can use addCompiler to expose compilers.
const Loader = require('@reinjs/rein-loader');
const loader = new Loader();
loader.addCompiler(name, callback);
loader.addProgram(dir);
loader.compile();addCompilerit has two args.namethe compiler namecallbackhow to build data with args ofdir
addProgramit has one arg ofdirwhich tell compiler how to build under the dir.compilebuild the data method.
System Compilers
We can got some compilers easily by system.
Controller Compiler
Arguments:
optionspathnamehow to build dir by arg of dir.- ...args
e.g.
loader.addControllerCompiler(Object.assign(
config.controller || {},
{
inject: this.app,
target: this.app.controller = {},
pathname: this.makePathname(scope, 'controller')
}
));Middleware Compiler
Arguments:
optionspathnamehow to build dir by arg of dir.- ...args
e.g.
loader.addMiddlewareCompiler(Object.assign(
config.middleware || {},
{
inject: this.app,
target: this.app.middleware = {},
pathname: this.makePathname(scope, 'middleware')
}
));Service Compiler
Arguments:
optionspathnamehow to build dir by arg of dir.- ...args
e.g.
loader.addServiceCompiler(Object.assign(
config.service || {},
{
inject: this.app,
target: this.app.service = {},
pathname: this.makePathname(scope, 'service')
}
));Extend Compiler
loader.addExtendCompiler(property, file, options)
Arguments:
propertythe name of extendingfilecallbackhow to get dir by arg of dir?options
targetwhich object can been built on?injectinject objectoverridecan override properties?originalPrototypesoriginal prototypes from koa or other framework
It also has four custom methods by alias name:
In KOA:
addContextCompilerextend context.jsaddRequestCompilerextend request.jsaddResponseCompilerextend response.jsaddApplicationCompilerextend application.js
this.loader
.addContextCompiler(this.extendCondition(this.app.context, scope, 'extend/context.js'))
.addRequestCompiler(this.extendCondition(this.app.request, scope, 'extend/request.js'))
.addResponseCompiler(this.extendCondition(this.app.response, scope, 'extend/response.js'))
.addApplicationCompiler(this.extendCondition(this.app, scope, 'extend/application.js'));Message Compiler
On agent you should add this compiler for ipc sender.
this.loader.addMessageCompiler(inject, fileCallback);
Arguments:
injectinject objectfileCallbackhwo to get dir by arg of dir?
this.loader.addMessageCompiler(this.app, ({ type, pathname }) => {
if (type === 'project') return path.resolve(pathname, `app/${this.app.name}.js`);
return path.resolve(pathname, 'app/message.js');
});License
It is MIT licensed.