forked from Superalgos/Superalgos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppSchemas.js
66 lines (51 loc) · 2.46 KB
/
AppSchemas.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
exports.newAppSchemas = function () {
let thisObject = {
initialize: initialize
}
return thisObject
async function initialize() {
/*
Here we will load into memory all the APP_SCHEMA files of every project.
*/
await loadAppSchemas()
async function loadAppSchemas() {
return new Promise(loadAppSchemasForAllProjects)
function loadAppSchemasForAllProjects(resolve, reject) {
let projectsLoaded = 0
for (let i = 0; i < PROJECTS_SCHEMA.length; i++) {
let projectDefinition = PROJECTS_SCHEMA[i]
loadAppSchemasForProject(projectDefinition.name)
}
function loadAppSchemasForProject(project) {
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/'
let folder = 'App-Schema'
SA.projects.foundations.utilities.filesAndDirectories.getAllFilesInDirectoryAndSubdirectories(filePath + folder, onFilesReady)
function onFilesReady(files) {
for (let k = 0; k < files.length; k++) {
let name = files[k]
let nameSplitted = name.split(folder)
let fileName = nameSplitted[1]
for (let i = 0; i < 10; i++) {
fileName = fileName.replace('\\', '/')
}
let fileToRead = filePath + folder + fileName
let fileContent = SA.nodeModules.fs.readFileSync(fileToRead)
let schemaDocument
try {
schemaDocument = JSON.parse(fileContent)
SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.set(project + '-' + schemaDocument.type, schemaDocument)
} catch (err) {
console.log('[WARN] loadAppSchemasForProject -> Error Parsing JSON File: ' + fileToRead + '. Error = ' + err.stack)
return
}
}
projectsLoaded++
if (projectsLoaded === PROJECTS_SCHEMA.length) {
resolve()
}
}
}
}
}
}
}