Rename second batch for '.ts' files to '.tsx' in plugin-lib dir
Summary: Rename first batch for '.ts' files to '.tsx' Reviewed By: passy Differential Revision: D33843245 fbshipit-source-id: 28fd161e258e4d20200620b083aea48f9e58ea64
This commit is contained in:
committed by
Facebook GitHub Bot
parent
75f874a5dd
commit
69bac4a3d6
73
desktop/plugin-lib/src/getPluginDetails.tsx
Normal file
73
desktop/plugin-lib/src/getPluginDetails.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and 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';
|
||||
import {
|
||||
getPluginDetails,
|
||||
InstalledPluginDetails,
|
||||
isPluginJson,
|
||||
} from 'flipper-common';
|
||||
import {pluginCacheDir} from './pluginPaths';
|
||||
|
||||
export async function readPluginPackageJson(dir: string): Promise<any> {
|
||||
const baseJson = await fs.readJson(path.join(dir, 'package.json'));
|
||||
if (await fs.pathExists(path.join(dir, 'fb', 'package.json'))) {
|
||||
const addedJson = await fs.readJson(path.join(dir, 'fb', 'package.json'));
|
||||
return Object.assign({}, baseJson, addedJson);
|
||||
} else {
|
||||
return baseJson;
|
||||
}
|
||||
}
|
||||
|
||||
export async function isPluginDir(dir: string): Promise<boolean> {
|
||||
const packageJsonPath = path.join(dir, 'package.json');
|
||||
const json = (await fs.pathExists(packageJsonPath))
|
||||
? await fs.readJson(path.join(dir, 'package.json'), {
|
||||
throws: false,
|
||||
})
|
||||
: undefined;
|
||||
return isPluginJson(json);
|
||||
}
|
||||
|
||||
export async function getInstalledPluginDetails(
|
||||
dir: string,
|
||||
packageJson?: any,
|
||||
): 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(
|
||||
pluginCacheDir,
|
||||
`${packageJson.name}@${packageJson.version || '0.0.0'}.js`,
|
||||
)
|
||||
: path.resolve(dir, packageJson.main);
|
||||
return {
|
||||
...pluginDetails,
|
||||
isBundled: false,
|
||||
isActivatable: true,
|
||||
dir,
|
||||
entry,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user