Show plugin documentation in Flipper
Reviewed By: passy Differential Revision: D29392524 fbshipit-source-id: 675de1fc070b1b8b22d0b27721c16dbd6f7076ef
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e4fb2907fd
commit
9fc85730ba
@@ -29,6 +29,10 @@ export interface PluginDetails {
|
||||
flipperSDKVersion?: string;
|
||||
pluginType?: PluginType;
|
||||
supportedDevices?: SupportedDevice[];
|
||||
publishedDocs?: {
|
||||
overview?: boolean;
|
||||
setup?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SupportedDevice {
|
||||
|
||||
@@ -94,6 +94,7 @@ test('getPluginDetailsV2', async () => {
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"pluginType": undefined,
|
||||
"publishedDocs": undefined,
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"supportedDevices": undefined,
|
||||
@@ -135,6 +136,7 @@ test('id used as title if the latter omited', async () => {
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"pluginType": undefined,
|
||||
"publishedDocs": undefined,
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"supportedDevices": undefined,
|
||||
@@ -175,6 +177,7 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"pluginType": undefined,
|
||||
"publishedDocs": undefined,
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"supportedDevices": undefined,
|
||||
@@ -218,6 +221,7 @@ test('flipper-plugin-version is parsed', async () => {
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"pluginType": undefined,
|
||||
"publishedDocs": undefined,
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"supportedDevices": undefined,
|
||||
@@ -265,6 +269,7 @@ test('plugin type and supported devices parsed', async () => {
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"pluginType": "device",
|
||||
"publishedDocs": undefined,
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"supportedDevices": Array [
|
||||
@@ -348,6 +353,10 @@ test('can merge two package.json files', async () => {
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"pluginType": "device",
|
||||
"publishedDocs": Object {
|
||||
"overview": true,
|
||||
"setup": true,
|
||||
},
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"supportedDevices": Array [
|
||||
|
||||
@@ -63,6 +63,20 @@ export async function getInstalledPluginDetails(
|
||||
): Promise<InstalledPluginDetails> {
|
||||
packageJson = packageJson ?? (await readPluginPackageJson(dir));
|
||||
const pluginDetails = getPluginDetails(packageJson);
|
||||
const [hasOverviewDocs, hasSetupDocs] = await Promise.all([
|
||||
pluginDetails.publishedDocs?.overview === undefined
|
||||
? fs.pathExists(path.join(dir, 'docs', 'overview.mdx'))
|
||||
: Promise.resolve(pluginDetails.publishedDocs.overview),
|
||||
pluginDetails.publishedDocs?.setup === undefined
|
||||
? fs.pathExists(path.join(dir, 'docs', 'setup.mdx'))
|
||||
: Promise.resolve(pluginDetails.publishedDocs.setup),
|
||||
]);
|
||||
if (hasOverviewDocs || hasSetupDocs) {
|
||||
pluginDetails.publishedDocs = {
|
||||
overview: hasOverviewDocs,
|
||||
setup: hasSetupDocs,
|
||||
};
|
||||
}
|
||||
const entry =
|
||||
pluginDetails.specVersion === 1
|
||||
? path.resolve(
|
||||
@@ -136,6 +150,7 @@ function getPluginDetailsV2(packageJson: any): PluginDetails {
|
||||
pluginType: packageJson?.pluginType,
|
||||
supportedDevices: packageJson?.supportedDevices,
|
||||
engines: packageJson.engines,
|
||||
publishedDocs: packageJson.publishedDocs,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user