|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +import {pluginsDir} from './paths'; |
| 11 | +import path from 'path'; |
| 12 | +import {runBuild} from 'flipper-pkg-lib'; |
| 13 | +import {getWorkspaces} from './workspaces'; |
| 14 | + |
| 15 | +async function bundleAllPlugins() { |
| 16 | + const plugins = await getWorkspaces().then((workspaces) => |
| 17 | + workspaces.packages.filter((x) => x.isPlugin), |
| 18 | + ); |
| 19 | + const errors = new Map<string, any>(); |
| 20 | + for (const plugin of plugins) { |
| 21 | + const relativeDir = path.relative(pluginsDir, plugin.dir); |
| 22 | + console.log(`Bundling "${relativeDir}"`); |
| 23 | + console.time(`Finished bundling "${relativeDir}"`); |
| 24 | + try { |
| 25 | + await runBuild(plugin.dir, false); |
| 26 | + } catch (err) { |
| 27 | + console.log(`Failed to bundle "${relativeDir}": ${err.message}`); |
| 28 | + errors.set(relativeDir, err); |
| 29 | + } finally { |
| 30 | + console.timeEnd(`Finished bundling "${relativeDir}"`); |
| 31 | + } |
| 32 | + } |
| 33 | + if (errors.size) { |
| 34 | + console.error('---'); |
| 35 | + for (const [plugin, error] of errors) { |
| 36 | + console.error(`Failed to bundle ${plugin}`); |
| 37 | + console.error(error); |
| 38 | + console.error('---'); |
| 39 | + } |
| 40 | + throw new Error( |
| 41 | + `Failed to bundle ${errors.size} plugins: ${[...errors.keys()].join( |
| 42 | + ', ', |
| 43 | + )}`, |
| 44 | + ); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +bundleAllPlugins() |
| 49 | + .then(() => { |
| 50 | + process.exit(0); |
| 51 | + }) |
| 52 | + .catch((err: any) => { |
| 53 | + console.error(err); |
| 54 | + process.exit(1); |
| 55 | + }); |
0 commit comments