From 63e205071a4ac1ee91035546ccf0862b014188e7 Mon Sep 17 00:00:00 2001 From: Matt Meigs Date: Wed, 31 Jan 2024 15:17:16 -0500 Subject: [PATCH] clean, try without creating Buffer --- .github/workflows/cloud-docs-lighthouse.yml | 48 ------------------- .../gatsby-source-snooty-prod/gatsby-node.js | 10 +--- src/init/DocumentDatabase.js | 19 ++++++-- src/utils/setup/fetch-manifest-metadata.js | 9 +++- src/utils/setup/save-asset-files.js | 6 +-- 5 files changed, 25 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/cloud-docs-lighthouse.yml diff --git a/.github/workflows/cloud-docs-lighthouse.yml b/.github/workflows/cloud-docs-lighthouse.yml deleted file mode 100644 index 7e787d7cb..000000000 --- a/.github/workflows/cloud-docs-lighthouse.yml +++ /dev/null @@ -1,48 +0,0 @@ -on: - push: - branches: - - DOP-4247-build-artifacts -name: Cloud-docs Lighthouse -jobs: - deploy: - permissions: write-all - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - #---------------------------------------------- - # ----- install node ----- - #---------------------------------------------- - - uses: actions/setup-node@v1 - with: - node-version: '18.x' - #---------------------------------------------- - # ----- install python ----- - #---------------------------------------------- - - name: Set up python - id: setup-python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - #---------------------------------------------- - # ----- install & configure poetry ----- - #---------------------------------------------- - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - # - name: Ssh - # uses: webfactory/ssh-agent@v0.8.0 - # with: - # ssh-private-key: ${{ secrets.GITHUB_TOKEN }} - # - name: Clone - # run: | - # git clone https://github.com/10gen/cloud-docs.git - # #---------------------------------------------- - # # ----- Run custom Github Action ----- - # #---------------------------------------------- - # - name: Cloud Docs Build - # uses: mongodb/docs-worker-actions/build-cloud-docs@DOP-4247-build-artifact - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/plugins/gatsby-source-snooty-prod/gatsby-node.js b/plugins/gatsby-source-snooty-prod/gatsby-node.js index 72dc3f4bd..78769787a 100644 --- a/plugins/gatsby-source-snooty-prod/gatsby-node.js +++ b/plugins/gatsby-source-snooty-prod/gatsby-node.js @@ -152,9 +152,7 @@ exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) => if (filename.endsWith('.txt') && !manifestMetadata.openapi_pages?.[key]) { PAGES.push(key); } - if (val?.ast?.options?.template === 'changelog') { - hasOpenAPIChangelog = true; - } + if (val?.ast?.options?.template === 'changelog') hasOpenAPIChangelog = true; }); await createDocsetNodes({ db, createNode, createNodeId, createContentDigest }); @@ -172,12 +170,8 @@ exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) => await createRemoteMetadataNode({ createNode, createNodeId, createContentDigest }, umbrellaProduct); - console.log('metadata ', siteMetadata); - console.log('has ', hasOpenAPIChangelog); - if (siteMetadata.project === 'cloud-docs' && hasOpenAPIChangelog) { - console.log('create changelog node'); + if (siteMetadata.project === 'cloud-docs' && hasOpenAPIChangelog) await createOpenAPIChangelogNode({ createNode, createNodeId, createContentDigest, siteMetadata, db }); - } await saveAssetFiles(assets, db); if (!siteMetadata.manifestPath) { diff --git a/src/init/DocumentDatabase.js b/src/init/DocumentDatabase.js index a7afdbe10..2ec2b6fb7 100644 --- a/src/init/DocumentDatabase.js +++ b/src/init/DocumentDatabase.js @@ -67,8 +67,13 @@ class ManifestDocumentDatabase { async getDocuments() { const result = []; if (!this.zip) { - const documents = JSON.parse(fs.readFileSync('snooty-documents.json')); - return documents; + try { + const documents = JSON.parse(fs.readFileSync('snooty-documents.json')); + return documents; + } catch (err) { + console.error('No Manifest Path was found.'); + return result; + } } else { const zipEntries = this.zip.getEntries(); for (const entry of zipEntries) { @@ -87,13 +92,17 @@ class ManifestDocumentDatabase { async getAsset(checksum) { if (!this.zip) { - const asset = fs.readFileSync(`assets/${checksum}`, { encoding: 'base64' }); - return asset; + try { + const asset = fs.readFileSync(`assets/${checksum}`, { encoding: 'base64' }); + return asset; + } catch (err) { + console.error('No Manifest Path was found.'); + return null; + } } const result = this.zip.getEntry(`assets/${checksum}`); if (result) { const buffer = result.getData(); - console.log('BUFF? ', buffer); return buffer; } return null; diff --git a/src/utils/setup/fetch-manifest-metadata.js b/src/utils/setup/fetch-manifest-metadata.js index 7dca6b8b4..96fc85628 100644 --- a/src/utils/setup/fetch-manifest-metadata.js +++ b/src/utils/setup/fetch-manifest-metadata.js @@ -6,8 +6,13 @@ const fs = require('fs'); const fetchManifestMetadata = () => { let metadata = {}; if (!process.env.GATSBY_MANIFEST_PATH || !process.env.GATSBY_MANIFEST_PATH.match(/\.zip$/)) { - metadata = JSON.parse(fs.readFileSync('snooty-metadata.json')); - return metadata; + try { + metadata = JSON.parse(fs.readFileSync('snooty-metadata.json')); + return metadata; + } catch (err) { + console.error('No Manifest Path was found.'); + return metadata; + } } if (process.env.GATSBY_MANIFEST_PATH) { const zip = new AdmZip(process.env.GATSBY_MANIFEST_PATH); diff --git a/src/utils/setup/save-asset-files.js b/src/utils/setup/save-asset-files.js index 85507ddc8..7068a4c25 100644 --- a/src/utils/setup/save-asset-files.js +++ b/src/utils/setup/save-asset-files.js @@ -6,8 +6,6 @@ const saveFile = async (file, data) => { recursive: true, }); await fs.writeFile(path.join('public', file), data, 'binary'); - await fs.stat(path.join('public', file)); - await fs.writeFile(path.join('public', file), data, 'binary'); }; // Write all assets to static directory @@ -23,8 +21,8 @@ const saveAssetFiles = async (assets, db) => { ); process.exit(1); } - // filenames.forEach((filename) => imageWrites.push(saveFile(filename, buffer))); - filenames.forEach((filename) => imageWrites.push(saveFile(filename, Buffer.from(buffer, 'base64')))); + filenames.forEach((filename) => imageWrites.push(saveFile(filename, buffer))); + // filenames.forEach((filename) => imageWrites.push(saveFile(filename, Buffer.from(buffer, 'base64')))); } } await Promise.all(imageWrites);