Summary: For the electron build, plugins are bundled with the app and loaded from there at launch. The headless version can't require from its binary, so plugins need to be required from another path. This diff makes the path where bundled plugins are loaded from adjustable via an environment variable: `BUNDLED_PLUGIN_PATH`. If it's set, the plugins are loaded from this path, otherwise we default to the old behaviour of including them from `./defaultPlugins`. For the headless version we expect the plugins to be in a folder called `plugins` next to the executable. This should later be configurable via an argument passed to the CLI. Reviewed By: passy Differential Revision: D13843676 fbshipit-source-id: 04237ae6631b4f2ba56887fe992a56f860724edc
95 lines
2.1 KiB
JavaScript
95 lines
2.1 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
const Metro = require('../static/node_modules/metro');
|
|
const compilePlugins = require('../static/compilePlugins');
|
|
const tmp = require('tmp');
|
|
const path = require('path');
|
|
const fs = require('fs-extra');
|
|
|
|
function die(err) {
|
|
console.error(err.stack);
|
|
process.exit(1);
|
|
}
|
|
|
|
function compileDefaultPlugins(defaultPluginDir) {
|
|
return compilePlugins(
|
|
null,
|
|
[
|
|
path.join(__dirname, '..', 'src', 'plugins'),
|
|
path.join(__dirname, '..', 'src', 'fb', 'plugins'),
|
|
],
|
|
defaultPluginDir,
|
|
{force: true, failSilently: false},
|
|
)
|
|
.then(defaultPlugins =>
|
|
fs.writeFileSync(
|
|
path.join(defaultPluginDir, 'index.json'),
|
|
JSON.stringify(
|
|
defaultPlugins.map(plugin => ({
|
|
...plugin,
|
|
out: path.parse(plugin.out).base,
|
|
})),
|
|
),
|
|
),
|
|
)
|
|
.catch(die);
|
|
}
|
|
|
|
function compile(buildFolder, entry) {
|
|
// eslint-disable-next-line no-console
|
|
console.log('Building main bundle', entry);
|
|
|
|
const projectRoots = path.join(__dirname, '..');
|
|
return Metro.runBuild(
|
|
{
|
|
reporter: {update: () => {}},
|
|
projectRoot: projectRoots,
|
|
watchFolders: [projectRoots],
|
|
serializer: {},
|
|
transformer: {
|
|
babelTransformerPath: path.join(
|
|
__dirname,
|
|
'..',
|
|
'static',
|
|
'transforms',
|
|
'index.js',
|
|
),
|
|
},
|
|
},
|
|
{
|
|
dev: false,
|
|
minify: false,
|
|
resetCache: true,
|
|
sourceMap: true,
|
|
entry,
|
|
out: path.join(buildFolder, 'bundle.js'),
|
|
},
|
|
).catch(die);
|
|
}
|
|
|
|
function buildFolder() {
|
|
// eslint-disable-next-line no-console
|
|
console.log('Creating build directory');
|
|
return new Promise((resolve, reject) => {
|
|
tmp.dir((err, buildFolder) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(buildFolder);
|
|
}
|
|
});
|
|
}).catch(die);
|
|
}
|
|
|
|
module.exports = {
|
|
buildFolder,
|
|
compile,
|
|
die,
|
|
compileDefaultPlugins,
|
|
};
|