From b018b2e4d8d3e5faee67ec7c35f3458ad0327da8 Mon Sep 17 00:00:00 2001 From: Alec Swanson Date: Mon, 11 Jul 2022 16:23:44 -0700 Subject: [PATCH] feat: source quickstarts concurrently * Source quickstart concurrently to improve build times --- .../gatsby-source-quickstarts/gatsby-node.js | 117 +++++++++--------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/plugins/gatsby-source-quickstarts/gatsby-node.js b/plugins/gatsby-source-quickstarts/gatsby-node.js index 4e0f6e21..471b5727 100644 --- a/plugins/gatsby-source-quickstarts/gatsby-node.js +++ b/plugins/gatsby-source-quickstarts/gatsby-node.js @@ -119,74 +119,73 @@ exports.createResolvers = ({ createResolvers }) => { * download all of the related images for use with `` (sharp). */ exports.sourceNodes = async ({ - actions, + actions: { createNode }, createNodeId, createContentDigest, getCache, -}) => { - const { createNode } = actions; - - for (const quickstart of QUICKSTARTS) { - const { name, id, logoUrl } = quickstart; +}) => + Promise.all( + QUICKSTARTS.map(async (quickstart) => { + const { name, id, logoUrl } = quickstart; + + let logoNode = null; + try { + // if we have a logoUrl, fetch it and create a "File" node + logoNode = logoUrl + ? await createRemoteFileNode({ + url: logoUrl, + parentNodeId: id, + createNode, + createNodeId, + getCache, + }) + : null; + } catch (e) { + // catch any errors when fetching image so that build still succeeds + console.log(`Unable to fetch logo for ${name}: ${logoUrl}`); // eslint-disable-line no-console + } - let logoNode = null; - try { - // if we have a logoUrl, fetch it and create a "File" node - logoNode = logoUrl - ? await createRemoteFileNode({ - url: logoUrl, + // loop over the dashboard(s) for this quickstart, fetch all the + // screenshot(s) and create "File" nodes for each. + const dashboards = await Promise.all( + quickstart.dashboards.map((dashboard) => + getDashboardData({ + dashboard, parentNodeId: id, createNode, createNodeId, getCache, }) - : null; - } catch (e) { - // catch any errors when fetching image so that build still succeeds - console.log(`Unable to fetch logo for ${name}: ${logoUrl}`); // eslint-disable-line no-console - } - - // loop over the dashboard(s) for this quickstart, fetch all the - // screenshot(s) and create "File" nodes for each. - const dashboards = await Promise.all( - quickstart.dashboards.map((dashboard) => - getDashboardData({ - dashboard, - parentNodeId: id, - createNode, - createNodeId, - getCache, - }) - ) - ); - - createNode({ - // quickstart fields - id, - name, - packUrl: quickstart.packUrl, - description: quickstart.description, - title: quickstart.title, - level: quickstart.level, - summary: quickstart.summary, - keywords: quickstart.keywords, - authors: quickstart.authors, - documentation: quickstart.documentation, - alerts: quickstart.alerts, - installPlans: quickstart.installPlans, - logo: logoNode || null, - dashboards, - // gatsby fields - parent: null, - children: [], - plugin: 'gatsby-source-quickstarts', - internal: { - type: 'Quickstarts', - contentDigest: createContentDigest({ id, name }), - }, - }); - } -}; + ) + ); + + createNode({ + // quickstart fields + id, + name, + packUrl: quickstart.packUrl, + description: quickstart.description, + title: quickstart.title, + level: quickstart.level, + summary: quickstart.summary, + keywords: quickstart.keywords, + authors: quickstart.authors, + documentation: quickstart.documentation, + alerts: quickstart.alerts, + installPlans: quickstart.installPlans, + logo: logoNode || null, + dashboards, + // gatsby fields + parent: null, + children: [], + plugin: 'gatsby-source-quickstarts', + internal: { + type: 'Quickstarts', + contentDigest: createContentDigest({ id, name }), + }, + }); + }) + ); /** * Gets the information for a `QuickstartDashboard` node. This will download