Skip to content

Commit

Permalink
feat: Add method info for api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 15, 2020
1 parent a86e16f commit a96cb28
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
7 changes: 5 additions & 2 deletions plugins/gatsby-source-newrelic-sdk/src/docInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { getExamples } = require('./exampleInfo');
const { getTypeDefs } = require('./typeDefInfo');
const { getPropTypes } = require('./propTypeInfo');
const { getMethods } = require('./methodInfo');

exports.getComponentDoc = (name, sdk) => {
const component = sdk[name];
Expand All @@ -21,8 +22,9 @@ exports.getComponentDoc = (name, sdk) => {
name,
usage: `import { ${name} } from 'nr1'`,
description: component.__docs__.text,
examples: getExamples(component),
examples: getExamples(name, sdk),
propTypes: getPropTypes(component),
methods: getMethods(name, sdk),
typeDefs: getTypeDefs(properties.concat(propTypes), sdk),
};
};
Expand All @@ -40,7 +42,8 @@ exports.getApiDoc = (name, sdk) => {
name,
usage: `import { ${name} } from 'nr1'`,
description: api.__docs__.text,
examples: getExamples(api),
examples: getExamples(name, sdk),
methods: getMethods(name, sdk),
typeDefs: getTypeDefs(properties, sdk),
};
};
6 changes: 3 additions & 3 deletions plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const IGNORED_PREVIEWS = ['Dropdown', 'Modal', 'Tooltip'];

exports.getExamples = (component) => {
return (component.__docs__.tags.examples || []).map(
exports.getExamples = (name, obj) => {
return (obj[name].__docs__.tags.examples || []).map(
({ label, options, sourceCode }) => ({
label,
sourceCode,
preview: IGNORED_PREVIEWS.includes(component.name) ? false : options.live,
preview: IGNORED_PREVIEWS.includes(name) ? false : options.live,
})
);
};
32 changes: 32 additions & 0 deletions plugins/gatsby-source-newrelic-sdk/src/methodInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { getExamples } = require('./exampleInfo');

const IGNORED_METHODS = [
'prototype',
'length',
'name',
'propTypes',
'getDerivedStateFromProps',
'defaultProps',
];

exports.getMethods = (name, sdk) => {
const obj = sdk[name];

return Object.getOwnPropertyNames(obj)
.filter(
(member) =>
!IGNORED_METHODS.includes(member) && typeof obj[member] === 'function'
)
.map((member) => {
const methodDocs = obj[member].__docs__ || {};
const tags = methodDocs.tags || {};

return {
name: `${name}.${member}`,
description: methodDocs.text,
returnValue: (tags.return || [])[0] || { type: 'undefined' },
params: tags.param || [],
examples: getExamples(member, obj),
};
});
};

0 comments on commit a96cb28

Please sign in to comment.