- Update export dir of wordpress projects.
This commit is contained in:
+17
-10
@@ -11,7 +11,7 @@ use Brick\VarExporter\VarExporter;
|
||||
trait Custom_Handlebars {
|
||||
public array $custom_handlebars = [];
|
||||
|
||||
public function register_default_handlebar_helpers() {
|
||||
public function register_default_handlebar_helpers(): void {
|
||||
$this->add_handlebar( 'esc_url', function ( $context ) {
|
||||
if ( function_exists( 'esc_url' ) ) {
|
||||
return esc_url( $context );
|
||||
@@ -45,7 +45,7 @@ trait Custom_Handlebars {
|
||||
} );
|
||||
}
|
||||
|
||||
public function add_handlebar( $key, $func ) {
|
||||
public function add_handlebar( $key, $func ): void {
|
||||
$this->custom_handlebars[ $key ] = $func;
|
||||
}
|
||||
}
|
||||
@@ -56,11 +56,14 @@ class Component_Builder {
|
||||
public string $component_name = '';
|
||||
public string $module_path = '';
|
||||
public string $project_path = '';
|
||||
private string $dist_path = '';
|
||||
|
||||
function __construct( $component_name, $module_path, $project_path ) {
|
||||
$this->module_path = $module_path;
|
||||
$this->project_path = $project_path;
|
||||
$this->component_name = $component_name;
|
||||
function __construct( $args = [] ) {
|
||||
$this->module_path = $args['backPath'];
|
||||
$this->project_path = $args['projectPath'];
|
||||
$this->component_name = $args['blockName'];
|
||||
|
||||
$this->dist_path = __DIR__ . '/' . $this->module_path . '../../' . $this->project_path . '/exports' . '/' . $args['platform'];
|
||||
$this->register_default_handlebar_helpers();
|
||||
}
|
||||
|
||||
@@ -70,10 +73,10 @@ class Component_Builder {
|
||||
$this->buildTemplatePhpFile( $root_path );
|
||||
}
|
||||
|
||||
private function buildTemplatePhpFile( $root_path ) {
|
||||
private function buildTemplatePhpFile( $root_path, $platform = 'wordpress' ): void {
|
||||
$file_name = $this->get_handlebars_template( "$root_path/src/$this->component_name.template.hbs" );
|
||||
|
||||
$output_folder = $root_path . '/exports/wordpress/templates';
|
||||
$output_folder = $this->dist_path . '/templates';
|
||||
rename( $file_name, "$output_folder/$this->component_name.template.php" );
|
||||
}
|
||||
|
||||
@@ -121,8 +124,12 @@ class Component_Builder {
|
||||
}
|
||||
}
|
||||
|
||||
function build( $args = [] ) {
|
||||
( new Component_Builder( $args['blockName'], $args['backPath'], $args['projectPath'] ) )->build();
|
||||
/**
|
||||
* Functions below will be triggered by JavaScript (index.js).
|
||||
*/
|
||||
|
||||
function build( $args = [] ): void {
|
||||
( new Component_Builder( $args ) )->build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user