forked from Superalgos/Superalgos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiProject.js
116 lines (95 loc) · 6.25 KB
/
MultiProject.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
exports.newMultiProject = function () {
let thisObject = {
initialize: initialize
}
return thisObject
function initialize(rootObject, rootObjectName) {
/*
Here we will setup the rootObject object, with all the
projects and modules that will have inside.
*/
rootObject.projects = {}
for (let i = 0; i < PROJECTS_SCHEMA.length; i++) {
let projectDefinition = PROJECTS_SCHEMA[i]
global[rootObjectName].projects[projectDefinition.propertyName] = {}
let projectInstance = global[rootObjectName].projects[projectDefinition.propertyName]
projectInstance.utilities = {}
projectInstance.globals = {}
projectInstance.functionLibraries = {}
projectInstance.modules = {}
projectInstance.taskModules = {}
projectInstance.processModules = {}
projectInstance.botModules = {}
if (projectDefinition[rootObjectName] === undefined) { continue }
/* Set up Utilities of this Project */
if (projectDefinition[rootObjectName].utilities !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].utilities.length; j++) {
let utilityDefinition = projectDefinition[rootObjectName].utilities[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Utilities' + '/' + utilityDefinition.fileName
let requiredObject = require(path)
let requiredFunction = requiredObject[utilityDefinition.functionName]
projectInstance.utilities[utilityDefinition.propertyName] = requiredFunction.call()
}
}
/* Set up Globals of this Project */
if (projectDefinition[rootObjectName].globals !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].globals.length; j++) {
let globalDefinition = projectDefinition[rootObjectName].globals[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Globals' + '/' + globalDefinition.fileName
let requiredObject = require(path)
let requiredFunction = requiredObject[globalDefinition.functionName]
projectInstance.globals[globalDefinition.propertyName] = requiredFunction.call()
}
}
/* Set up Function Libraries of this Project */
if (projectDefinition[rootObjectName].functionLibraries !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].functionLibraries.length; j++) {
let functionLibraryDefinition = projectDefinition[rootObjectName].functionLibraries[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Function-Libraries' + '/' + functionLibraryDefinition.fileName
let requiredObject = require(path)
let requiredFunction = requiredObject[functionLibraryDefinition.functionName]
projectInstance.functionLibraries[functionLibraryDefinition.propertyName] = requiredFunction.call()
}
}
/*
From here we will require and get the modules, but without instantiating thisObject.
*/
/* Set up Modules for this Project */
if (projectDefinition[rootObjectName].modules !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].modules.length; j++) {
let taskModuleDefinition = projectDefinition[rootObjectName].modules[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Modules' + '/' + taskModuleDefinition.fileName
let requiredObject = require(path)
projectInstance.modules[taskModuleDefinition.propertyName] = requiredObject
}
}
/* Set up Task Modules for this Project */
if (projectDefinition[rootObjectName].taskModules !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].taskModules.length; j++) {
let taskModuleDefinition = projectDefinition[rootObjectName].taskModules[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Task-Modules' + '/' + taskModuleDefinition.fileName
let requiredObject = require(path)
projectInstance.taskModules[taskModuleDefinition.propertyName] = requiredObject
}
}
/* Set up Process Modules for this Project */
if (projectDefinition[rootObjectName].processModules !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].processModules.length; j++) {
let processModuleDefinition = projectDefinition[rootObjectName].processModules[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Process-Modules' + '/' + processModuleDefinition.fileName
let requiredObject = require(path)
projectInstance.processModules[processModuleDefinition.propertyName] = requiredObject
}
}
/* Set up Bot Modules for this Project */
if (projectDefinition[rootObjectName].botModules !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].botModules.length; j++) {
let botModuleDefinition = projectDefinition[rootObjectName].botModules[j]
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + rootObjectName + '/' + 'Bot-Modules' + '/' + botModuleDefinition.folderName + '/' + botModuleDefinition.fileName
let requiredObject = require(path)
projectInstance.botModules[botModuleDefinition.propertyName] = requiredObject
}
}
}
}
}