第一弹 koahub-loader KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架Installation<br>
<br>
$ npm install koahub-loader<br>
Use with koa<br>
<br>
// 1.model loader<br>
var model = loader([<br>
{<br>
root: './app/model',<br>
suffix: '.model.js'<br>
},<br>
{<br>
root: './addon',<br>
suffix: '.model.js',<br>
filter: [/\w*\/model\//]<br>
}<br>
]);<br>
<br>
// 2.controller loader<br>
var app = require('koa')();<br>
var router = require('koa-router')();<br>
var controller = loader([<br>
{<br>
root: './app/controller',<br>
suffix: '.controller.js',<br>
prefix: '/',<br>
}, {<br>
root: './addon',<br>
suffix: '.controller.js',<br>
prefix: '/addon/',<br>
filter: [/\w*\/controller\//]<br>
}<br>
]);<br>
<br>
for (var key in controller) {<br>
router.use(key, controller[key].routes());<br>
}<br>
app.use(router.routes());<br>
<br>
// 3.util loader<br>
var util = loader([<br>
{<br>
root: './app/common',<br>
suffix: '.util.js'<br>
},<br>
{<br>
root: './addon',<br>
suffix: '.util.js',<br>
filter: [/\w*\/common\//]<br>
}<br>
]);
官网:http://js.koahub.com