2020-07-07 09:05:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const { omit } = require( 'lodash' );
|
2020-07-22 12:05:56 +00:00
|
|
|
const glob = require( 'glob' );
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2020-07-22 12:05:56 +00:00
|
|
|
// List of blocks that should be used as webpack entry points. They are expected
|
|
|
|
// to be in `/assets/js/blocks/[BLOCK_NAME]`. If they are not, their relative
|
|
|
|
// path should be defined in the `customDir` property. The scripts below will
|
|
|
|
// take care of looking for `index.js`, `frontend.js` and `*.scss` files in each
|
|
|
|
// block directory.
|
|
|
|
// If a block is experimental, it should be marked with the `isExperimental`
|
|
|
|
// property.
|
|
|
|
const blocks = {
|
|
|
|
'handpicked-products': {},
|
|
|
|
'product-best-sellers': {},
|
|
|
|
'product-category': {},
|
|
|
|
'product-categories': {},
|
|
|
|
'product-new': {},
|
|
|
|
'product-on-sale': {},
|
|
|
|
'product-top-rated': {},
|
|
|
|
'products-by-attribute': {},
|
|
|
|
'featured-product': {},
|
|
|
|
'all-reviews': {
|
|
|
|
customDir: 'reviews/all-reviews',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
'reviews-by-product': {
|
|
|
|
customDir: 'reviews/reviews-by-product',
|
|
|
|
},
|
|
|
|
'reviews-by-category': {
|
|
|
|
customDir: 'reviews/reviews-by-category',
|
|
|
|
},
|
|
|
|
'product-search': {},
|
|
|
|
'product-tag': {},
|
|
|
|
'featured-category': {},
|
|
|
|
'all-products': {
|
|
|
|
customDir: 'products/all-products',
|
|
|
|
},
|
|
|
|
'price-filter': {},
|
|
|
|
'attribute-filter': {},
|
2021-08-20 15:56:14 +00:00
|
|
|
'stock-filter': {},
|
2020-07-22 12:05:56 +00:00
|
|
|
'active-filters': {},
|
|
|
|
cart: {
|
|
|
|
customDir: 'cart-checkout/cart',
|
|
|
|
},
|
|
|
|
checkout: {
|
|
|
|
customDir: 'cart-checkout/checkout',
|
|
|
|
},
|
2021-08-25 15:42:55 +00:00
|
|
|
'mini-cart': {
|
|
|
|
customDir: 'cart-checkout/mini-cart',
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
'single-product': {
|
|
|
|
isExperimental: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns the entries for each block given a relative path (ie: `index.js`,
|
|
|
|
// `**/*.scss`...).
|
|
|
|
// It also filters out elements with undefined props and experimental blocks.
|
|
|
|
const getBlockEntries = ( relativePath ) => {
|
|
|
|
const experimental =
|
|
|
|
! parseInt( process.env.WOOCOMMERCE_BLOCKS_PHASE, 10 ) < 3;
|
|
|
|
|
|
|
|
return Object.fromEntries(
|
|
|
|
Object.entries( blocks )
|
|
|
|
.filter(
|
|
|
|
( [ , config ] ) =>
|
|
|
|
! config.isExperimental ||
|
|
|
|
config.isExperimental === experimental
|
|
|
|
)
|
|
|
|
.map( ( [ blockCode, config ] ) => {
|
|
|
|
const filePaths = glob.sync(
|
|
|
|
`./assets/js/blocks/${ config.customDir || blockCode }/` +
|
|
|
|
relativePath
|
|
|
|
);
|
|
|
|
if ( filePaths.length > 0 ) {
|
|
|
|
return [ blockCode, filePaths ];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} )
|
|
|
|
.filter( Boolean )
|
|
|
|
);
|
|
|
|
};
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2020-07-22 12:05:56 +00:00
|
|
|
const entries = {
|
|
|
|
styling: {
|
2020-07-07 09:05:06 +00:00
|
|
|
// @wordpress/components styles
|
|
|
|
'custom-select-control-style':
|
|
|
|
'./node_modules/wordpress-components/src/custom-select-control/style.scss',
|
|
|
|
'spinner-style':
|
|
|
|
'./node_modules/wordpress-components/src/spinner/style.scss',
|
|
|
|
'snackbar-notice-style':
|
|
|
|
'./node_modules/wordpress-components/src/snackbar/style.scss',
|
2021-08-12 16:30:42 +00:00
|
|
|
'combobox-control-style':
|
|
|
|
'./node_modules/wordpress-components/src/combobox-control/style.scss',
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2020-07-22 12:05:56 +00:00
|
|
|
'general-style': glob.sync( './assets/**/*.scss', {
|
|
|
|
ignore: [
|
|
|
|
// Block styles are added below.
|
|
|
|
'./assets/js/blocks/*/*.scss',
|
|
|
|
],
|
|
|
|
} ),
|
|
|
|
|
2021-01-07 12:02:21 +00:00
|
|
|
'packages-style': glob.sync( './packages/**/*.scss' ),
|
|
|
|
|
2020-07-29 14:07:21 +00:00
|
|
|
'reviews-style': './assets/js/blocks/reviews/editor.scss',
|
2020-07-22 12:05:56 +00:00
|
|
|
...getBlockEntries( '**/*.scss' ),
|
|
|
|
},
|
|
|
|
core: {
|
|
|
|
wcBlocksRegistry: './assets/js/blocks-registry/index.js',
|
2021-04-22 11:37:27 +00:00
|
|
|
wcSettings: './assets/js/settings/shared/index.ts',
|
2021-08-13 13:28:41 +00:00
|
|
|
wcBlocksData: './assets/js/data/index.ts',
|
2020-07-22 12:05:56 +00:00
|
|
|
wcBlocksMiddleware: './assets/js/middleware/index.js',
|
2021-06-09 14:09:42 +00:00
|
|
|
wcBlocksSharedContext: './assets/js/shared/context/index.js',
|
|
|
|
wcBlocksSharedHocs: './assets/js/shared/hocs/index.js',
|
2021-02-04 15:30:28 +00:00
|
|
|
priceFormat: './packages/prices/index.js',
|
2021-01-11 12:12:26 +00:00
|
|
|
blocksCheckout: './packages/checkout/index.js',
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
|
|
|
main: {
|
|
|
|
// Shared blocks code
|
2021-06-09 14:09:42 +00:00
|
|
|
'wc-blocks': './assets/js/index.js',
|
2020-07-07 09:05:06 +00:00
|
|
|
|
|
|
|
// Blocks
|
2021-06-09 14:09:42 +00:00
|
|
|
...getBlockEntries( 'index.{t,j}s{,x}' ),
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
frontend: {
|
|
|
|
reviews: './assets/js/blocks/reviews/frontend.js',
|
2021-06-09 14:09:42 +00:00
|
|
|
...getBlockEntries( 'frontend.{t,j}s{,x}' ),
|
2021-08-25 15:42:55 +00:00
|
|
|
'mini-cart-component':
|
|
|
|
'./assets/js/blocks/cart-checkout/mini-cart/component-frontend.tsx',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
payments: {
|
|
|
|
'wc-payment-method-stripe':
|
|
|
|
'./assets/js/payment-method-extensions/payment-methods/stripe/index.js',
|
|
|
|
'wc-payment-method-cheque':
|
|
|
|
'./assets/js/payment-method-extensions/payment-methods/cheque/index.js',
|
|
|
|
'wc-payment-method-paypal':
|
|
|
|
'./assets/js/payment-method-extensions/payment-methods/paypal/index.js',
|
2020-07-08 00:39:16 +00:00
|
|
|
'wc-payment-method-bacs':
|
|
|
|
'./assets/js/payment-method-extensions/payment-methods/bacs/index.js',
|
2020-07-15 14:14:41 +00:00
|
|
|
'wc-payment-method-cod':
|
|
|
|
'./assets/js/payment-method-extensions/payment-methods/cod/index.js',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
2021-03-16 11:40:22 +00:00
|
|
|
extensions: {
|
|
|
|
'wc-blocks-google-analytics':
|
|
|
|
'./assets/js/extensions/google-analytics/index.ts',
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getEntryConfig = ( type = 'main', exclude = [] ) => {
|
2020-07-22 12:05:56 +00:00
|
|
|
return omit( entries[ type ], exclude );
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getEntryConfig,
|
|
|
|
};
|