Skip to content

Commit

Permalink
clean, try without creating Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Jan 31, 2024
1 parent 0111623 commit 63e2050
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 67 deletions.
48 changes: 0 additions & 48 deletions .github/workflows/cloud-docs-lighthouse.yml

This file was deleted.

10 changes: 2 additions & 8 deletions plugins/gatsby-source-snooty-prod/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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) {
Expand Down
19 changes: 14 additions & 5 deletions src/init/DocumentDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/utils/setup/fetch-manifest-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/utils/setup/save-asset-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 63e2050

Please sign in to comment.