Update build scripts to support bundling server add-ons
Summary: Summary Reviewed By: nikoant Differential Revision: D34170565 fbshipit-source-id: be9904809bf33e85536a4c6ead0e753ef05209ff
This commit is contained in:
committed by
Facebook GitHub Bot
parent
47dd675dc8
commit
5cdb7c952e
@@ -36,6 +36,7 @@ import {
|
||||
serverDir,
|
||||
rootDir,
|
||||
browserUiDir,
|
||||
serverCoreDir,
|
||||
} from './paths';
|
||||
import pFilter from 'p-filter';
|
||||
import child from 'child_process';
|
||||
@@ -108,6 +109,27 @@ export async function prepareDefaultPlugins(isInsidersBuild: boolean = false) {
|
||||
console.log('✅ Prepared default plugins.');
|
||||
}
|
||||
|
||||
function getGeneratedIndex(pluginRequires: string) {
|
||||
return `
|
||||
/* eslint-disable */
|
||||
// THIS FILE IS AUTO-GENERATED by function "generateDefaultPluginEntryPoints" in "build-utils.ts".
|
||||
|
||||
declare const require: any;
|
||||
|
||||
// This function exists to make sure that if one require fails in its module initialisation, not everything fails
|
||||
function tryRequire(module: string, fn: () => any): any {
|
||||
try {
|
||||
return fn();
|
||||
} catch (e) {
|
||||
console.error(\`Could not require \${module}: \`, e)
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export default {\n${pluginRequires}\n} as any
|
||||
`;
|
||||
}
|
||||
|
||||
async function generateDefaultPluginEntryPoints(
|
||||
defaultPlugins: InstalledPluginDetails[],
|
||||
) {
|
||||
@@ -124,36 +146,20 @@ async function generateDefaultPluginEntryPoints(
|
||||
p.flipperSDKVersion === '0.0.0' ? version : p.flipperSDKVersion,
|
||||
dir: undefined,
|
||||
entry: undefined,
|
||||
serverAddOnEntry: undefined,
|
||||
} as BundledPluginDetails),
|
||||
);
|
||||
await fs.writeJSON(
|
||||
path.join(defaultPluginsDir, 'bundled.json'),
|
||||
bundledPlugins,
|
||||
);
|
||||
const pluginRequres = bundledPlugins
|
||||
const pluginRequires = bundledPlugins
|
||||
.map(
|
||||
(x) =>
|
||||
` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`,
|
||||
)
|
||||
.join(',\n');
|
||||
const generatedIndex = `
|
||||
/* eslint-disable */
|
||||
// THIS FILE IS AUTO-GENERATED by function "generateDefaultPluginEntryPoints" in "build-utils.ts".
|
||||
|
||||
declare const require: any;
|
||||
|
||||
// This function exists to make sure that if one require fails in its module initialisation, not everything fails
|
||||
function tryRequire(module: string, fn: () => any): any {
|
||||
try {
|
||||
return fn();
|
||||
} catch (e) {
|
||||
console.error(\`Could not require \${module}: \`, e)
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export default {\n${pluginRequres}\n} as any
|
||||
`;
|
||||
const generatedIndex = getGeneratedIndex(pluginRequires);
|
||||
await fs.ensureDir(path.join(appDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(appDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
@@ -164,6 +170,25 @@ async function generateDefaultPluginEntryPoints(
|
||||
path.join(browserUiDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndex,
|
||||
);
|
||||
|
||||
const serverAddOns = defaultPlugins.filter(
|
||||
({serverAddOnSource}) => !!serverAddOnSource,
|
||||
);
|
||||
if (serverAddOns.length) {
|
||||
const serverAddOnRequires = serverAddOns
|
||||
.map(
|
||||
(x) =>
|
||||
` '${x.name}': tryRequire('${x.serverAddOnSource}', () => require('${x.serverAddOnSource}'))`,
|
||||
)
|
||||
.join(',\n');
|
||||
const generatedIndexServerAddOns = getGeneratedIndex(serverAddOnRequires);
|
||||
await fs.ensureDir(path.join(serverCoreDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(serverCoreDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndexServerAddOns,
|
||||
);
|
||||
}
|
||||
|
||||
console.log('✅ Generated bundled plugin entry points.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user