2019-02-12 20:02:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Generates an array of feature flags, based on the config used by the client application.
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin
|
2019-02-12 20:02:02 +00:00
|
|
|
*/
|
|
|
|
|
2019-04-26 18:37:39 +00:00
|
|
|
/**
|
|
|
|
* Get phase for feature flags
|
|
|
|
* - development: All features should be enabled in development.
|
|
|
|
* - plugin: For the standalone feature plugin, for GitHub and WordPress.org.
|
|
|
|
* - core: Stable features for WooCommerce core merge.
|
|
|
|
*/
|
2019-10-22 23:56:22 +00:00
|
|
|
|
|
|
|
$phase = getenv( 'WC_ADMIN_PHASE' );
|
2019-10-17 18:00:20 +00:00
|
|
|
|
2019-04-11 18:31:31 +00:00
|
|
|
if ( ! in_array( $phase, array( 'development', 'plugin', 'core' ), true ) ) {
|
2019-04-26 18:37:39 +00:00
|
|
|
$phase = 'plugin'; // Default to plugin when running `npm run build`.
|
2019-02-12 20:02:02 +00:00
|
|
|
}
|
|
|
|
$config_json = file_get_contents( 'config/' . $phase . '.json' );
|
|
|
|
$config = json_decode( $config_json );
|
|
|
|
|
2019-11-17 22:39:27 +00:00
|
|
|
$write = "<?php\n";
|
|
|
|
$write .= "// WARNING: Do not directly edit this file.\n";
|
|
|
|
$write .= "// This file is auto-generated as part of the build process and things may break.\n";
|
|
|
|
$write .= "if ( ! function_exists( 'wc_admin_get_feature_config' ) ) {\n";
|
|
|
|
$write .= "\tfunction wc_admin_get_feature_config() {\n";
|
|
|
|
$write .= "\t\treturn array(\n";
|
|
|
|
foreach ( $config->features as $feature => $bool ) {
|
|
|
|
$write .= "\t\t\t'{$feature}' => " . ( $bool ? 'true' : 'false' ) . ",\n";
|
2019-02-12 20:02:02 +00:00
|
|
|
}
|
2019-11-17 22:39:27 +00:00
|
|
|
$write .= "\t\t);\n";
|
|
|
|
$write .= "\t}\n";
|
|
|
|
$write .= "}\n";
|
|
|
|
|
|
|
|
$config_file = fopen( 'includes/feature-config.php', 'w' );
|
2019-02-12 20:02:02 +00:00
|
|
|
|
|
|
|
fwrite( $config_file, $write );
|
|
|
|
fclose( $config_file );
|