-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeStruct.js
More file actions
95 lines (86 loc) · 2.73 KB
/
Copy pathmakeStruct.js
File metadata and controls
95 lines (86 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var path = require('path');
var fs = require('fs');
var GLOBAL_METHODS=require('./../index.js').methods;
var doneMap = {};
var N_REG = GLOBAL_METHODS.isAlphaNum;
var kys = ['+','=','$', '$get', '$post', '$put', '$delete', '$options', '>', '$patch', '*'];
module.exports = function(ModuleDir,apiFile, startFile){
try {
fs.mkdirSync(ModuleDir);
} catch(erm){
}
var MAINS = require(apiFile);
GLOBAL_METHODS.replace(MAINS.vars, MAINS.vars);
GLOBAL_METHODS.replace(MAINS.root, MAINS.vars);
if(startFile) {
require('fs').writeFileSync(startFile, "var j2s = require('json2server')(); j2s.start();");
}
var forOneModule = function(bs){
var mods =[];
var pths = [ModuleDir];
if(!(Array.isArray(bs))) bs = [];
pths = pths.concat(bs);
var ls = GLOBAL_METHODS.assign(false,pths);
if(ls[ls.length-1] && ls[ls.length-1].charAt(0) === ':'){
ls[ls.length-1] = ls[ls.length-1].substring(1);
}
try {
fs.mkdirSync(path.join.apply(path, ls.concat(['_methods'])));
} catch(erm){
}
var toCreateMethods = [];
kys.forEach(function(ky){
GLOBAL_METHODS.objwalk(function(vl){
var kn = GLOBAL_METHODS.lastValue(vl,'@');
if(typeof kn ==='string' && N_REG(kn) && isNaN(Number(kn))){
toCreateMethods.push(vl['@']);
}
},null,GLOBAL_METHODS.lastValue.apply(null, [MAINS.root].concat(bs).concat([ky])));
});
toCreateMethods.forEach(function(ky){
if(doneMap[ky]) return;
doneMap[ky]=true;
try {
fs.mkdirSync(path.join.apply(path, ls.concat(['_methods', ky])));
} catch(erm){
}
});
toCreateMethods.forEach(function(ky){
var ph =path.join.apply(path, ls.concat(['_methods', ky, 'index.js']));
if(!(fs.existsSync(ph))) {
try {
fs.writeFileSync(ph, '\nmodule.exports = function MainBlock(GLOBAL_APP_CONFIG, GLOBAL_METHODS, GLOBAL_VARS, GLOBAL_API) {\n function func(vars, methods, req, res) {\n }\n return func;\n};\n');
} catch(erm){
}
}
});
var ms = [],_ms = {};
pths.shift();
ls.shift();
var nls = GLOBAL_METHODS.assign(false,ls);
try {
Object.keys(GLOBAL_METHODS.lastValue.apply(null, [MAINS.root].concat(nls))).forEach(function(m){
var _m = m;
if(m.charAt(0) === ':'){
m = m.substring(1);
}
if(N_REG(m)){
ms.push(m);
_ms[m] = _m;
}
});
} catch(erm){
return;
}
ms.forEach(function(mt){
if(typeof mt ==='string' && isNaN(Number(mt))){
try {
fs.mkdirSync(path.join.apply(path, [ModuleDir].concat(ls).concat([mt])));
} catch(erm){
}
forOneModule(pths.concat([_ms[mt]]));
}
});
};
forOneModule();
};