diff --git a/.env.dist b/.env.dist index 27ed36e..7805203 100644 --- a/.env.dist +++ b/.env.dist @@ -1,7 +1,12 @@ -# Basic Wordpress Data - +# ./local env vars DB_HOST=mysql DB_PORT=3306 DB_PASSWORD=p@55w0rd DB_NAME=wordpress DB_USER=root + +# wp-env env vars +WP_BASE_URL=http://localhost:8888 +WP_USERNAME=admin +WP_PASSWORD=password +WP_AUTH_STORAGE=.auth/wordpress.json diff --git a/.husky/pre-commit b/.husky/pre-commit index fdbbd24..417ae38 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,5 +2,6 @@ . "$(dirname -- "$0")/_/husky.sh" yarn lint:js && yarn test:js +yarn lint:css composer lint composer test:unit diff --git a/README.md b/README.md index e63e3c9..7a7b817 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,74 @@ [![JS lint & test](https://github.com/codebtech/wp-feature-flags/actions/workflows/js.yml/badge.svg)](https://github.com/codebtech/wp-feature-flags/actions/workflows/js.yml) [![E2E Tests](https://github.com/codebtech/wp-feature-flags/actions/workflows/e2e.yml/badge.svg)](https://github.com/codebtech/wp-feature-flags/actions/workflows/e2e.yml) -Contributors: Mohan Raj Pachaiyappan -Tags: feature-flags, feature-flag, wp-feature-flags -Requires at least: 6.2 -Tested up to: 6.4 -Stable tag: 1.0.0 -Requires PHP: 7.4 -Contributor link: https://github.com/m0hanraj +Feature flags allows developers to configure features in plugins/themes behind the feature flags on both Server(PHP) and Client(JS/TS) side.Feature flags allow developers to configure features in plugins/themes behind the feature flags on both the server (PHP) and client (JS/TS) side. -## Description +## Hooks -Feature flags allows developers to configure features behind the feature flags on both Server(PHP) and Client(JS/TS) side. +### JS Filters -## Frequently Asked Questions +##### mrFeatureFlags.newFlag.defaultStatus -### Does this plugin work with PHP 8? +The filter controls whether the new flag is enabled by default or not. Default `true` -Yes, it's actively tested and working up to PHP 8.3 +Example usage: -### Does this plugin work with latest WordPress? +```js +addFilter('mrFeatureFlags.newFlag.defaultStatus', 'mr-feature-flags', () => { + return false; +}); +``` -Yes, it's actively tested and working up to WordPress 6.4.3 +## Development setup + +To build the plugin + +PHP setup + +- `composer install` + +JS setup + +- `yarn install` +- `yarn build` to create the build +- `yarn start` to start the development watch mode + +## Linting and formatting + +PHP + +- `composer lint` +- To auto fix the linting errors `composer lint:fix` + +💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs) to auto format PHP files based on `phpcs.xml.dist` configuration + +JS + +- `yarn lint:js` + +💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) to auto format JS / TS files based on `.prettierrc` configuration + +CSS + +- `yarn lint:css` +- To auto fix the css linting errors `yarn lint:css:fix` + +## Testing + +### PHP + +- Run `./local` from your preferred CLI. Ensure you have Docker installed and running. +- The setup will automatically ssh into the container. +- To run unit tests `composer run test:unit` +- To run integrations tests `composer run test:integration` +- To run integrations tests as multisite `composer run test:multisite` + +### JS + +- Run `yarn test:js` which will run all jest and React Testing Library tests + +### E2E + +The E2E tests depends on `wp-env` setup. Ensure you run `wp-env start` before running the tests. + +- Run `yarn test:e2e` which will run all Playwright e2e tests. diff --git a/includes/Api/Flags.php b/includes/Api/Flags.php index be3eeb3..6f92946 100644 --- a/includes/Api/Flags.php +++ b/includes/Api/Flags.php @@ -3,7 +3,7 @@ * API class for feature flags options * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ declare(strict_types = 1); @@ -18,7 +18,7 @@ * Class Settings * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ class Flags { @@ -32,7 +32,7 @@ class Flags { /** * Register feature flag endpoints. * - * @since 1.0.0 + * @since 0.1.0 */ public function register(): void { add_action( @@ -44,7 +44,7 @@ public function register(): void { /** * Register routes. * - * * @since 1.0.0 + * * @since 0.1.0 */ public function register_routes(): void { register_rest_route( diff --git a/includes/Flag.php b/includes/Flag.php index 4c1a43f..1feabc0 100644 --- a/includes/Flag.php +++ b/includes/Flag.php @@ -3,7 +3,7 @@ * Utility class to expose flag methods. * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ declare(strict_types = 1); @@ -14,7 +14,7 @@ * Utils class for feature flags * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ class Flag { @@ -31,7 +31,7 @@ class Flag { * * @param string $flag name of the flag. * @return bool - * @since 1.0.0 + * @since 0.1.0 */ public static function is_enabled( string $flag ): bool { $flags = get_option( self::$option_name, [] ); diff --git a/includes/Helper.php b/includes/Helper.php index 3721ad0..e9f0bc3 100644 --- a/includes/Helper.php +++ b/includes/Helper.php @@ -3,7 +3,7 @@ * This is the init file for the plugin * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ declare(strict_types = 1); @@ -14,7 +14,7 @@ * Class FeatureFlags * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ class Helper { @@ -25,7 +25,7 @@ class Helper { * @param string $field field to search. * @param string $flag name of the flag. * @return boolean - * @since 1.0.0 + * @since 0.1.0 */ public function search_flag( $flags, $field, $flag ) { diff --git a/includes/Settings.php b/includes/Settings.php index 56c3309..d8bcd30 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -3,7 +3,7 @@ * Admin setting page for feature flags * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ declare(strict_types = 1); @@ -14,7 +14,7 @@ * Class Settings * * @package mr-feature-flags - * @since 1.0.0 + * @since 0.1.0 */ class Settings { @@ -22,7 +22,7 @@ class Settings { * Register feature flag settings page. * * @return void - * @since 1.0.0 + * @since 0.1.0 */ public function register_feature_settings() { add_action( 'admin_menu', [ $this, 'register_settings' ] ); @@ -32,7 +32,7 @@ public function register_feature_settings() { * Register settings action method. * * @return void - * @since 1.0.0 + * @since 0.1.0 */ public function register_settings() { diff --git a/package.json b/package.json index 46b8281..472f821 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,13 @@ { "name": "mr-feature-flags", - "version": "1.0.0", + "version": "0.1.0", "description": "Allows developers to enable / disable features based on flags.", "scripts": { "start": "wp-scripts start", "build": "wp-scripts build", "lint:js": "wp-scripts lint-js", + "lint:css": "wp-scripts lint-style", + "lint:css:fix": "npm run lint:css -- --fix", "test:js": "wp-scripts test-unit-js", "test:watch": "wp-scripts test-unit-js --watch", "prepare": "husky install", diff --git a/plugin.php b/plugin.php index f0cf939..4a2b7b7 100644 --- a/plugin.php +++ b/plugin.php @@ -2,13 +2,13 @@ /** * The plugin bootstrap file * - * @since 1.0.0 + * @since 0.1.0 * @package mr-feature-flags * * @wordpress-plugin * Plugin Name: Feature Flags * Description: Allows developers to enable / disable features based on flags. - * Version: 1.0.0 + * Version: 0.1.0 * Author: Mohan Raj * Author URI: https://mohanraj.dev * License: GPL-2.0+ diff --git a/src/styles/settings.scss b/src/styles/settings.scss index a693f16..48e9987 100644 --- a/src/styles/settings.scss +++ b/src/styles/settings.scss @@ -9,6 +9,7 @@ .feature-flag-snackbar { bottom: 3.5rem; position: fixed; + .components-snackbar__icon { left: 18px; top: auto; @@ -16,6 +17,7 @@ } .feature-flag-loader { + .components-spinner { width: 20px; height: 20px; @@ -40,7 +42,7 @@ } .mr-feature-flags-clipboard-base { - color: darkgray !important; + color: #a9a9a9 !important; float: right; position: relative; right: 40px;