-
Notifications
You must be signed in to change notification settings - Fork 106
/
memberDocs.js
62 lines (51 loc) · 1.93 KB
/
memberDocs.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
/**
* @dgProcessor memberDocsProcessor
* @description
* Merge the member docs into their container doc, and remove them from the main docs collection
*/
module.exports = function memberDocsProcessor(log, getDocFromAlias, createDocMessage) {
const mergeableTypes = {
method: 'methods',
property: 'properties',
event: 'events'
};
return {
$runAfter: ['ids-computed'],
$runBefore: ['computing-paths'],
$process(docs) {
docs = docs.filter(doc => {
// Is this doc a member of another doc?
if ( doc.id.indexOf('#' ) !== -1 ) {
doc.isMember = true;
const parts = doc.id.split('#');
doc.memberof = parts[0];
// remove the 'method:', 'property:', etc specifier from the id part
doc.name = parts[1].replace(/^.*:/, '');
log.debug('child doc found', doc.id, doc.memberof);
let containerDocs = getDocFromAlias(doc.memberof, doc);
if ( containerDocs.length === 0 ) {
log.warn(createDocMessage('Missing container document: "'+ doc.memberof + '"', doc));
return;
}
if ( containerDocs.length > 1 ) {
// The memberof field was ambiguous, try prepending the module name too
containerDocs = getDocFromAlias(`${doc.module}.${doc.memberof}`, doc);
if ( containerDocs.length !== 1 ) {
log.warn(createDocMessage('Ambiguous container document reference: '+ doc.memberof, doc));
return;
}
}
const containerDoc = containerDocs[0];
doc.memberof = containerDoc.id;
// Add this member doc to the container doc
const containerProperty = mergeableTypes[doc.docType];
const container = containerDoc[containerProperty] = containerDoc[containerProperty] || [];
container.push(doc);
} else {
return doc;
}
});
return docs;
}
};
};