From 000e80f8b7e7a1d5dea24fcbf5bb0426bbc94588 Mon Sep 17 00:00:00 2001 From: Michal Kuklis Date: Thu, 30 Jun 2022 11:42:54 -0400 Subject: [PATCH 1/4] Add transpile command --- lib/commands/transpile.js | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/commands/transpile.js diff --git a/lib/commands/transpile.js b/lib/commands/transpile.js new file mode 100644 index 0000000..113fe6c --- /dev/null +++ b/lib/commands/transpile.js @@ -0,0 +1,47 @@ +const importLazy = require('import-lazy')(require); +const { contextMiddleware } = importLazy('../cli/context-middleware'); +const StripesCore = importLazy('../cli/stripes-core'); +const StripesPlatform = importLazy('../platform/stripes-platform'); +const { stripesConfigFile } = importLazy('./common-options'); +const { processError, processStats } = importLazy('../webpack-common'); + +let _stripesPlatform; +let _stripesCore; + +// stripesPlatform and stripesCore overrides primarily used as injection for unit tests +function stripesOverrides(stripesPlatform, stripesCore) { + _stripesPlatform = stripesPlatform; + _stripesCore = stripesCore; +} + +function transpileCommand(argv) { + const context = argv.context; + // Default transpile command to production env + if (!process.env.NODE_ENV) { + process.env.NODE_ENV = 'production'; + } + + const platform = _stripesPlatform || new StripesPlatform(argv.stripesConfig, context, argv); + const webpackOverrides = platform.getWebpackOverrides(context); + + console.log('Transpiling...'); + const stripes = _stripesCore || new StripesCore(context, platform.aliases); + stripes.api.transpile(Object.assign({}, argv, { webpackOverrides })) + .then(processStats) + .catch(processError); +} + +module.exports = { + command: 'transpile', + describe: 'Transpile single module', + builder: (yargs) => { + yargs + .middleware([ + contextMiddleware(), + ]) + .positional('configFile', stripesConfigFile.configFile) + .example('$0 transpile', 'Transpile a module'); + }, + handler: transpileCommand, + stripesOverrides, +}; From 6a3905f242df56ebd34bab6880d6d4fed62afde9 Mon Sep 17 00:00:00 2001 From: Michal Kuklis Date: Thu, 30 Jun 2022 11:57:13 -0400 Subject: [PATCH 2/4] Cleanup --- lib/commands/transpile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/commands/transpile.js b/lib/commands/transpile.js index 113fe6c..926b74f 100644 --- a/lib/commands/transpile.js +++ b/lib/commands/transpile.js @@ -1,4 +1,5 @@ const importLazy = require('import-lazy')(require); + const { contextMiddleware } = importLazy('../cli/context-middleware'); const StripesCore = importLazy('../cli/stripes-core'); const StripesPlatform = importLazy('../platform/stripes-platform'); From 7c058961f462712bd9ba302940356cb11b54a931 Mon Sep 17 00:00:00 2001 From: Michal Kuklis Date: Tue, 23 Aug 2022 15:18:56 -0400 Subject: [PATCH 3/4] Add ability to analyze output --- lib/commands/transpile.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/commands/transpile.js b/lib/commands/transpile.js index 926b74f..956d7b5 100644 --- a/lib/commands/transpile.js +++ b/lib/commands/transpile.js @@ -23,7 +23,15 @@ function transpileCommand(argv) { } const platform = _stripesPlatform || new StripesPlatform(argv.stripesConfig, context, argv); - const webpackOverrides = platform.getWebpackOverrides(context); + const webpackOverrides = []; + + if (argv.analyze) { + const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // eslint-disable-line + webpackOverrides.push((config) => { + config.plugins.push(new BundleAnalyzerPlugin()); + return config; + }); + } console.log('Transpiling...'); const stripes = _stripesCore || new StripesCore(context, platform.aliases); @@ -41,6 +49,10 @@ module.exports = { contextMiddleware(), ]) .positional('configFile', stripesConfigFile.configFile) + .option('analyze', { + describe: 'Run the Webpack Bundle Analyzer after build (launches in browser)', + type: 'boolean', + }) .example('$0 transpile', 'Transpile a module'); }, handler: transpileCommand, From faa6efc98fa13ff124a7bd7c42ed34974a5bb432 Mon Sep 17 00:00:00 2001 From: Michal Kuklis Date: Wed, 24 Aug 2022 11:35:09 -0400 Subject: [PATCH 4/4] Cleanup --- lib/commands/transpile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/transpile.js b/lib/commands/transpile.js index 956d7b5..1c2b7db 100644 --- a/lib/commands/transpile.js +++ b/lib/commands/transpile.js @@ -33,7 +33,7 @@ function transpileCommand(argv) { }); } - console.log('Transpiling...'); + console.info('Transpiling...'); const stripes = _stripesCore || new StripesCore(context, platform.aliases); stripes.api.transpile(Object.assign({}, argv, { webpackOverrides })) .then(processStats)