Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
feat: source quickstarts concurrently
Browse files Browse the repository at this point in the history
* Source quickstart concurrently to improve build times
  • Loading branch information
aswanson-nr committed Jul 11, 2022
1 parent 37a3892 commit b018b2e
Showing 1 changed file with 58 additions and 59 deletions.
117 changes: 58 additions & 59 deletions plugins/gatsby-source-quickstarts/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,74 +119,73 @@ exports.createResolvers = ({ createResolvers }) => {
* download all of the related images for use with `<GatsbyImage>` (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
Expand Down

0 comments on commit b018b2e

Please sign in to comment.