From aac883ba7fd958fb8551e22238ef809cfe19f6aa Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 19 Apr 2024 13:18:13 +0200 Subject: [PATCH 1/3] support multiple docmodels --- gatsby-config.js | 16 ++++++--- .../gatsby-node.js | 34 ++++++++++--------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/gatsby-config.js b/gatsby-config.js index 1b17d9db3..8b53f1d8a 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -8,7 +8,7 @@ const {query, transformer} = require('./algolia'); const yaml = require('js-yaml'); const fs = require('fs'); const remoteSources = require('./sources/remote'); -const {join} = require('path'); +const {join, basename} = require('path'); const isProduction = process.env.CONTEXT === 'production'; @@ -103,9 +103,17 @@ const plugins = [ { resolve: 'gatsby-plugin-apollo-client-api-doc', options: { - file: isSingleDocset - ? join(__dirname, 'local/public/client.api.json') - : 'https://apollo-client-docs.netlify.app/client.api.json' + files: [ + 'https://apollo-client-docs.netlify.app/client.api.json', + 'https://main--apollo-client-nextjs-docmodel.netlify.app/client-react-streaming.api.json', + 'https://main--apollo-client-nextjs-docmodel.netlify.app/experimental-nextjs-app-support.api.json' + ].map(url => { + if (isSingleDocset) { + const local = join(__dirname, 'local/public/', basename(url)); + if (fs.existsSync(local)) return local; + } + return url; + }) } }, { diff --git a/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js b/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js index 639513d57..843eb376e 100644 --- a/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js +++ b/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js @@ -11,24 +11,26 @@ const reactPreset = require('@babel/preset-react'); /** @type {import("gatsby").GatsbyNode['sourceNodes']} */ exports.sourceNodes = async (api, options) => { const tempDir = fs.mkdtempSync('api-model'); - try { - let {file} = /** @type {{file:string}} */ (options); + const {files} = /** @type {{files:string[]}} */ (options); - if (file.includes('://')) { - console.info('downloading api doc from url', file); - const request = await fetch(file); - const contents = await request.text(); - file = path.join(tempDir, 'api.json'); - fs.writeFileSync(file, contents); - } - if (fs.existsSync(file)) { - console.info('loading api doc from file', file); - loadApiDoc(file, api); - } else { - console.info('api doc file not found, skipping', file); + for (let file of files) { + try { + if (file.includes('://')) { + console.info('downloading api doc from url', file); + const request = await fetch(file); + const contents = await request.text(); + file = path.join(tempDir, 'api.json'); + fs.writeFileSync(file, contents); + } + if (fs.existsSync(file)) { + console.info('loading api doc from file', file); + loadApiDoc(file, api); + } else { + console.info('api doc file not found, skipping', file); + } + } finally { + fs.rmSync(tempDir, {recursive: true}); } - } finally { - fs.rmSync(tempDir, {recursive: true}); } }; From 602efac3ce2d6ad96d6ec56acfe2ec23c117d0a6 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 19 Apr 2024 13:20:44 +0200 Subject: [PATCH 2/3] fix temp dir cleanup --- .../gatsby-plugin-apollo-client-api-doc/gatsby-node.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js b/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js index 843eb376e..45ed4085d 100644 --- a/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js +++ b/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js @@ -13,8 +13,8 @@ exports.sourceNodes = async (api, options) => { const tempDir = fs.mkdtempSync('api-model'); const {files} = /** @type {{files:string[]}} */ (options); - for (let file of files) { - try { + try { + for (let file of files) { if (file.includes('://')) { console.info('downloading api doc from url', file); const request = await fetch(file); @@ -28,9 +28,9 @@ exports.sourceNodes = async (api, options) => { } else { console.info('api doc file not found, skipping', file); } - } finally { - fs.rmSync(tempDir, {recursive: true}); } + } finally { + fs.rmSync(tempDir, {recursive: true}); } }; From 600b6a42c5566b44f89bbaba5cbae5bf6877c754 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 19 Apr 2024 13:46:51 +0200 Subject: [PATCH 3/3] parser adjustment for ApolloClient$1 identifer --- plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js b/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js index 66c8d82d6..b3b5875ac 100644 --- a/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js +++ b/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js @@ -114,7 +114,7 @@ const parseKeyword = getRegexParser( const parseNumber = getRegexParser(/^\d+(\.\d+)?/, 'Number'); -const parseIdentifier = getRegexParser(/^[a-zA-Z]\w*/, 'Identifier'); +const parseIdentifier = getRegexParser(/^[a-zA-Z][$\w]*/, 'Identifier'); /** @type {ParserFn} */ function parseString(code, index) {