-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cem): add dependencies/dependants graph to the components descri…
…ption Fixes #826
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* CEM analyzer plugin: add-dependencies-in-description | ||
* | ||
* This plugin adds the dependencies and the dependants at the description of each component if they have some. | ||
*/ | ||
import { | ||
getComponentsGraph, | ||
getComponentsTree, | ||
} from '../tasks/component-usage-graph.js'; | ||
|
||
const graph = await getComponentsGraph(); | ||
|
||
export default function addDependenciesInDescription () { | ||
|
||
return { | ||
name: 'add-dependencies-in-description', | ||
moduleLinkPhase ({ moduleDoc }) { | ||
|
||
const isNotSmartComponentFile = !moduleDoc.path.includes('.smart'); | ||
|
||
const dependencies = isNotSmartComponentFile ? getComponentsTree([moduleDoc.path], graph, 'dependencies') : ''; | ||
const dependants = isNotSmartComponentFile ? getComponentsTree([moduleDoc.path], graph, 'dependants', 1) : ''; | ||
|
||
let sourceLine = ''; | ||
if (dependencies !== '') { | ||
sourceLine += '### Dependencies\n' + '```\n' + dependencies + '\n```'; | ||
} | ||
if (dependants !== '') { | ||
sourceLine += '\n\n### Dependants\n' + '```\n' + dependants + '\n```'; | ||
} | ||
|
||
moduleDoc.declarations | ||
?.filter((declaration) => declaration.kind === 'class') | ||
?.forEach((declaration) => { | ||
declaration.description += '\n\n' + sourceLine; | ||
}); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters