Files
flipper/desktop/static/getPluginFolders.ts
Anton Nikolaev ebfd045328 Fix symlinks resolution for plugin dependencies
Summary: Moved getWatchFolders script to flipper-pkg and used it from other packages. Script helps to resolve all the folders with package dependencies including symlinked folders in case if plugin is a part of yarn workspaces.

Reviewed By: mweststrate

Differential Revision: D21068373

fbshipit-source-id: 8691837fdb1aef333dab4c13d8758262838d36ee
2020-04-17 05:24:35 -07:00

39 lines
1.2 KiB
TypeScript

/**
* 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 path from 'path';
import fs from 'fs-extra';
import expandTilde from 'expand-tilde';
import {homedir} from 'os';
export default async function getPluginFolders(
includeThirdparty: boolean = false,
) {
const pluginFolders: string[] = [];
if (includeThirdparty) {
pluginFolders.push(path.join(homedir(), '.flipper', 'thirdparty'));
}
if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS === 'true') {
console.log(
'🥫 Skipping embedded plugins because "--no-embedded-plugins" flag provided',
);
return pluginFolders;
}
const flipperConfigPath = path.join(homedir(), '.flipper', 'config.json');
if (await fs.pathExists(flipperConfigPath)) {
const config = await fs.readJson(flipperConfigPath);
if (config.pluginPaths) {
pluginFolders.push(...config.pluginPaths);
}
}
pluginFolders.push(path.resolve(__dirname, '..', 'plugins'));
pluginFolders.push(path.resolve(__dirname, '..', 'plugins', 'fb'));
return pluginFolders.map(expandTilde).filter(fs.existsSync);
}