mastercontroller 1.1.16 → 1.1.17
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/MasterAction.js +5 -5
- package/MasterControl.js +29 -0
- package/MasterRouter.js +24 -32
- package/package.json +3 -2
package/MasterAction.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
// version 1.0.
|
|
2
|
+
// version 1.0.17
|
|
3
3
|
|
|
4
4
|
var master = require('./MasterControl');
|
|
5
5
|
var fileserver = require('fs');
|
|
@@ -24,7 +24,7 @@ class MasterAction{
|
|
|
24
24
|
|
|
25
25
|
// location starts from the view folder. Ex: partialViews/fileName.html
|
|
26
26
|
returnPartialView(location, data){
|
|
27
|
-
var actionUrl = master.router.currentRoute.root + "app/views/" + location;
|
|
27
|
+
var actionUrl = master.router.currentRoute.root + "/app/views/" + location;
|
|
28
28
|
var getAction = fileserver.readFileSync(actionUrl, 'utf8');
|
|
29
29
|
if(typeof(templateFunc) === "function"){
|
|
30
30
|
return templateFunc(getAction, data);
|
|
@@ -96,7 +96,7 @@ class MasterAction{
|
|
|
96
96
|
this.params = tools.combineObjects(data, this.params);
|
|
97
97
|
var func = master.viewList;
|
|
98
98
|
this.params = tools.combineObjects(this.params, func);
|
|
99
|
-
var actionUrl = (location === undefined) ? master.router.currentRoute.root + "app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html" : master.router.currentRoute.root + location;
|
|
99
|
+
var actionUrl = (location === undefined) ? master.router.currentRoute.root + "/app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html" : master.router.currentRoute.root + location;
|
|
100
100
|
var actionView = fileserver.readFileSync(actionUrl, 'utf8');
|
|
101
101
|
if(typeof(templateFunc) === "function"){
|
|
102
102
|
masterView = templateFunc(actionView, data);
|
|
@@ -127,7 +127,7 @@ class MasterAction{
|
|
|
127
127
|
this.params = tools.combineObjects(data, this.params);
|
|
128
128
|
var func = master.viewList;
|
|
129
129
|
this.params = tools.combineObjects(this.params, func);
|
|
130
|
-
var viewUrl = (location === undefined || location === "" || location === null) ? master.router.currentRoute.root + "app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html": master.router.currentRoute.root + "app/" + location;
|
|
130
|
+
var viewUrl = (location === undefined || location === "" || location === null) ? master.router.currentRoute.root + "/app/views/" + master.router.currentRoute.toController + "/" + master.router.currentRoute.toAction + ".html": master.router.currentRoute.root + "/app/" + location;
|
|
131
131
|
var viewFile = fileserver.readFileSync(viewUrl,'utf8');
|
|
132
132
|
if(typeof(templateFunc) === "function"){
|
|
133
133
|
childView = templateFunc(viewFile, this.params);
|
|
@@ -137,7 +137,7 @@ class MasterAction{
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
this.params.yield = childView;
|
|
140
|
-
var masterFile = fileserver.readFileSync(master.router.currentRoute.root + "app/views/layouts/master.html", 'utf8');
|
|
140
|
+
var masterFile = fileserver.readFileSync(master.router.currentRoute.root + "/app/views/layouts/master.html", 'utf8');
|
|
141
141
|
if(typeof(templateFunc) === "function"){
|
|
142
142
|
masterView = templateFunc(masterFile, this.params);
|
|
143
143
|
}
|
package/MasterControl.js
CHANGED
|
@@ -8,6 +8,7 @@ var https = require('https');
|
|
|
8
8
|
var fs = require('fs');
|
|
9
9
|
var url = require('url');
|
|
10
10
|
var path = require('path');
|
|
11
|
+
var globSearch = require("glob");
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class MasterControl {
|
|
@@ -146,6 +147,22 @@ class MasterControl {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
component(folderLocation, innerFolder){
|
|
151
|
+
|
|
152
|
+
var rootFolderLocation = `${this.root}/${folderLocation}/${innerFolder}`;
|
|
153
|
+
var search = `${rootFolderLocation}/**/*config.js`;
|
|
154
|
+
var files = globSearch.sync(search, rootFolderLocation);
|
|
155
|
+
require(files[0]);
|
|
156
|
+
var searchRoutes = `${rootFolderLocation}/**/*routes.js`;
|
|
157
|
+
var routeFiles = globSearch.sync(searchRoutes, rootFolderLocation);
|
|
158
|
+
var route = routeFiles[0];
|
|
159
|
+
var routeObject = {
|
|
160
|
+
isComponent : true,
|
|
161
|
+
root : rootFolderLocation
|
|
162
|
+
}
|
|
163
|
+
this.router.setup(routeObject);
|
|
164
|
+
require(route);
|
|
165
|
+
}
|
|
149
166
|
|
|
150
167
|
|
|
151
168
|
// adds all the server settings needed
|
|
@@ -240,6 +257,18 @@ class MasterControl {
|
|
|
240
257
|
start(server){
|
|
241
258
|
this.server = server;
|
|
242
259
|
}
|
|
260
|
+
|
|
261
|
+
startMVC(foldername){
|
|
262
|
+
var rootFolderLocation = `${this.root}/${foldername}`;
|
|
263
|
+
var search = `${rootFolderLocation}/**/*routes.js`;
|
|
264
|
+
var files = globSearch.sync(search, rootFolderLocation);
|
|
265
|
+
var route = {
|
|
266
|
+
isComponent : false,
|
|
267
|
+
root : `${this.root}`
|
|
268
|
+
}
|
|
269
|
+
this.router.setup(route);
|
|
270
|
+
require(files[0]);
|
|
271
|
+
}
|
|
243
272
|
|
|
244
273
|
|
|
245
274
|
// builds and calls all the required tools to have master running completely
|
package/MasterRouter.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// version 1.0.
|
|
1
|
+
// version 1.0.20
|
|
2
2
|
|
|
3
3
|
var master = require('./MasterControl');
|
|
4
4
|
var tools = require('./MasterTools');
|
|
5
5
|
const EventEmitter = require("events");
|
|
6
6
|
var currentRoute = {};
|
|
7
|
-
const path = require('path')
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { root } = require('./MasterControl');
|
|
8
9
|
|
|
9
10
|
var normalizePaths = function(requestPath, routePath, requestParams){
|
|
10
11
|
var obj = {
|
|
@@ -95,38 +96,9 @@ var loadScopedListClasses = function(){
|
|
|
95
96
|
class MasterRouter {
|
|
96
97
|
currentRouteName = null
|
|
97
98
|
_routes = {}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
loadRoutes(mimeList){
|
|
101
|
-
this.init(mimeList);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
addMimeList(mimeList){
|
|
105
|
-
this._addMimeList(mimeList);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
init(root){
|
|
109
|
-
var rootPath = path.join(root, '../');
|
|
110
|
-
this.__rootLocation = rootPath;
|
|
111
|
-
require( rootPath + "/routes");
|
|
112
|
-
}
|
|
113
|
-
|
|
99
|
+
|
|
114
100
|
start(){
|
|
115
101
|
var $that = this;
|
|
116
|
-
var rootLocation = path.join(this.__rootLocation, '../');
|
|
117
|
-
var componentExist = false;
|
|
118
|
-
if(rootLocation.includes("components")){
|
|
119
|
-
componentExist = true;
|
|
120
|
-
}
|
|
121
|
-
this.currentRouteName = tools.makeWordId(4);
|
|
122
|
-
|
|
123
|
-
if(this._routes[this.currentRouteName] === undefined){
|
|
124
|
-
this._routes[this.currentRouteName] = {
|
|
125
|
-
root : rootLocation,
|
|
126
|
-
isComponent : componentExist,
|
|
127
|
-
routes : []
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
102
|
return {
|
|
131
103
|
route : function(path, toPath, type, constraint){ // function to add to list of routes
|
|
132
104
|
|
|
@@ -207,6 +179,26 @@ class MasterRouter {
|
|
|
207
179
|
}
|
|
208
180
|
}
|
|
209
181
|
|
|
182
|
+
loadRoutes(mimeList){
|
|
183
|
+
this.init(mimeList);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
addMimeList(mimeList){
|
|
187
|
+
this._addMimeList(mimeList);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
setup(route){
|
|
191
|
+
this.currentRouteName = tools.makeWordId(4);
|
|
192
|
+
|
|
193
|
+
if(this._routes[this.currentRouteName] === undefined){
|
|
194
|
+
this._routes[this.currentRouteName] = {
|
|
195
|
+
root : route.root,
|
|
196
|
+
isComponent : route.isComponent,
|
|
197
|
+
routes : []
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
210
202
|
get currentRoute(){
|
|
211
203
|
return currentRoute;
|
|
212
204
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
"qs" : "^6.11.0",
|
|
4
4
|
"formidable": "^2.0.1",
|
|
5
5
|
"cookie": "^0.5.0",
|
|
6
|
-
"winston": "^3.8.2"
|
|
6
|
+
"winston": "^3.8.2",
|
|
7
|
+
"glob" :"^8.0.3"
|
|
7
8
|
},
|
|
8
9
|
"description": "A class library that makes using the Master Framework a breeze",
|
|
9
10
|
"homepage": "https://github.com/Tailor/MasterController#readme",
|
|
@@ -17,5 +18,5 @@
|
|
|
17
18
|
"scripts": {
|
|
18
19
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
20
|
},
|
|
20
|
-
"version": "1.1.
|
|
21
|
+
"version": "1.1.17"
|
|
21
22
|
}
|