woocommerce/plugins/woocommerce-blocks/bin/webpack-entries.js

179 lines
5.0 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
const { omit } = require( 'lodash' );
const glob = require( 'glob' );
// 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 = {
'active-filters': {},
'add-to-cart-form': {},
'all-products': {
customDir: 'products/all-products',
},
'all-reviews': {
customDir: 'reviews/all-reviews',
},
'attribute-filter': {},
breadcrumbs: {},
cart: {},
'catalog-sorting': {},
checkout: {},
'customer-account': {},
'featured-category': {
customDir: 'featured-items/featured-category',
},
'featured-product': {
customDir: 'featured-items/featured-product',
},
'filter-wrapper': {},
'handpicked-products': {},
// We need to keep the legacy-template id, so we need to add a custom config to point to the renamed classic-template folder
'legacy-template': {
customDir: 'classic-template',
},
'mini-cart': {},
'mini-cart-contents': {
customDir: 'mini-cart/mini-cart-contents',
},
'store-notices': {},
'price-filter': {},
'product-best-sellers': {},
'product-category': {},
'product-categories': {},
'product-new': {},
'product-on-sale': {},
'product-query': {
isExperimental: true,
},
[Blockifying Product Archive Templates] Add Results Count block (https://github.com/woocommerce/woocommerce-blocks/pull/8078) * Init setup to add a new block Results Count * Render template part as a content of ResultsCount block * Switch to template part rendering * Rename the block to ProductResultsCount * Fix typo in BlockTypesController * Change the ProductResultsCount class name * Remove Product Results Count block from Product Query template * Improve the way Product Results Count is rendered in the editor * Add prefix to places that missed renaming from ResultsCount to ProductResultsCount * Remove unnecessary frontend.tsx file for ProductResultsCount * Make sure global styles are applied and respected by Product Results Count block * Make sure the Product Results Count is available inly in Product Catalog template * Add basic tests to Product Results Count * Remove empty line in style file * Fix TS issue in Product Results Count * Fix typo * Override the enqueue_assets method to prevent unnecessary enqueue and 404 error on the frontend * Add necessary property to block's metadata * Address code review feedback * Update description Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * Remove disabled component * Improve test description * Merge edit and block files * Remove align support * Remove background support * Simplify edit component * Improve readability with sprintf and add custom class * Simplify test case * Add styles and order placeholders Co-authored-by: Tung Du <dinhtungdu@gmail.com> * Fix markup to match with the frontend Co-authored-by: Tung Du <dinhtungdu@gmail.com> Co-authored-by: Alba Rincón <albarin@users.noreply.github.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> Co-authored-by: Alba Rincón <alba.rincon@automattic.com> Co-authored-by: Tung Du <dinhtungdu@gmail.com>
2023-01-17 15:19:42 +00:00
'product-results-count': {},
'product-search': {},
'product-tag': {},
'product-top-rated': {},
'products-by-attribute': {},
'rating-filter': {},
'reviews-by-category': {
customDir: 'reviews/reviews-by-category',
},
'reviews-by-product': {
customDir: 'reviews/reviews-by-product',
},
Add single product block (https://github.com/woocommerce/woocommerce-blocks/pull/8610) * Add block minimal structure * Add Single Product block icon * Add usesContext to block.json * Add Save function to Single Product Block registration settings * Add InnerBlocks template to Editor for Single Product Block * Add Product selector to Single Product block * Add withProduct HOC to the block editor * Add save function to the Single Product block * Add renderOnServerSide attribute to Product image This attribute is used to determine if the product image should be rendered on the server side or not. This is needed because the product image is not rendered on the server side by default, but we want to render it on the server side when it is inside the Single Product block. * Add renderOnServerSide attribute to Product Category List block * Add renderOnServerSide attribute to Product Price block * Add renderOnServerSide attribute to Product Rating block * Add renderOnServerSide attribute to Product Stock Indicator block * Add renderOnServerSide attribute to Product Summary block * Add renderOnServerSide attribute to Product Tag List block * Add renderOnServerSide attribute to Product Title block * Add renderOnServerSide attribute to Product Add to Cart, Sales Badge and Sku block * Reuse editor code for Single Product block * Add Props interface to Single Product Server Side Editor * Add render_block_context hook to SingleProductServerSide block * Fix Single Product Server Side block that was not appearing in the block inserter * Fix bug where the correct product was not being displayed on the frontend * Remove Single Product Block * Add Product title and product summary variations * Add Add To Cart Form and Product Meta blocks to the Single Product Block * remove more files that belong the Single Product block * fix php linter error * wrap up Single Product Block * Fix issue preventing the block from working on the Single Product Template * Fix update context function for Single Product block * Replace Single Product block title * Replace global $post only for Single Product inner blocks * Remove unnecessary var_dump statement * Improve documentation for the Single Product block * fix registration: add-to-cart-form and product-meta blocks * Improve documentation for Single Product block * Fix lint error related to imports * Remove query monitor debug code * Remove unnecessary `renderOnServerSide` attribute from product elements * Fix return type for the Save function of the Product Elements blocks * Fix return type for the Save function of the Product Title block * Add scss file for Single Product block * Fix PHP coding standards * Fix php coding standards * Remove internal dependencies section duplication * Replace .wc-block with .wc-block-editor- styles According to the naming convention for this project (https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/contributors/contributing/coding-guidelines.md#naming) we should be using the `.wc-block-editor-` prefix for styles that are only used in the editor. * Solve style for the Edit card component in the Single Product block * Fix error preventing Block Control from being displayed * Make the Product title to be a link by default * Fix PHP Coding Standards * Fix PHP Code Standards * Fix php cs issues * Fix issue with php cs * Remove unnecessary comment * Remove unused Icon import * Remove unnecessary dot from the className attributes in the Single Product Block * Replace metadata.name with metadata.title in the Editor file * Ignore phpcs rule * Add new attributes to the Attributes interface of the Price block * Fix typescript errors on the Product Meta block * Fix ts errors on Single Product editor * Fix ts errors on layout-editor.tsx * Fix ts errors in Single Product index file * Fix ts errors on add to cart form index file * Fix unsupported block error when using inner blocks outside the Single Product template * Fix unsupported block error for the Single Product block when editing Posts/Pages * Remove unnecessary JSDoc types * Remove unnecessary APIError component * Replace global $post only when rendering a `core/post-excerpt` block * Fix php cs errors * Put the Single Product block behind an experimental flag * Fix error occurring when trying to access ancestor of an undefined block settings * Remove JS Doc from shared-product-control.tsx * Fix single-product-frontend.js 404 error * Fix error 'Block names must be string' when adding Single Product block * Add todo comment to state the temporary solution used in the Single Product block * Move the wp_reset_postdata outside the block name check condition * Add comments about why we need to unregister the block on Single Product template --------- Co-authored-by: Luigi <gigitux@gmail.com>
2023-04-06 18:40:43 +00:00
'single-product': {
isExperimental: true,
},
'stock-filter': {},
Foundation of New Product Collection Block (https://github.com/woocommerce/woocommerce-blocks/pull/9352) * Add Products Collection block scaffolding This commit adds the initial scaffolding for the new Products Collection block. It includes the creation of new files (block.json, edit.tsx, index.tsx and ProductsCollection.php) and additions to existing files (webpack-entries.js and BlockTypesController.php). The block is marked as experimental and currently displays a static "Product collection" text in both the editor and the frontend. * Add Product Template block and integrate with Products Collection block This commit introduces the new Product Template block and integrates it with the existing Products Collection block. The changes include: - Creation of the Product Template block, including its block.json, edit.tsx, icon.tsx, index.tsx, and save.tsx files. - Modification of the Products Collection block, adding an icon.tsx file and updating its edit.tsx and index.tsx files. - Updates to the webpack-entries.js file to include the new Product Template block. - Addition of the ProductTemplate class in the src/BlockTypes directory. - Inclusion of the ProductTemplate class in the src/BlockTypesController.php file. * Enhance product-template block with context and styling This commit adds various enhancements to the product-template block. It includes: - Introduce `usesContext` and `supports` properties to the block.json file - Update the edit.tsx file to use BlockContextProvider and add query logic - Add an editor.scss file for styling the product-template block in the editor - Extend the products-collection block.json file with new properties - Modify the products-collection edit.tsx file to include instanceId and useEffect These changes improve the product-template block by providing better context handling and styling options. * Add 'woocommerce/product-template' to supported inner blocks and improve product-template editing This commit adds 'woocommerce/product-template' as a supported inner block for various product elements, including button, image, rating, sale-badge, SKU, and stock-indicator. It also improves the editing experience for the product-template block by memoizing the block previews and rendering them more efficiently. This should lead to a smoother editing experience and better performance in the block editor. * Add product title and summary variations for Products Collection block - Add default spacing between product elements in `style.scss` - Register product title and summary element variations in `products-collection` block - Create utility for registering element variations - Extend core elements with WooCommerce namespace * Set inherit to false by default and other improvements This commit introduces several changes to the ProductsCollection block: 1. Set the "inherit" property to false in block.json, disabling inheritance by default. 2. Remove the default styles for inner blocks in the edit.tsx file. 3. Add a save function in the index.tsx file, and create a save.tsx file to handle saving the block. 4. Update the ProductTemplate.php file to properly render the block content based on the changes. 5. Remove the render function from the ProductsCollection.php file, as it is no longer necessary. These changes improve the functionality and flexibility of the ProductsCollection block, allowing for better customization and control over the block's appearance and behavior. * Fix pagination issue * Minor code quality improvments * Register product blocks only in experimental builds - Wrap registerBlockType calls in product-template and products-collection with isExperimentalBuild check to enable block registration only in experimental builds. - Update the default value for the perPage property in products-collection/block.json from null to 9, setting a default display of 9 items per page. * Add experimental flag to PHP file * Update documentation for feature flags - Add Products Collection and Product Template blocks to the list of experimental flags in the feature-flags-and-experimental-interfaces.md file. - Include references to PHP and webpack flags for both blocks. * Change default order and orderBy values in block.json - Update the default 'order' value from 'desc' to 'asc'. - Update the default 'orderBy' value from 'date' to 'title'. * Refactor experimental block registration and remove unused file - Replace `isExperimentalBuild()` with `registerExperimentalBlockType()` in product-template/index.tsx. - Remove unused file types.ts in product-template directory. - Add `get_block_type_script()` function to ProductTemplate.php and ProductsCollection.php to return null. * Update variation names in product summary and product title elements Updated variation names for product summary and product title elements to match the new products-collection namespace. The previous variation names used the product-query namespace which will be deprecated. This change ensures that the correct variation names are used for these elements in the products-collection block. * Rename 'Products Collection' to 'Product Collection' - Renamed all instances of "products-collection" to "product-collection" across multiple files. - Adjusted related types and method calls to match the new naming convention. - Updated documentation and feature flags to reflect the name change. - Made necessary changes in `BlockTypesController.php` and `bin/webpack-entries.js`. * Hide product-template block from inserter - Added "woocommerce/product-collection" to the list of parent blocks in `product-template/block.json`. - Added `"inserter": false` to the "supports" section to disable the option of inserting this block through the editor inserter component. * Fix Eslint error
2023-05-15 08:51:49 +00:00
'product-collection': {
isExperimental: true,
},
'product-template': {
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 )
);
};
const entries = {
styling: {
// @wordpress/components styles
'custom-select-control-style':
'./node_modules/wordpress-components/src/custom-select-control/style.scss',
'snackbar-notice-style':
'./node_modules/wordpress-components/src/snackbar/style.scss',
'combobox-control-style':
'./node_modules/wordpress-components/src/combobox-control/style.scss',
'form-token-field-style':
'./node_modules/wordpress-components/src/form-token-field/style.scss',
'general-style': glob.sync( './assets/**/*.scss', {
ignore: [
// Block styles are added below.
'./assets/js/blocks/*/*.scss',
],
} ),
'packages-style': glob.sync( './packages/**/*.scss' ),
'reviews-style': './assets/js/blocks/reviews/editor.scss',
...getBlockEntries( '**/*.scss' ),
},
core: {
wcBlocksRegistry: './assets/js/blocks-registry/index.js',
Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) * BLOCK SETTINGS: Remove unused constants/settings * AssetDataRegistry: Helpers to check for settings that exist, and registering page ID/permalinks * Move checkout and cart block settings to checkout and cart blocktypes * Move isShippingCalculatorEnabled to cart block * Remove HAS_DARK_EDITOR_STYLE_SUPPORT and IS_SHIPPING_CALCULATOR_ENABLED in favour of getSetting * Move displayCartPricesIncludingTax to blocktypes, and implement getSetting * Move block settings to core settings and blocktypes * Fix namespace usage * Move review settings * move tag settings * Keep productCount in core data * Move min and default height * Improve storePages code * Move attributes to attribute filter block type * Move $word_count_type outside of settings array * Remove unneeded setting in preview data (shippingCostRequiresAddress) * Move min/max settings dependency from GridLayoutControl to Blocks themselves and use getSettings * DEFAULT_COLUMNS and ROWS to settings * Move product columns/rows to block types * Add grid settings to AllProducts block * Correct default rows * correct min rows default * Move hasDarkEditorStyleSupport * Move hideOutOfStockItems to block type settings * Move build settings to inline script dependency * Pass data through asset api and move restApiRoutes * Export all core settings as constants * Remove WORD_COUNT_TYPE from core settings * Move some other core settings to assets * Update constants * Make settings use TypeScript * Update CURRENT_USER_IS_ADMIN usage * WORD_COUNT_TYPE * REST_API_ROUTES * REVIEW_RATINGS_ENABLED and SHOW_AVATARS * Remove REVIEW_RATINGS_ENABLED and SHOW_AVATARS constants * Remove MIN_HEIGHT * Remove DEFAULT_HEIGHT * PLACEHOLDER_IMG_SRC * LIMIT_TAGS * HAS_PRODUCTS * HOME_URL * HAS_TAGS * COUPONS_ENABLED * SHIPPING_ENABLED * TAXES_ENABLED * DISPLAY_ITEMIZED_TAXES * SHIPPING_COST_REQUIRES_ADDRESS * SHIPPING_STATES and SHIPPING_COUNTRIES * STORE_PAGES * ALLOWED_COUNTRIES * ALLOWED_STATES * SHIPPING_METHODS_EXIST * PAYMENT_GATEWAY_SORT_ORDER * CHECKOUT_SHOW_LOGIN_REMINDER * CHECKOUT_ALLOWS_GUEST and CHECKOUT_ALLOWS_SIGNUP * ATTRIBUTES * DISPLAY_CART_PRICES_INCLUDING_TAX * DISPLAY_CART_PRICES_INCLUDING_TAX * update build for TS files * fix build dir * Move blocks build config params * Move placeholderImgSrc to core settings * Move rest api hydration hoc to shared hocs and provide it restApiRoutes directly to avoid asset data registration * Move wordCountType to abstract block * Remove WORD_COUNT_TYPE in favour of getSetting * Move IS_LARGE_CATALOG and PRODUCT_COUNT to abstract block type and use getSetting inline * Add wcBlocksConfig * fix tests * Remove unused $asset_data_registry * remove console.log * Move build settings to abstract block * Trigger build again * Move hydration back to regular hocs for compatibility with trunk (merge conflict) * Removed wcSharedHocsConfig * esc home url * Update search fixture * Update search snap * 40000 timeout * hasProducts -> productCount * Product Count is part of blocks config * update mocks * Use version comparison to determine if batching is enabled * Change isWpVersion * scrollTo button
2021-04-22 11:37:27 +00:00
wcSettings: './assets/js/settings/shared/index.ts',
wcBlocksData: './assets/js/data/index.ts',
wcBlocksMiddleware: './assets/js/middleware/index.js',
wcBlocksSharedContext: './assets/js/shared/context/index.js',
wcBlocksSharedHocs: './assets/js/shared/hocs/index.js',
priceFormat: './packages/prices/index.js',
blocksCheckout: './packages/checkout/index.js',
},
main: {
// Shared blocks code
'wc-blocks': './assets/js/index.js',
// Blocks
...getBlockEntries( 'index.{t,j}s{,x}' ),
},
frontend: {
reviews: './assets/js/blocks/reviews/frontend.js',
...getBlockEntries( 'frontend.{t,j}s{,x}' ),
'mini-cart-component':
'./assets/js/blocks/mini-cart/component-frontend.tsx',
},
payments: {
'wc-payment-method-cheque':
'./assets/js/extensions/payment-methods/cheque/index.js',
'wc-payment-method-paypal':
'./assets/js/extensions/payment-methods/paypal/index.js',
'wc-payment-method-bacs':
'./assets/js/extensions/payment-methods/bacs/index.js',
'wc-payment-method-cod':
'./assets/js/extensions/payment-methods/cod/index.js',
},
extensions: {
'wc-blocks-google-analytics':
'./assets/js/extensions/google-analytics/index.ts',
'wc-shipping-method-pickup-location':
'./assets/js/extensions/shipping-methods/pickup-location/index.js',
},
};
const getEntryConfig = ( type = 'main', exclude = [] ) => {
return omit( entries[ type ], exclude );
};
module.exports = {
getEntryConfig,
};