Auto-generate plugin docs

Summary:
This diff changes the way on how plugin documentation is produced. Instead of keeping plugin documentation together with other docs, we will now keep it together with plugin code. There are multiple advantages of such solution:
1. We are generating docs for every plugin in a standartised way so all of them looks similar. We can also use plugin metadata for generation as well (e.g. take title, icon, oncall name etc from package.json).
2. Standartised plugin docs make it possible to build docs both for websites (public and internal) and for embedding into Flipper.
3. It will hopefully incentivise authors to write docs as they will be a part of plugin "package".
4. We can scaffold documentation template using scarf to further incentivise filling it.

Reviewed By: jknoxville

Differential Revision: D29378053

fbshipit-source-id: 66ea48dc9ba225fabfb256ae6a10f8c81eef6f5f
This commit is contained in:
Anton Nikolaev
2021-06-29 13:00:18 -07:00
committed by Facebook GitHub Bot
parent 116f6eb5ba
commit e4fb2907fd
17 changed files with 352 additions and 26 deletions

View File

@@ -173,7 +173,15 @@ const siteConfig = {
],
// end_config_example
plugins: [
[
'./src/plugins/support-symlinks',
[require.resolve('@docusaurus/plugin-content-pages'),
{
id: 'embedded-pages',
path: './src/embedded-pages/',
mdxPageComponent: '@theme/EmbeddedMDXPage',
}
],
[
'@docusaurus/plugin-client-redirects',
{
redirects: [

View File

@@ -0,0 +1,130 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import fs from 'fs-extra';
import path from 'path';
const repoRoot = path.resolve(__dirname, '..');
const pluginsDir = path.join(
repoRoot,
'desktop',
'plugins',
'public',
);
const fbPluginsDir = path.resolve(
repoRoot,
'desktop',
'plugins',
'fb'
)
const generatedPluginsDocsDir = path.resolve(
repoRoot,
'docs',
'features',
'plugins',
);
const generatedPluginsSetupDocsDir = path.resolve(
repoRoot,
'docs',
'setup',
'plugins'
);
const generatedPluginSymlinksDir = path.resolve(
__dirname,
'src',
'embedded-pages',
'docs',
'plugins'
);
const repoUrl = process.env.FB_INTERNAL ? 'https://www.internalfb.com/code/fbsource/xplat/sonar' : 'https://github.com/facebook/flipper/blob/master';
const relativePluginSymlinksDir = path.relative(
generatedPluginsDocsDir,
generatedPluginSymlinksDir,
);
async function generatePluginDocs() {
await Promise.all([fs.emptyDir(generatedPluginsDocsDir), fs.emptyDir(generatedPluginsSetupDocsDir), fs.emptyDir(generatedPluginSymlinksDir)]);
const publicDirs = (await fs.readdir(pluginsDir)).map(dir => path.join(pluginsDir, dir));
const fbDirs = process.env.FB_INTERNAL ? (await fs.readdir(fbPluginsDir)).map(dir => path.join(fbPluginsDir, dir)) : [];
const allDirs = [...publicDirs, ...fbDirs];
console.log(allDirs.length);
for (const pluginSourceDir of allDirs) {
const pluginSourceDocsDir = path.join(pluginSourceDir, 'docs');
const packageJsonPath = path.join(pluginSourceDir, 'package.json');
if (
(
await Promise.all([
fs.pathExists(pluginSourceDocsDir),
fs.pathExists(packageJsonPath),
])
).every(p => p)
) {
console.log(`Found docs in ${pluginSourceDir}`);
const packageJson = await fs.readJson(packageJsonPath);
const name: string = packageJson.name;
const title: string = packageJson.title;
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,
);
if (setupDocsExists) {
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, setupDocPath)}`;
await fs.writeFile(
path.join(generatedPluginsSetupDocsDir, `${id}.mdx`),
`---
id: ${id}
title: ${title} Plugin Setup
sidebar_label: ${title}
custom_edit_url: ${customEditUrl}
---
import Article from '${relativePluginSymlinksDir}/${id}/setup.mdx';
<Article />
`,
);
}
if (overviewDocsExists) {
const customEditUrl = `${repoUrl}/${path.relative(repoRoot, overviewDocPath)}`;
const linkToSetup = setupDocsExists
? `
→ [See setup instructions for the ${title} plugin](../../setup/plugins/${id}.mdx)
`
: '';
await fs.writeFile(
path.join(generatedPluginsDocsDir, `${id}.mdx`),
`---
id: ${id}
title: ${title} Plugin
sidebar_label: ${title}
custom_edit_url: ${customEditUrl}
---
import Article from '${relativePluginSymlinksDir}/${id}/overview.mdx';
${linkToSetup}
<Article />
`,
);
}
}
}
}
generatePluginDocs()
.then(() => process.exit(0))
.catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -1,28 +1,33 @@
{
"scripts": {
"copy-schema": "fcli ensure static/schemas/plugin-package && fcli copy ../desktop/pkg/schemas/plugin-package-v2.json static/schemas/plugin-package/v2.json -o",
"start": "yarn copy-schema && yarn generate-uidocs && docusaurus start",
"build": "yarn copy-schema && yarn generate-uidocs && docusaurus build",
"start": "yarn copy-schema && yarn generate-uidocs && yarn generate-plugin-docs && docusaurus start --port 3001",
"build": "yarn copy-schema && yarn generate-uidocs && yarn generate-plugin-docs && docusaurus build",
"publish-gh-pages": "docusaurus deploy",
"write-translations": "docusaurus write-translations",
"version": "docusaurus version",
"rename-version": "docusaurus rename-version",
"generate-uidocs": "node ./generate-uidocs.js"
"generate-uidocs": "node ./generate-uidocs.js",
"generate-plugin-docs": "ts-node ./generate-plugin-docs.ts"
},
"devDependencies": {
"@babel/parser": "^7.14.5",
"@docusaurus/core": "^2.0.0-beta.0",
"@docusaurus/plugin-client-redirects": "2.0.0-beta.0",
"@docusaurus/preset-classic": "^2.0.0-beta.0",
"@types/fs-extra": "^9.0.11",
"classnames": "^2.3.1",
"docblock-parser": "^1.0.0",
"docusaurus-plugin-internaldocs-fb": "^0.8.5",
"file-cli": "^1.2.0",
"fs-extra": "^10.0.0",
"glob": "^7.1.7",
"mermaid": "^8.10.2",
"react": "^17.0.2",
"react-docgen": "^5.4.0",
"react-dom": "^17.0.2"
"react-dom": "^17.0.2",
"ts-node": "^10.0.0",
"typescript": "^4.3.4"
},
"resolutions": {
"kind-of": "6.0.3",

View File

@@ -9,14 +9,13 @@
const {fbInternalOnly, fbContent} = require('internaldocs-fb-helpers');
module.exports = {
module.exports = {
features: {
Features: [
'features/index',
'features/logs-plugin',
'features/layout-plugin',
'features/navigation-plugin',
'features/network-plugin',
'features/databases-plugin',
'features/images-plugin',
'features/sandbox-plugin',
@@ -34,6 +33,12 @@ module.exports = {
'fb/plugins',
]),
],
Plugins: [
{
type: 'autogenerated',
dirName: 'features/plugins',
}
]
},
setup: {
'Getting Started': [
@@ -82,7 +87,6 @@ module.exports = {
'Plugin Setup': [
'setup/layout-plugin',
'setup/navigation-plugin',
'setup/network-plugin',
'setup/databases-plugin',
'setup/images-plugin',
'setup/sandbox-plugin',
@@ -91,6 +95,12 @@ module.exports = {
'setup/leak-canary-2-plugin',
'setup/crash-reporter-plugin',
],
Plugins: [
{
type: 'autogenerated',
dirName: 'setup/plugins',
}
],
Advanced: ['custom-ports', 'stetho',
...fbInternalOnly([
'fb/www-certificate-exchange'

View File

@@ -0,0 +1 @@
DO NOT REMOVE! This folder is used for auto-generated symlinks to plugin docs. See generate-plugin.docs.ts.

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
// we need to use this plugin to be able to symlink plugin docs to "docs" folder
module.exports = function(context, options) {
return {
name: "support-symlinks",
configureWebpack(config, isServer, utils) {
return {
resolve: {
symlinks: false
},
devServer: {
watchOptions: { followSymlinks: false }
}
};
}
};
};

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import clsx from 'clsx';
import LayoutProviders from '@theme/LayoutProviders';
import useKeyboardNavigation from '@theme/hooks/useKeyboardNavigation';
import {ThemeClassNames} from '@docusaurus/theme-common';
import './styles.css';
function EmbeddedLayout(props) {
const {children, wrapperClassName, pageClassName} = props;
useKeyboardNavigation();
return (
<LayoutProviders>
<div
className={clsx(
ThemeClassNames.wrapper.main,
wrapperClassName,
pageClassName,
'embedded'
)}>
{children}
</div>
</LayoutProviders>
);
}
export default EmbeddedLayout;

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
div.embedded {
margin: 12px;
}

View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import EmbeddedLayout from '@theme/EmbeddedLayout';
import {MDXProvider} from '@mdx-js/react';
import MDXComponents from '@theme/MDXComponents';
import {ThemeClassNames} from '@docusaurus/theme-common';
function EmbeddedMDXPage(props) {
const {content: MDXPageContent} = props;
return (
<EmbeddedLayout
wrapperClassName={ThemeClassNames.wrapper.mdxPages}
pageClassName={ThemeClassNames.page.mdxPage}>
<main>
<MDXProvider components={MDXComponents}>
<MDXPageContent />
</MDXProvider>
</main>
</EmbeddedLayout>
);
}
export default EmbeddedMDXPage;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 KiB

View File

@@ -2921,6 +2921,26 @@
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.1.1.tgz#3348564048e7a2d7398c935d466c0414ebb6a669"
integrity sha512-Z6DoceYb/1xSg5+e+ZlPZ9v0N16ZvZ+wYMraFue4HYrE4ttONKtsvruIRf6t9TBR0YvSOfi1hUU0fJfBLCDYow==
"@tsconfig/node10@^1.0.7":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==
"@tsconfig/node12@^1.0.7":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c"
integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==
"@tsconfig/node14@^1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==
"@tsconfig/node16@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1"
integrity sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA==
"@types/color-name@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
@@ -2952,6 +2972,13 @@
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==
"@types/fs-extra@^9.0.11":
version "9.0.11"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.11.tgz#8cc99e103499eab9f347dbc6ca4e99fb8d2c2b87"
integrity sha512-mZsifGG4QeQ7hlkhO56u7zt/ycBgGxSVsFI/6lGTU34VtwkiqrrSDgw0+ygs8kFGWcXnFQWMrzF2h7TtDFNixA==
dependencies:
"@types/node" "*"
"@types/github-slugger@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@types/github-slugger/-/github-slugger-1.3.0.tgz#16ab393b30d8ae2a111ac748a015ac05a1fc5524"
@@ -3358,6 +3385,11 @@ anymatch@~3.1.1:
normalize-path "^3.0.0"
picomatch "^2.0.4"
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
arg@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.0.tgz#a20e2bb5710e82950a516b3f933fee5ed478be90"
@@ -4255,6 +4287,11 @@ cosmiconfig@^7.0.0:
path-type "^4.0.0"
yaml "^1.10.0"
create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
cross-fetch@^3.0.4:
version "3.0.6"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c"
@@ -4940,6 +4977,11 @@ detect-port@^1.3.0:
address "^1.0.1"
debug "^2.6.0"
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
@@ -5694,6 +5736,15 @@ fresh@0.5.2:
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=
fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"
fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
@@ -7230,6 +7281,11 @@ make-dir@^3.0.0, make-dir@^3.0.2, make-dir@^3.1.0:
dependencies:
semver "^6.0.0"
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
@@ -9547,7 +9603,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"
source-map-support@~0.5.12, source-map-support@~0.5.19:
source-map-support@^0.5.17, source-map-support@~0.5.12, source-map-support@~0.5.19:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
@@ -10028,6 +10084,22 @@ ts-essentials@^2.0.3:
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-2.0.12.tgz#c9303f3d74f75fa7528c3d49b80e089ab09d8745"
integrity sha512-3IVX4nI6B5cc31/GFFE+i8ey/N2eA0CZDbo6n0yrz0zDX8ZJ8djmU1p+XRz7G3is0F3bB3pu2pAroFdAWQKU3w==
ts-node@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
dependencies:
"@tsconfig/node10" "^1.0.7"
"@tsconfig/node12" "^1.0.7"
"@tsconfig/node14" "^1.0.0"
"@tsconfig/node16" "^1.0.1"
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
tslib@^1.10.0, tslib@^1.9.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
@@ -10068,6 +10140,11 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"
typescript@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==
ua-parser-js@0.7.24, ua-parser-js@^0.7.18:
version "0.7.24"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.24.tgz#8d3ecea46ed4f1f1d63ec25f17d8568105dc027c"
@@ -10830,6 +10907,11 @@ yargs@^16.2.0:
y18n "^5.0.5"
yargs-parser "^20.2.2"
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"