Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Introduce feature flags #1631

Merged
merged 24 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ tests/cli/vendor
bin/languages
woocommerce-gutenberg-products-block.zip
storybook-static/
blocks.ini
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,32 @@ jobs:
php: 7.1
env:
- WP_VERSION=latest
- WOOCOMMERCE_BLOCKS_PHASE=experimental
script:
- phpunit
- name: PHP 5.6/unit-tests/Latest WP
php: 5.6
env:
- WP_VERSION=latest
- WOOCOMMERCE_BLOCKS_PHASE=experimental
script:
- phpunit
- name: PHP Linting Check
php: 7.1
env:
- WP_TRAVISCI=phpcs
- WOOCOMMERCE_BLOCKS_PHASE=experimental
script:
- npm run lint:php
- name: Javascript Tests
script:
- npm install
- npm run test
env:
- WOOCOMMERCE_BLOCKS_PHASE=experimental
- name: Javascript/CSS Lint and Bundle Size Check
script:
- npm install
- npm run build:ci
env:
- WOOCOMMERCE_BLOCKS_PHASE=experimental
8 changes: 6 additions & 2 deletions assets/js/blocks/cart-checkout/cart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import './style.scss';
/**
* Register and run the Cart block.
*/
registerBlockType( 'woocommerce/cart', {
const settings = {
title: __( 'Cart', 'woo-gutenberg-products-block' ),
icon: {
src: 'cart',
Expand Down Expand Up @@ -51,4 +51,8 @@ registerBlockType( 'woocommerce/cart', {
</div>
);
},
} );
};

if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
registerBlockType( 'woocommerce/cart', settings );
}
8 changes: 6 additions & 2 deletions assets/js/blocks/cart-checkout/checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import edit from './edit';
import { example } from './example';
import './editor.scss';

registerBlockType( 'woocommerce/checkout', {
const settings = {
title: __( 'Checkout', 'woo-gutenberg-products-block' ),
icon: {
// @todo: Replace this once we have an icon for the checkout
Expand Down Expand Up @@ -52,4 +52,8 @@ registerBlockType( 'woocommerce/checkout', {
</div>
);
},
} );
};

if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
registerBlockType( 'woocommerce/checkout', settings );
}
34 changes: 30 additions & 4 deletions bin/webpack-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extrac
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
const chalk = require( 'chalk' );
const { omit } = require( 'lodash' );

const { DefinePlugin } = require( 'webpack' );
const NODE_ENV = process.env.NODE_ENV || 'development';

function findModuleMatch( module, match ) {
Expand Down Expand Up @@ -95,7 +95,7 @@ const getAlias = ( options = {} ) => {
};
};

const mainEntry = {
const stableMainEntry = {
// Shared blocks code
blocks: './assets/js/index.js',

Expand Down Expand Up @@ -127,22 +127,36 @@ const mainEntry = {
'panel-style': './node_modules/@wordpress/components/src/panel/style.scss',
'custom-select-control-style':
'./node_modules/@wordpress/components/src/custom-select-control/style.scss',
};

// cart & checkout blocks
const experimentalMainEntry = {
Comment on lines -131 to +132
Copy link
Contributor

@nerrad nerrad Jan 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea to split out the stable from experimental configuration!

cart: './assets/js/blocks/cart-checkout/cart/index.js',
checkout: './assets/js/blocks/cart-checkout/checkout/index.js',
};

const frontEndEntry = {
const mainEntry =
process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental'
? { ...stableMainEntry, ...experimentalMainEntry }
: stableMainEntry;

const stableFrontEndEntry = {
reviews: './assets/js/blocks/reviews/frontend.js',
'all-products': './assets/js/blocks/products/all-products/frontend.js',
'price-filter': './assets/js/blocks/price-filter/frontend.js',
'attribute-filter': './assets/js/blocks/attribute-filter/frontend.js',
'active-filters': './assets/js/blocks/active-filters/frontend.js',
};

const experimentalFrontEndEntry = {
checkout: './assets/js/blocks/cart-checkout/checkout/frontend.js',
cart: './assets/js/blocks/cart-checkout/cart/frontend.js',
};

const frontEndEntry =
process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental'
? { ...stableFrontEndEntry, ...experimentalFrontEndEntry }
: stableFrontEndEntry;

const getEntryConfig = ( main = true, exclude = [] ) => {
const entryConfig = main ? mainEntry : frontEndEntry;
return omit( entryConfig, exclude );
Expand Down Expand Up @@ -305,6 +319,12 @@ const getMainConfig = ( options = {} ) => {
requestToExternal,
requestToHandle,
} ),
new DefinePlugin( {
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
),
} ),
],
resolve,
};
Expand Down Expand Up @@ -400,6 +420,12 @@ const getFrontConfig = ( options = {} ) => {
requestToExternal,
requestToHandle,
} ),
new DefinePlugin( {
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
),
} ),
],
resolve,
};
Expand Down
Loading