1 |
|
2 | var ModuleDefiner = require('./resourcesDefiner/moduleDefiner');
|
3 | var ControllerDefiner = require('./resourcesDefiner/controllerDefiner');
|
4 | var Server = require('./server');
|
5 |
|
6 |
|
7 | module.exports = Definer;
|
8 |
|
9 | function Definer(){
|
10 | return this
|
11 | }
|
12 |
|
13 | Definer.prototype.defaultModule = function(moduleName){
|
14 | this.modules.default = moduleName;
|
15 | return this;
|
16 | }
|
17 |
|
18 | Definer.prototype.load = function(loaderMethod){
|
19 | for(var moduleName in this.modules){
|
20 |
|
21 | if (moduleName == 'default') return
|
22 |
|
23 | this.moduleLoder(moduleName,loaderMethod);
|
24 | console.info(loaderMethod + ' successfully loaded ' + moduleName + ' module');
|
25 | }
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | Definer.prototype.moduleLoder = function(name,loaderMethod){
|
32 | this.modules[name].loadControllers(loaderMethod);
|
33 |
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | Definer.prototype.module =function(options){
|
40 | ModuleDefiner.__proto__ = this
|
41 | var module = new ModuleDefiner(options);
|
42 | this.modules[module.name] = module;
|
43 |
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | Definer.prototype.controller = function(options){
|
50 | var controller = new ControllerDefiner(options);
|
51 |
|
52 | if(!controller.moduleName){
|
53 | controller.moduleName = this.modules.default;
|
54 | }
|
55 |
|
56 | if(!this.modules[controller.moduleName]){
|
57 | console.error(controller.moduleName + ' module does`t exist');
|
58 | throw new Error();
|
59 | }
|
60 |
|
61 | var currentModule = this.modules[controller.moduleName];
|
62 |
|
63 | if(currentModule.controllers[controller.name]){
|
64 |
|
65 | console.error(controller.moduleName + '模块的 ' + controller.name + '控制器 已经被定义,请检查是否重复');
|
66 | throw new Error();
|
67 | }
|
68 |
|
69 | currentModule.controllers[controller.name] = controller;
|
70 |
|
71 |
|
72 | return controller.actionDefiner;
|
73 |
|
74 | }
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | Definer.prototype.server = function(options){
|
80 | var server = new Server();
|
81 | server.optionsHandler(options);
|
82 | return server
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|