2021-06-29 11:18:29 +00:00
|
|
|
/* eslint-disable no-console */
|
2019-10-06 12:36:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
2021-06-29 11:18:29 +00:00
|
|
|
const chalk = require( 'chalk' );
|
2020-07-07 09:05:06 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
2021-04-08 12:31:12 +00:00
|
|
|
const CHECK_CIRCULAR_DEPS = process.env.CHECK_CIRCULAR_DEPS || false;
|
2022-02-02 14:56:16 +00:00
|
|
|
const ASSET_CHECK = process.env.ASSET_CHECK === 'true';
|
2019-10-06 12:36:15 +00:00
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const wcDepMap = {
|
|
|
|
'@woocommerce/blocks-registry': [ 'wc', 'wcBlocksRegistry' ],
|
|
|
|
'@woocommerce/settings': [ 'wc', 'wcSettings' ],
|
|
|
|
'@woocommerce/block-data': [ 'wc', 'wcBlocksData' ],
|
2022-08-12 14:23:08 +00:00
|
|
|
'@woocommerce/data': [ 'wc', 'data' ],
|
2021-06-09 14:09:42 +00:00
|
|
|
'@woocommerce/shared-context': [ 'wc', 'wcBlocksSharedContext' ],
|
|
|
|
'@woocommerce/shared-hocs': [ 'wc', 'wcBlocksSharedHocs' ],
|
2021-02-04 15:30:28 +00:00
|
|
|
'@woocommerce/price-format': [ 'wc', 'priceFormat' ],
|
2021-01-11 12:12:26 +00:00
|
|
|
'@woocommerce/blocks-checkout': [ 'wc', 'blocksCheckout' ],
|
2023-06-27 10:22:12 +00:00
|
|
|
'@woocommerce/interactivity': [ 'wc', '__experimentalInteractivity' ],
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const wcHandleMap = {
|
|
|
|
'@woocommerce/blocks-registry': 'wc-blocks-registry',
|
|
|
|
'@woocommerce/settings': 'wc-settings',
|
|
|
|
'@woocommerce/block-data': 'wc-blocks-data-store',
|
2022-08-12 14:23:08 +00:00
|
|
|
'@woocommerce/data': 'wc-store-data',
|
2021-06-09 14:09:42 +00:00
|
|
|
'@woocommerce/shared-context': 'wc-blocks-shared-context',
|
|
|
|
'@woocommerce/shared-hocs': 'wc-blocks-shared-hocs',
|
2021-02-04 15:30:28 +00:00
|
|
|
'@woocommerce/price-format': 'wc-price-format',
|
2021-01-07 12:02:21 +00:00
|
|
|
'@woocommerce/blocks-checkout': 'wc-blocks-checkout',
|
2023-06-27 10:22:12 +00:00
|
|
|
'@woocommerce/interactivity': 'wc-interactivity',
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getAlias = ( options = {} ) => {
|
|
|
|
let { pathPart } = options;
|
|
|
|
pathPart = pathPart ? `${ pathPart }/` : '';
|
|
|
|
return {
|
2020-05-29 13:49:56 +00:00
|
|
|
'@woocommerce/atomic-blocks': path.resolve(
|
2019-10-06 12:36:15 +00:00
|
|
|
__dirname,
|
2020-05-29 13:49:56 +00:00
|
|
|
`../assets/js/${ pathPart }atomic/blocks`
|
2019-10-06 12:36:15 +00:00
|
|
|
),
|
2020-05-29 11:28:04 +00:00
|
|
|
'@woocommerce/atomic-utils': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }atomic/utils`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/base-components': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/components/`
|
|
|
|
),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/base-context': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/context/`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/base-hocs': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/hocs/`
|
|
|
|
),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/base-hooks': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/hooks/`
|
|
|
|
),
|
2023-01-26 11:39:25 +00:00
|
|
|
'@woocommerce/interactivity': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }interactivity/`
|
|
|
|
),
|
2019-11-15 14:41:23 +00:00
|
|
|
'@woocommerce/base-utils': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/utils/`
|
|
|
|
),
|
2022-10-31 18:56:17 +00:00
|
|
|
'@woocommerce/blocks': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }/blocks`
|
|
|
|
),
|
2020-09-02 08:21:46 +00:00
|
|
|
'@woocommerce/editor-components': path.resolve(
|
2019-10-06 12:36:15 +00:00
|
|
|
__dirname,
|
2020-09-02 08:21:46 +00:00
|
|
|
`../assets/js/${ pathPart }editor-components/`
|
2019-10-06 12:36:15 +00:00
|
|
|
),
|
|
|
|
'@woocommerce/block-hocs': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }hocs`
|
|
|
|
),
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/block-settings': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../assets/js/settings/blocks'
|
2019-10-28 13:53:09 +00:00
|
|
|
),
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/icons': path.resolve( __dirname, `../assets/js/icons` ),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/resource-previews': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }previews/`
|
|
|
|
),
|
2021-05-25 11:49:13 +00:00
|
|
|
'@woocommerce/types': path.resolve( __dirname, `../assets/js/types/` ),
|
2022-04-21 07:28:41 +00:00
|
|
|
'@woocommerce/utils': path.resolve( __dirname, `../assets/js/utils/` ),
|
2023-05-10 11:02:33 +00:00
|
|
|
'@woocommerce/templates': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/templates/`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
function findModuleMatch( module, match ) {
|
|
|
|
if ( module.request && match.test( module.request ) ) {
|
|
|
|
return true;
|
|
|
|
} else if ( module.issuer ) {
|
|
|
|
return findModuleMatch( module.issuer, match );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-06 12:36:15 +00:00
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const requestToExternal = ( request ) => {
|
|
|
|
if ( wcDepMap[ request ] ) {
|
|
|
|
return wcDepMap[ request ];
|
|
|
|
}
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const requestToHandle = ( request ) => {
|
|
|
|
if ( wcHandleMap[ request ] ) {
|
|
|
|
return wcHandleMap[ request ];
|
|
|
|
}
|
2020-03-30 12:07:49 +00:00
|
|
|
};
|
|
|
|
|
2022-12-22 16:04:54 +00:00
|
|
|
const getProgressBarPluginConfig = ( name ) => {
|
2021-06-29 11:18:29 +00:00
|
|
|
return {
|
|
|
|
format:
|
2022-12-22 16:04:54 +00:00
|
|
|
chalk.blue( `Building ${ name }` ) +
|
2021-06-29 11:18:29 +00:00
|
|
|
' [:bar] ' +
|
|
|
|
chalk.green( ':percent' ) +
|
|
|
|
' :msg (:elapsed seconds)',
|
|
|
|
summary: false,
|
|
|
|
customSummary: ( time ) => {
|
|
|
|
console.log(
|
|
|
|
chalk.green.bold(
|
2022-12-22 16:04:54 +00:00
|
|
|
`${ name } assets build completed (${ time })`
|
2021-06-29 11:18:29 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
module.exports = {
|
2020-07-07 09:05:06 +00:00
|
|
|
NODE_ENV,
|
2021-04-08 12:31:12 +00:00
|
|
|
CHECK_CIRCULAR_DEPS,
|
2022-02-02 14:56:16 +00:00
|
|
|
ASSET_CHECK,
|
2019-10-06 12:36:15 +00:00
|
|
|
getAlias,
|
2020-07-07 09:05:06 +00:00
|
|
|
findModuleMatch,
|
|
|
|
requestToHandle,
|
|
|
|
requestToExternal,
|
2021-06-29 11:18:29 +00:00
|
|
|
getProgressBarPluginConfig,
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|