2019-02-12 20:02:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Generates an array of feature flags, based on the config used by the client application.
|
|
|
|
*
|
|
|
|
* @package WooCommerce Admin
|
|
|
|
*/
|
|
|
|
|
|
|
|
$phase = isset( $_SERVER['WC_ADMIN_PHASE'] ) ? $_SERVER['WC_ADMIN_PHASE'] : ''; // WPCS: sanitization ok.
|
2019-04-11 18:31:31 +00:00
|
|
|
if ( ! in_array( $phase, array( 'development', 'plugin', 'core' ), true ) ) {
|
2019-04-15 12:25:14 +00:00
|
|
|
$phase = 'development';
|
2019-02-12 20:02:02 +00:00
|
|
|
}
|
|
|
|
$config_json = file_get_contents( 'config/' . $phase . '.json' );
|
|
|
|
$config = json_decode( $config_json );
|
|
|
|
|
2019-04-11 18:31:31 +00:00
|
|
|
|
|
|
|
if ( 'core' !== $phase ) {
|
|
|
|
$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 .= "function wc_admin_get_feature_config() {\n";
|
|
|
|
$write .= "\treturn array(\n";
|
|
|
|
foreach ( $config->features as $feature => $bool ) {
|
|
|
|
$write .= "\t\t'{$feature}' => " . ( $bool ? 'true' : 'false' ) . ",\n";
|
|
|
|
}
|
|
|
|
$write .= "\t);\n";
|
|
|
|
$write .= "}\n";
|
|
|
|
|
|
|
|
$config_file = fopen( 'includes/feature-config.php', 'w' );
|
|
|
|
} else {
|
|
|
|
$write = "\t\t\tarray(\n";
|
|
|
|
foreach ( $config->features as $feature => $bool ) {
|
|
|
|
if ( true === $bool ) {
|
|
|
|
$write .= "\t\t\t\t'{$feature}',\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$write .= "\t\t\t)";
|
|
|
|
|
2019-04-24 16:50:30 +00:00
|
|
|
if ( ! is_dir( './dist' ) && ! @mkdir( './dist' ) ) {
|
|
|
|
echo 'Run `npm run clean` to wipe artifacts.';
|
2019-04-15 12:25:14 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
2019-04-11 18:31:31 +00:00
|
|
|
$config_file = fopen( 'dist/feature-config-core.php', 'w' );
|
2019-02-12 20:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fwrite( $config_file, $write );
|
|
|
|
fclose( $config_file );
|