Skip to content

Commit

Permalink
feat: Specify the components and apis that will be documented via opt…
Browse files Browse the repository at this point in the history
…ions to the plugin
  • Loading branch information
jerelmiller committed Jun 12, 2020
1 parent f6cc594 commit 895a97b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
2 changes: 2 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ module.exports = {
resolve: 'gatsby-source-nr1-sdk',
options: {
release: 'release-1093',
components: ['Button', 'BlockText'],
apis: ['logger', 'nerdlet'],
},
},
],
Expand Down
58 changes: 42 additions & 16 deletions plugins/gatsby-source-nr1-sdk/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,52 @@ const loadSdk = require('./loadSdk');

exports.sourceNodes = async (
{ actions, createNodeId, createContentDigest },
{ release }
{ release, components = [], apis = [] }
) => {
const { createNode } = actions;

const sdk = await loadSdk(release);
const { Button } = sdk;

const data = {
name: 'Button',
description: Button.__docs__.text,
};
const documentedComponents = components
.map((name) => ({ name, component: sdk[name] }))
.filter(({ component }) => Boolean(component));

const documentedAPIs = apis
.map((name) => ({ name, api: sdk[name] }))
.filter(({ api }) => Boolean(api));

documentedComponents.forEach(({ name, component }) => {
const data = {
name,
description: component.__docs__.text,
};

createNode({
...data,
id: createNodeId(`NR1SdkComponent-${name}`),
parent: null,
children: [],
internal: {
type: 'NR1SdkComponent',
contentDigest: createContentDigest(data),
},
});
});

documentedAPIs.forEach(({ name, api }) => {
const data = {
name,
description: api.__docs__.text,
};

createNode({
...data,
id: createNodeId('NR1SdkComponent-Button'),
parent: null,
children: [],
internal: {
type: 'NR1SdkComponent',
contentDigest: createContentDigest(data),
},
createNode({
...data,
id: createNodeId(`NR1SdkAPI-${name}`),
parent: null,
children: [],
internal: {
type: 'NR1SdkAPI',
contentDigest: createContentDigest(data),
},
});
});
};

0 comments on commit 895a97b

Please sign in to comment.