mastercontroller 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/MasterControl.js +21 -12
- package/MasterRouter.js +21 -10
- package/README.md +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alexander Rich
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/MasterControl.js
CHANGED
|
@@ -151,19 +151,25 @@ class MasterControl {
|
|
|
151
151
|
|
|
152
152
|
component(folderLocation, innerFolder){
|
|
153
153
|
|
|
154
|
-
var rootFolderLocation =
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
var rootFolderLocation = path.join(this.root, folderLocation, innerFolder);
|
|
155
|
+
var files = globSearch.sync("**/*config.js", { cwd: rootFolderLocation, absolute: true });
|
|
156
|
+
if(files && files.length > 0){
|
|
157
|
+
require(files[0]);
|
|
158
|
+
}else{
|
|
159
|
+
master.error.log(`Cannot find config file under ${rootFolderLocation}`, "error");
|
|
160
|
+
}
|
|
161
|
+
var routeFiles = globSearch.sync("**/*routes.js", { cwd: rootFolderLocation, absolute: true });
|
|
162
|
+
var route = routeFiles && routeFiles.length > 0 ? routeFiles[0] : null;
|
|
161
163
|
var routeObject = {
|
|
162
164
|
isComponent : true,
|
|
163
165
|
root : rootFolderLocation
|
|
164
166
|
}
|
|
165
167
|
this.router.setup(routeObject);
|
|
166
|
-
|
|
168
|
+
if(route){
|
|
169
|
+
require(route);
|
|
170
|
+
}else{
|
|
171
|
+
master.error.log(`Cannot find routes file under ${rootFolderLocation}`, "error");
|
|
172
|
+
}
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
|
|
@@ -464,15 +470,18 @@ class MasterControl {
|
|
|
464
470
|
}
|
|
465
471
|
|
|
466
472
|
startMVC(foldername){
|
|
467
|
-
var rootFolderLocation =
|
|
468
|
-
var
|
|
469
|
-
var files = globSearch.sync(search, rootFolderLocation);
|
|
473
|
+
var rootFolderLocation = path.join(this.root, foldername);
|
|
474
|
+
var files = globSearch.sync("**/*routes.js", { cwd: rootFolderLocation, absolute: true });
|
|
470
475
|
var route = {
|
|
471
476
|
isComponent : false,
|
|
472
477
|
root : `${this.root}`
|
|
473
478
|
}
|
|
474
479
|
this.router.setup(route);
|
|
475
|
-
|
|
480
|
+
if(files && files.length > 0){
|
|
481
|
+
require(files[0]);
|
|
482
|
+
}else{
|
|
483
|
+
master.error.log(`Cannot find routes file under ${rootFolderLocation}`, "error");
|
|
484
|
+
}
|
|
476
485
|
}
|
|
477
486
|
|
|
478
487
|
|
package/MasterRouter.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var master = require('./MasterControl');
|
|
4
4
|
var toolClass = require('./MasterTools');
|
|
5
5
|
const EventEmitter = require("events");
|
|
6
|
+
var path = require('path');
|
|
6
7
|
var currentRoute = {};
|
|
7
8
|
var tools = new toolClass();
|
|
8
9
|
|
|
@@ -36,6 +37,17 @@ var tools = new toolClass();
|
|
|
36
37
|
var root = routeObject.root;
|
|
37
38
|
var isComponent = routeObject.isComponent;
|
|
38
39
|
try{
|
|
40
|
+
// Ensure routes is an array
|
|
41
|
+
if(!Array.isArray(routeList)){
|
|
42
|
+
master.error.log(`route list is not an array`, "error");
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// No routes registered for this scope; skip silently
|
|
47
|
+
if(routeList.length === 0){
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
if(routeList.length > 0){
|
|
40
52
|
// loop through routes
|
|
41
53
|
for(var item in routeList){
|
|
@@ -86,10 +98,6 @@ var tools = new toolClass();
|
|
|
86
98
|
};
|
|
87
99
|
return -1;
|
|
88
100
|
}
|
|
89
|
-
else{
|
|
90
|
-
master.error.log(`route list is not an array`, "error");
|
|
91
|
-
return -1;
|
|
92
|
-
}
|
|
93
101
|
}
|
|
94
102
|
catch(e){
|
|
95
103
|
throw new Error("Error processing routes: " + e.stack);
|
|
@@ -251,12 +259,15 @@ class MasterRouter {
|
|
|
251
259
|
|
|
252
260
|
tools.combineObjects(master.requestList, requestObject);
|
|
253
261
|
requestObject = master.requestList;
|
|
254
|
-
var Control =
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
var Control = null;
|
|
263
|
+
try{
|
|
264
|
+
Control = require(path.join(currentRoute.root, 'app', 'controllers', `${tools.firstLetterlowercase(requestObject.toController)}Controller`));
|
|
265
|
+
}catch(e){
|
|
266
|
+
try{
|
|
267
|
+
Control = require(path.join(currentRoute.root, 'app', 'controllers', `${tools.firstLetterUppercase(requestObject.toController)}Controller`));
|
|
268
|
+
}catch(e2){
|
|
269
|
+
console.log(`Cannot find controller name - ${requestObject.toController}`);
|
|
270
|
+
}
|
|
260
271
|
}
|
|
261
272
|
tools.combineObjectPrototype(Control, master.controllerList);
|
|
262
273
|
Control.prototype.__namespace = Control.name;
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "A class library that makes using the Master Framework a breeze",
|
|
10
10
|
"homepage": "https://github.com/Tailor/MasterController#readme",
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "MIT",
|
|
12
12
|
"main": "MasterControl.js",
|
|
13
13
|
"name": "mastercontroller",
|
|
14
14
|
"repository": {
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
20
|
},
|
|
21
|
-
"version": "1.2.
|
|
21
|
+
"version": "1.2.7"
|
|
22
22
|
}
|