scanner.js 696 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * User: Hui Xie
  3. * Date: 14-3-9
  4. * Time: 下午3:17
  5. * To change this template use File | Settings | File Templates.
  6. */
  7. var router = require('koa-router'),
  8. path = require('path'),
  9. fsutil = require('./fsutil')();
  10. module.exports = function (app) {
  11. var exports = {};
  12. app.use(router(app));
  13. this.r = app;
  14. exports.scan = function(dir) {
  15. fsutil.recurse(dir, function(abspath, rootdir, subdir, filename) {
  16. if (path.extname(abspath) === '.js') {
  17. abspath = path.resolve(abspath);
  18. require(abspath.substring(0, abspath.length - 3))(app);
  19. }
  20. });
  21. };
  22. return exports;
  23. }