diff --git a/gatsby-config.js b/gatsby-config.js index 8f87f3954..2898c8a7c 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -76,6 +76,8 @@ module.exports = { resolve: 'gatsby-source-nr1-sdk', options: { release: 'release-1093', + components: ['Button', 'BlockText'], + apis: ['logger', 'nerdlet'], }, }, ], diff --git a/plugins/gatsby-source-nr1-sdk/gatsby-node.js b/plugins/gatsby-source-nr1-sdk/gatsby-node.js index a020cda4a..a317553ed 100644 --- a/plugins/gatsby-source-nr1-sdk/gatsby-node.js +++ b/plugins/gatsby-source-nr1-sdk/gatsby-node.js @@ -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), + }, + }); }); };