model.js 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. var fs=require('fs');
  3. var F = require('../common/function');
  4. var path = require('path');
  5. function modelMgr() {
  6. var model_path = path.resolve(__dirname, '../model/');
  7. this.model_map = {};
  8. var that = this;
  9. this.init = function (){
  10. try{
  11. if(!fs.existsSync(model_path)) {
  12. F.throwErr("model path err");
  13. }
  14. var files = fs.readdirSync(model_path);
  15. console.log(files);
  16. files.forEach(function(file, index) {
  17. try {
  18. if(file != 'model_base.js' && file.endsWith(".js")){
  19. var class_name = file.substr(0, file.length - 3);
  20. var model_obj = require('../model/' + class_name);
  21. that.model_map[class_name] = new model_obj(class_name,that);
  22. }
  23. } catch(e) {
  24. F.log("loading model err:"+file);
  25. F.log(e);
  26. console.log(e);
  27. }
  28. });
  29. }catch(e) {
  30. console.log(e);
  31. }
  32. }
  33. this.init();
  34. }
  35. module.exports = modelMgr;