Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Fix generating separate fb-internal docs for plugins
Browse files Browse the repository at this point in the history
Reviewed By: lblasa

Differential Revision: D42370725

fbshipit-source-id: 0f0a1c9676aaa8a57ed8e4a6e973ef476ca757d3
  • Loading branch information
nikoant authored and facebook-github-bot committed Jan 6, 2023
1 parent 45770ee commit f8161d6
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions website/generate-plugin-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ async function generatePluginDocs() {
const id = name.replace('flipper-plugin-', '');
const generatedPluginResourcesPath = path.join(generatedPluginSymlinksDir, id);
await fs.symlink(pluginSourceDocsDir, generatedPluginResourcesPath, 'junction');
const setupDocPath = path.join(pluginSourceDocsDir, 'setup.mdx');
const setupDocsExists = await fs.pathExists(
setupDocPath,
);
const overviewDocPath = path.join(pluginSourceDocsDir, 'overview.mdx');
const overviewDocsExists = await fs.pathExists(
overviewDocPath,
);
const [setupDocRelativePath, overviewDocRelativePath] = await Promise.all([
getInternalOrPublicDocRelativePathOrNull(pluginSourceDocsDir, 'setup.mdx'),
getInternalOrPublicDocRelativePathOrNull(pluginSourceDocsDir, 'overview.mdx'),
]);
const setupDocsExists = setupDocRelativePath !== null;
const overviewDocsExists = overviewDocRelativePath !== null;
if (setupDocsExists) {
const setupDocPath = path.join(pluginSourceDocsDir, setupDocRelativePath);
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, setupDocPath)}`;
const setupArticleImportPath = path.join(relativePluginSymlinksDir, id, setupDocRelativePath);
await fs.writeFile(
path.join(generatedPluginsSetupDocsDir, `${id}.mdx`),
`---
Expand All @@ -87,15 +87,17 @@ title: ${title} Plugin Setup
sidebar_label: ${title}
custom_edit_url: ${customEditUrl}
---
import Article from '${relativePluginSymlinksDir}/${id}/setup.mdx';
import Article from '${setupArticleImportPath}';
<Article />
`,
);
}

if (overviewDocsExists) {
const overviewDocPath = path.join(pluginSourceDocsDir, overviewDocRelativePath);
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, overviewDocPath)}`;
const overviewArticleImportPath = path.join(relativePluginSymlinksDir, id, overviewDocRelativePath);
const linkToSetup = setupDocsExists
? `
→ [See setup instructions for the ${title} plugin](../../setup/plugins/${id}.mdx)
Expand All @@ -110,7 +112,7 @@ title: ${title} Plugin
sidebar_label: ${title}
custom_edit_url: ${customEditUrl}
---
import Article from '${relativePluginSymlinksDir}/${id}/overview.mdx';
import Article from '${overviewArticleImportPath}';
${linkToSetup}
<Article />
Expand All @@ -121,6 +123,16 @@ ${linkToSetup}
}
}

async function getInternalOrPublicDocRelativePathOrNull(docsDir: string, docName: string) {
if (process.env.FB_INTERNAL && await fs.pathExists(path.join(docsDir, 'fb', docName))) {
return path.join('fb', docName);
}
if (await fs.pathExists(path.join(docsDir, docName))) {
return docName;
}
return null
}

generatePluginDocs()
.then(() => process.exit(0))
.catch(err => {
Expand Down

0 comments on commit f8161d6

Please sign in to comment.