Skip to content

Commit 752757c

Browse files
mkukliszburke
authored andcommitted
STRIPES-861: Setup federation
1 parent 798f10c commit 752757c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

lib/commands/federate.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const importLazy = require('import-lazy')(require);
2+
3+
const { contextMiddleware } = importLazy('../cli/context-middleware');
4+
const StripesCore = importLazy('../cli/stripes-core');
5+
const StripesPlatform = importLazy('../platform/stripes-platform');
6+
const { stripesConfigFile } = importLazy('./common-options');
7+
8+
let _stripesPlatform;
9+
let _stripesCore;
10+
11+
// stripesPlatform and stripesCore overrides primarily used as injection for unit tests
12+
function stripesOverrides(stripesPlatform, stripesCore) {
13+
_stripesPlatform = stripesPlatform;
14+
_stripesCore = stripesCore;
15+
}
16+
17+
function federateCommand(argv) {
18+
const context = argv.context;
19+
// Default federate command to production env
20+
if (!process.env.NODE_ENV) {
21+
process.env.NODE_ENV = 'production';
22+
}
23+
24+
const platform = _stripesPlatform || new StripesPlatform(argv.stripesConfig, context, argv);
25+
const webpackOverrides = [];
26+
27+
if (argv.analyze) {
28+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // eslint-disable-line
29+
webpackOverrides.push((config) => {
30+
config.plugins.push(new BundleAnalyzerPlugin());
31+
return config;
32+
});
33+
}
34+
35+
console.info('Federate module...');
36+
const stripes = _stripesCore || new StripesCore(context, platform.aliases);
37+
stripes.api.federate(Object.assign({}, argv, { webpackOverrides }));
38+
}
39+
40+
module.exports = {
41+
command: 'federate',
42+
describe: 'federate single module',
43+
builder: (yargs) => {
44+
yargs
45+
.middleware([
46+
contextMiddleware(),
47+
])
48+
.positional('configFile', stripesConfigFile.configFile)
49+
.option('analyze', {
50+
describe: 'Run the Webpack Bundle Analyzer after build (launches in browser)',
51+
type: 'boolean',
52+
})
53+
.example('$0 federate', 'federate a module');
54+
},
55+
handler: federateCommand,
56+
stripesOverrides,
57+
};

0 commit comments

Comments
 (0)