-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
74 lines (70 loc) · 2.08 KB
/
setup.js
File metadata and controls
74 lines (70 loc) · 2.08 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
/**
* TODO create a perspective for each root subject
*/
const debug = require('debug')('refocus-load-sim:setup');
const subjects = require('./subjects');
const aspects = require('./aspects');
/**
* Adds root subjects.
*
* @returns {Promise} which resolves to an array of absolutePaths.
*/
function setupRootSubjects() {
debug('Setting up root subjects...');
return subjects.addRoots()
.then((rootsAdded) => {
debug('Finished setting up root subjects');
return rootsAdded.map((root) => root.absolutePath);
});
} // setupRootSubjects
/**
* Adds subject children.
*
* @returns {Promise} which resolves to an array of absolutePaths.
*/
function setupSubjectChildren() {
debug('Setting up subject children...');
return subjects.addChildren()
.then((subjectsAdded) => {
debug('Finished setting up subject children');
return subjectsAdded.map((subj) => subj.absolutePath);
});
} // setupSubjectChildren
/**
* Adds aspects (a different set of aspects for each root subject).
*
* @returns {Promise} which resolves to an array of aspect names.
*/
function setupAspects() {
debug('Setting up aspects...');
return aspects.addAspects()
.then((aspectsAdded) => {
debug('Finished setting up aspects');
return aspectsAdded.map((asp) => asp.name);
});
} // setupAspects
module.exports = {
doSetup() {
const rootMap = {};
return setupRootSubjects()
.then((rootsAdded) => {
// Store the results in a map keyed off of each root subject's absolutePath.
rootsAdded.forEach((root) => {
rootMap[root] = { aspects: [], subjects: [] };
});
})
.then(() => setupSubjectChildren())
.then((subjectsAdded) => {
// Store the array of absolutePaths in the rootMap.
subjectsAdded.forEach((s) =>
rootMap[s.split('.').slice(0, 1)].subjects.push(s));
})
.then(() => setupAspects())
.then((aspectsAdded) => {
// Store the array of aspect names in the rootMap.
aspectsAdded.forEach((a) =>
rootMap[a.split('_').slice(0, 1)].aspects.push(a));
})
.then(() => rootMap);
}, // doSetup
};