Skip to content

Commit

Permalink
docs: remove plugin from asset and add async file write function
Browse files Browse the repository at this point in the history
  • Loading branch information
addetz committed Nov 12, 2024
1 parent 887ce07 commit 6c0d8be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
2 changes: 0 additions & 2 deletions .github/actions/build-cached-packs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ runs:
run: |
# Ensure the correct folders exist.
mkdir -p .docusaurus/packs-integrations
mkdir -p .docusaurus/plugin-packs-integrations
# Move the files to their correct places in the checked out repository
mv downloaded_artifacts/.docusaurus/packs-integrations/* .docusaurus/packs-integrations
mv downloaded_artifacts/.docusaurus/plugin-packs-integrations/* .docusaurus/plugin-packs-integrations
mkdir -p static/img/packs
mv downloaded_artifacts/build/packs/* static/img/packs
# Clean up.
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/post_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ jobs:
path: |
build/packs
.docusaurus/packs-integrations
.docusaurus/plugin-packs-integrations
if-no-files-found: error
retention-days: 7
57 changes: 23 additions & 34 deletions plugins/packs-integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,7 @@ async function mapRepositories(repositories) {
return acc;
}, []);

open(`${dirname}${repos_filename}`, "w+", (err, fd) => {
if (err) {
logger.error("An error occurred while opening the JSON file:", err);
return;
}
try {
writeFile(`${dirname}${repos_filename}`, JSON.stringify(repoMap), (err1) => {
if (err1) {
logger.error("An error occurred while writing the JSON file:", err1);
}
});
} finally {
close(fd, (err2) => {
if (err2) logger.error("An error occurred while closing the file:", err2);
});
}
});
await writeResponseFile(`${dirname}${repos_filename}`, repoMap);

return repoMap;
}
Expand Down Expand Up @@ -420,6 +404,27 @@ async function getLogoUrl(packsAllData, logoUrlMap) {
}
}

async function writeResponseFile(path, apiResponse) {
open(path, "w+", (err, fd) => {
if (err) {
logger.error("An error occurred while opening the JSON file:", err);
return;
}
try {
writeFile(path, JSON.stringify(apiResponse), (err1) => {
if (err1) {
logger.error("An error occurred while writing the JSON file:", err1);
}
logger.info(`API Response saved to ${path}`);
});
} finally {
close(fd, (err2) => {
if (err2) logger.error("An error occurred while closing the file:", err2);
});
}
});
}

// If the plugin is disabled, then the packs and integrations data will not be fetched.
// However, the PDE service packs still need to be loaded.
// Otherwise, errors will be thrown when the PDE service packs are accessed.
Expand Down Expand Up @@ -532,23 +537,7 @@ async function pluginPacksAndIntegrationsData(context, options) {
apiPackResponse.apiPacksData = apiPacksData;
apiPackResponse.packMDMap = packMDMap;
apiPackResponse.logoUrlMap = logoUrlMap;
open(`${dirname}${packs_filename}`, "w+", (err, fd) => {
if (err) {
logger.error("An error occurred while opening the JSON file:", err);
return;
}
try {
writeFile(`${dirname}${packs_filename}`, JSON.stringify(apiPackResponse), (err1) => {
if (err1) {
logger.error("An error occurred while writing the JSON file:", err1);
}
});
} finally {
close(fd, (err2) => {
if (err2) logger.error("An error occurred while closing the file:", err2);
});
}
});
await writeResponseFile(`${dirname}${packs_filename}`, apiPackResponse);
} else {
try {
const data = await promises.readFile(`${dirname}${packs_filename}`);
Expand Down
2 changes: 0 additions & 2 deletions scripts/get-cached-packs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ echo "✅ Cached packs artifact downloaded."

# Ensure the correct folders exist.
mkdir -p .docusaurus/packs-integrations
mkdir -p .docusaurus/plugin-packs-integrations

# Move the files to their correct places in the checked out repository
mv downloaded_artifacts/.docusaurus/packs-integrations/* .docusaurus/packs-integrations
mv downloaded_artifacts/.docusaurus/plugin-packs-integrations/* .docusaurus/plugin-packs-integrations
mkdir -p static/img/packs
mv downloaded_artifacts/build/packs/* static/img/packs

Expand Down

0 comments on commit 6c0d8be

Please sign in to comment.