Bundle headless plugins
Summary: Current temporary limitations: all headless plugins are bundled with Flipper. Reviewed By: antonk52 Differential Revision: D36098168 fbshipit-source-id: c58abe41776157258a5c39a80a5c1a33cf3f42c5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1f2f799772
commit
a6d7f98cfd
@@ -16,6 +16,7 @@ import {
|
||||
genMercurialRevision,
|
||||
getVersionNumber,
|
||||
prepareDefaultPlugins,
|
||||
prepareHeadlessPlugins,
|
||||
} from './build-utils';
|
||||
import {defaultPluginsDir, distDir, serverDir, staticDir} from './paths';
|
||||
import isFB from './isFB';
|
||||
@@ -330,6 +331,7 @@ async function buildServerRelease() {
|
||||
|
||||
await compileServerMain(false);
|
||||
await prepareDefaultPlugins(argv.channel === 'insiders');
|
||||
await prepareHeadlessPlugins();
|
||||
await copyStaticResources(dir, versionNumber);
|
||||
await downloadIcons(path.join(dir, 'static'));
|
||||
await buildBrowserBundle(path.join(dir, 'static'), false);
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
rootDir,
|
||||
browserUiDir,
|
||||
serverCoreDir,
|
||||
serverCompanionDir,
|
||||
} from './paths';
|
||||
import pFilter from 'p-filter';
|
||||
import child from 'child_process';
|
||||
@@ -110,6 +111,14 @@ export async function prepareDefaultPlugins(isInsidersBuild: boolean = false) {
|
||||
console.log('✅ Prepared default plugins.');
|
||||
}
|
||||
|
||||
export async function prepareHeadlessPlugins() {
|
||||
console.log(`⚙️ Preparing headless plugins...`);
|
||||
const sourcePlugins = await getSourcePlugins();
|
||||
const headlessPlugins = sourcePlugins.filter((p) => p.headless);
|
||||
await generateHeadlessPluginEntryPoints(headlessPlugins);
|
||||
console.log('✅ Prepared headless plugins.');
|
||||
}
|
||||
|
||||
function getGeneratedIndex(pluginRequires: string) {
|
||||
return `
|
||||
/* eslint-disable */
|
||||
@@ -191,6 +200,28 @@ async function generateDefaultPluginEntryPoints(
|
||||
console.log('✅ Generated bundled plugin entry points.');
|
||||
}
|
||||
|
||||
async function generateHeadlessPluginEntryPoints(
|
||||
headlessPlugins: InstalledPluginDetails[],
|
||||
) {
|
||||
console.log(
|
||||
`⚙️ Generating entry points for ${headlessPlugins.length} headless plugins...`,
|
||||
);
|
||||
const headlessRequires = headlessPlugins
|
||||
.map(
|
||||
(x) =>
|
||||
` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`,
|
||||
)
|
||||
.join(',\n');
|
||||
const generatedIndexHeadless = getGeneratedIndex(headlessRequires);
|
||||
await fs.ensureDir(path.join(serverCompanionDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(serverCompanionDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndexHeadless,
|
||||
);
|
||||
|
||||
console.log('✅ Generated headless plugin entry points.');
|
||||
}
|
||||
|
||||
async function buildDefaultPlugins(defaultPlugins: InstalledPluginDetails[]) {
|
||||
if (process.env.FLIPPER_NO_REBUILD_PLUGINS) {
|
||||
console.log(
|
||||
|
||||
@@ -9,9 +9,11 @@
|
||||
|
||||
/* eslint-disable flipper/no-console-error-without-context */
|
||||
|
||||
import {prepareDefaultPlugins} from './build-utils';
|
||||
import {prepareDefaultPlugins, prepareHeadlessPlugins} from './build-utils';
|
||||
|
||||
prepareDefaultPlugins().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Promise.all([prepareDefaultPlugins(), prepareHeadlessPlugins()]).catch(
|
||||
(err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -15,6 +15,10 @@ export const browserUiDir = path.join(rootDir, 'flipper-ui-browser');
|
||||
export const staticDir = path.join(rootDir, 'static');
|
||||
export const serverDir = path.join(rootDir, 'flipper-server');
|
||||
export const serverCoreDir = path.join(rootDir, 'flipper-server-core');
|
||||
export const serverCompanionDir = path.join(
|
||||
rootDir,
|
||||
'flipper-server-companion',
|
||||
);
|
||||
export const defaultPluginsDir = path.join(staticDir, 'defaultPlugins');
|
||||
export const pluginsDir = path.join(rootDir, 'plugins');
|
||||
export const fbPluginsDir = path.join(pluginsDir, 'fb');
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
compileServerMain,
|
||||
launchServer,
|
||||
prepareDefaultPlugins,
|
||||
prepareHeadlessPlugins,
|
||||
} from './build-utils';
|
||||
import Watchman from './watchman';
|
||||
import isFB from './isFB';
|
||||
@@ -185,6 +186,7 @@ async function startWatchChanges() {
|
||||
await prepareDefaultPlugins(
|
||||
process.env.FLIPPER_RELEASE_CHANNEL === 'insiders',
|
||||
);
|
||||
await prepareHeadlessPlugins();
|
||||
|
||||
// watch
|
||||
await startWatchChanges();
|
||||
|
||||
Reference in New Issue
Block a user