From b136a032ff4ba5648535dfd1390e7acf62ac911d Mon Sep 17 00:00:00 2001 From: Callum Macdonald Date: Thu, 10 Sep 2020 20:27:22 +0200 Subject: [PATCH] Fixing netlify build (#888) --- gatsby/.nvmrc | 1 + gatsby/gatsby-config.js | 10 ++++++- gatsby/gatsby-node.js | 65 ++++++++++++++++++++++++++++++++++++++--- gatsby/netlify.toml | 5 +--- gatsby/package.json | 2 +- 5 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 gatsby/.nvmrc diff --git a/gatsby/.nvmrc b/gatsby/.nvmrc new file mode 100644 index 00000000..e1fcd1ea --- /dev/null +++ b/gatsby/.nvmrc @@ -0,0 +1 @@ +lts/erbium diff --git a/gatsby/gatsby-config.js b/gatsby/gatsby-config.js index 5da1f68c..4e0940bd 100644 --- a/gatsby/gatsby-config.js +++ b/gatsby/gatsby-config.js @@ -30,7 +30,15 @@ module.exports = { display: `minimal-ui`, }, }, - `gatsby-transformer-json`, + { + resolve: `gatsby-transformer-json`, + options: { + // NOTE: Without this setting, the JSON types are named based on the + // folder name. In the case of `content.json`, that depends on what the + // directory name of the repo is. In netlify's case, that's `repo`. + typeName: `jsonFile`, + }, + }, { resolve: `gatsby-source-filesystem`, options: { diff --git a/gatsby/gatsby-node.js b/gatsby/gatsby-node.js index 83c4d939..de6e0e14 100644 --- a/gatsby/gatsby-node.js +++ b/gatsby/gatsby-node.js @@ -2,11 +2,14 @@ const path = require('path') const crypto = require('crypto') const Bluebird = require('bluebird') +const util = require('util') // Set this to true to enable more logging in this file const DEBUG = false const isDev = process.env.NODE_ENV === 'development' +const jsonTypeName = `jsonFile` + /** * Implement Gatsby's Node APIs in this file. * @@ -17,10 +20,16 @@ const isDev = process.env.NODE_ENV === 'development' exports.onCreateNode = async ({ node, actions }) => { const { createNode } = actions - if (node.internal.type === 'OpenSourceIosAppsJson') { + + if (node.internal.type === jsonTypeName) { const { categories, projects } = node - categories.forEach(category => { + if (DEBUG) console.error('Found the json node #QE5PnL') + + let createdCategoryCount = 0 + let createdProjectCount = 0 + + await Bluebird.each(categories, async category => { if (typeof category.id !== 'string' || category.id.length < 1) { console.error('Invalid category #veJYyW', category) return @@ -32,7 +41,7 @@ exports.onCreateNode = async ({ node, actions }) => { project['category-ids'].includes(category.id), ).length - createNode({ + await createNode({ ...category, slug: category.id, parentSlug: category.parent, @@ -48,6 +57,8 @@ exports.onCreateNode = async ({ node, actions }) => { content: JSON.stringify(category), }, }) + + createdCategoryCount++ }) await Bluebird.each(projects, async project => { @@ -67,14 +78,60 @@ exports.onCreateNode = async ({ node, actions }) => { content: JSON.stringify(project), }, } + await createNode(projectNode) + + createdProjectCount++ }) + + console.error( + 'Created counts #WVIeFH', + createdCategoryCount, + createdProjectCount, + ) } } -exports.createPages = async ({ actions, graphql }) => { +exports.createPages = async ({ actions, graphql, getNodesByType }) => { const { createPage } = actions + if (DEBUG) { + const jsonNodes = getNodesByType(jsonTypeName) + const fileNodes = getNodesByType(`File`) + console.error( + 'START createPages() #IMKm8p', + jsonNodes.length, + fileNodes.length, + ) + + const debugResult = await graphql(` + query Debugging { + allFile { + edges { + node { + id + internal { + type + } + relativePath + children { + id + internal { + type + } + } + } + } + } + } + `) + + console.error( + 'File nodes #bIMtXP', + util.inspect(debugResult.data, { depth: null }), + ) + } + const categoryTemplate = path.resolve('src/templates/category.tsx') const tagTemplate = path.resolve('src/templates/tag.tsx') diff --git a/gatsby/netlify.toml b/gatsby/netlify.toml index 4d917458..195c8607 100644 --- a/gatsby/netlify.toml +++ b/gatsby/netlify.toml @@ -1,9 +1,6 @@ [[plugins]] package = "netlify-plugin-gatsby-cache" -[build.environment] - SHARP_IGNORE_GLOBAL_LIBVIPS="true" - [build] publish = "public/" - command = "yarn run build" + command = "head -n 2 ../contents.json && yarn run build" diff --git a/gatsby/package.json b/gatsby/package.json index 1c3f94bd..60ad50f0 100644 --- a/gatsby/package.json +++ b/gatsby/package.json @@ -30,6 +30,7 @@ "@material-ui/icons": "^4.9.1", "@material-ui/styles": "^4.10.0", "@reduxjs/toolkit": "^1.4.0", + "bluebird": "^3.7.2", "deepmerge": "^4.2.2", "gatsby": "^2.24.56", "gatsby-plugin-manifest": "^2.4.28", @@ -55,7 +56,6 @@ "@types/redux": "^3.6.0", "@typescript-eslint/eslint-plugin": "^4.1.0", "@typescript-eslint/parser": "^4.1.0", - "bluebird": "^3.7.2", "eslint": "^7.8.1", "eslint-config-prettier": "^6.11.0", "eslint-plugin-prettier": "^3.1.4",