From c7e492ae8a94a306bef666721f6cbd5ad05392d7 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Fri, 2 Sep 2022 07:09:50 +0300 Subject: [PATCH] Updated "export" logic on WordPress/PHP platforms. --- .gitignore | 1 + build.js | 2 +- package-lock.json | 2 +- package.json | 2 +- platforms/php/build.php | 21 +++++++++++++++++---- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d7eed0b..c3d3dd0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ blocks config data src +exports diff --git a/build.js b/build.js index a3e652e..9eccfbc 100755 --- a/build.js +++ b/build.js @@ -16,7 +16,7 @@ class buildGenerator extends Generator { type: "list", name: "platform", message: "Choose Platform", - choices: ['WordPress', 'Hubspot', 'JavaScript', 'PHP'], + choices: ['WordPress', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'], default: 'WordPress' } ]) diff --git a/package-lock.json b/package-lock.json index 3918509..25c7def 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "create-block-dev-tool", - "version": "1.0.5", + "version": "1.0.6", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 0cc38dc..ce24d95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-block-dev-tool", - "version": "1.0.5", + "version": "1.0.6", "scripts": { "start": "component-dev", "dev": "NODE_ENV=development node server.js", diff --git a/platforms/php/build.php b/platforms/php/build.php index c3c1eb5..4ac3818 100644 --- a/platforms/php/build.php +++ b/platforms/php/build.php @@ -3,7 +3,6 @@ // Composer - Autoloader require_once __DIR__ . '/vendor/autoload.php'; -use JetBrains\PhpStorm\NoReturn; use LightnCandy\Flags; use LightnCandy\LightnCandy; @@ -61,9 +60,23 @@ class Component_Builder { $this->register_default_handlebar_helpers(); } - #[NoReturn] - function build() { - $file_name = $this->get_handlebars_template( __DIR__ . '/' . $this->module_path . '/../../src/' . $this->component_name . '.template.hbs' ); + function build(): void { + $root_path = __DIR__ . '/' . $this->module_path . '../..'; + $file_name = $this->get_handlebars_template( "$root_path/src/$this->component_name.template.hbs" ); + + $output_folder = $root_path . '/exports/wordpress/templates'; + foreach ( [ 'styles', 'scripts', 'images' ] as $dir ) { + $output_dir = "$output_folder/$dir"; + if ( is_dir( $output_dir ) === false ) { + mkdir( $output_dir, 0777, true ); + } + } + + rename( $file_name, "$output_folder/$this->component_name.template.php" ); + copy( "$root_path/src/styles/$this->component_name.min.css", "$output_folder/styles/$this->component_name.min.css" ); + copy( "$root_path/src/scripts/$this->component_name.min.js", "$output_folder/scripts/$this->component_name.min.js" ); + shell_exec( "cp -r $root_path/src/images $output_folder" ); + echo "Generated '$file_name'."; }