Fix generating separate fb-internal docs for plugins
Reviewed By: lblasa Differential Revision: D42370725 fbshipit-source-id: 0f0a1c9676aaa8a57ed8e4a6e973ef476ca757d3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
45770eeff4
commit
f8161d67a0
@@ -69,16 +69,16 @@ async function generatePluginDocs() {
|
|||||||
const id = name.replace('flipper-plugin-', '');
|
const id = name.replace('flipper-plugin-', '');
|
||||||
const generatedPluginResourcesPath = path.join(generatedPluginSymlinksDir, id);
|
const generatedPluginResourcesPath = path.join(generatedPluginSymlinksDir, id);
|
||||||
await fs.symlink(pluginSourceDocsDir, generatedPluginResourcesPath, 'junction');
|
await fs.symlink(pluginSourceDocsDir, generatedPluginResourcesPath, 'junction');
|
||||||
const setupDocPath = path.join(pluginSourceDocsDir, 'setup.mdx');
|
const [setupDocRelativePath, overviewDocRelativePath] = await Promise.all([
|
||||||
const setupDocsExists = await fs.pathExists(
|
getInternalOrPublicDocRelativePathOrNull(pluginSourceDocsDir, 'setup.mdx'),
|
||||||
setupDocPath,
|
getInternalOrPublicDocRelativePathOrNull(pluginSourceDocsDir, 'overview.mdx'),
|
||||||
);
|
]);
|
||||||
const overviewDocPath = path.join(pluginSourceDocsDir, 'overview.mdx');
|
const setupDocsExists = setupDocRelativePath !== null;
|
||||||
const overviewDocsExists = await fs.pathExists(
|
const overviewDocsExists = overviewDocRelativePath !== null;
|
||||||
overviewDocPath,
|
|
||||||
);
|
|
||||||
if (setupDocsExists) {
|
if (setupDocsExists) {
|
||||||
|
const setupDocPath = path.join(pluginSourceDocsDir, setupDocRelativePath);
|
||||||
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, setupDocPath)}`;
|
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, setupDocPath)}`;
|
||||||
|
const setupArticleImportPath = path.join(relativePluginSymlinksDir, id, setupDocRelativePath);
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
path.join(generatedPluginsSetupDocsDir, `${id}.mdx`),
|
path.join(generatedPluginsSetupDocsDir, `${id}.mdx`),
|
||||||
`---
|
`---
|
||||||
@@ -87,7 +87,7 @@ title: ${title} Plugin Setup
|
|||||||
sidebar_label: ${title}
|
sidebar_label: ${title}
|
||||||
custom_edit_url: ${customEditUrl}
|
custom_edit_url: ${customEditUrl}
|
||||||
---
|
---
|
||||||
import Article from '${relativePluginSymlinksDir}/${id}/setup.mdx';
|
import Article from '${setupArticleImportPath}';
|
||||||
|
|
||||||
<Article />
|
<Article />
|
||||||
`,
|
`,
|
||||||
@@ -95,7 +95,9 @@ import Article from '${relativePluginSymlinksDir}/${id}/setup.mdx';
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (overviewDocsExists) {
|
if (overviewDocsExists) {
|
||||||
|
const overviewDocPath = path.join(pluginSourceDocsDir, overviewDocRelativePath);
|
||||||
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, overviewDocPath)}`;
|
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, overviewDocPath)}`;
|
||||||
|
const overviewArticleImportPath = path.join(relativePluginSymlinksDir, id, overviewDocRelativePath);
|
||||||
const linkToSetup = setupDocsExists
|
const linkToSetup = setupDocsExists
|
||||||
? `
|
? `
|
||||||
→ [See setup instructions for the ${title} plugin](../../setup/plugins/${id}.mdx)
|
→ [See setup instructions for the ${title} plugin](../../setup/plugins/${id}.mdx)
|
||||||
@@ -110,7 +112,7 @@ title: ${title} Plugin
|
|||||||
sidebar_label: ${title}
|
sidebar_label: ${title}
|
||||||
custom_edit_url: ${customEditUrl}
|
custom_edit_url: ${customEditUrl}
|
||||||
---
|
---
|
||||||
import Article from '${relativePluginSymlinksDir}/${id}/overview.mdx';
|
import Article from '${overviewArticleImportPath}';
|
||||||
${linkToSetup}
|
${linkToSetup}
|
||||||
|
|
||||||
<Article />
|
<Article />
|
||||||
@@ -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()
|
generatePluginDocs()
|
||||||
.then(() => process.exit(0))
|
.then(() => process.exit(0))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|||||||
Reference in New Issue
Block a user