Skip to content

Commit

Permalink
feat(cem): add dependencies/dependants graph to the components descri…
Browse files Browse the repository at this point in the history
…ption

Fixes #826
  • Loading branch information
Galimede committed Oct 4, 2023
1 parent 903d1b9 commit ac63307
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cem/add-dependencies-in-description.js
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;
});
},
};
}
2 changes: 2 additions & 0 deletions custom-elements-manifest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import sortItems from './cem/sort-items.js';
import removePrivateMembers from './cem/remove-private-members.js';
import identifyReadonlyMembers from './cem/identify-readonly-members.js';
import addDependenciesInDescription from './cem/add-dependencies-in-description.js';
import addGithubSourceInDescription from './cem/add-github-source-in-description.js';
import supportCssdisplayJsdoc from './cem/support-cssdisplay-jsdoc.js';
import supportTypedefJsdoc from './cem/support-typedef-jsdoc.js';
Expand All @@ -22,6 +23,7 @@ export default {
identifyReadonlyMembers(),
supportCssdisplayJsdoc(),
supportTypedefJsdoc(),
addDependenciesInDescription(),
addGithubSourceInDescription({ githubProject: 'CleverCloud/clever-components' }),
listImages(),
],
Expand Down

0 comments on commit ac63307

Please sign in to comment.