- 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
||||
|
||||
class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{
|
||||
const VERSION = '<%= version %>';<% if (isComponentManager) { %>
|
||||
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';<% } %>
|
||||
const VERSION = '<%= version %>';
|
||||
|
||||
<% if (!isComponentManager) { %>public function __construct() {
|
||||
<% if (isElementor) { %>parent::__construct();
|
||||
<% } %>// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
|
||||
<% if (!isComponentManager && !isElementor) { %>public function __construct() {
|
||||
parent::__construct();
|
||||
// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
|
||||
add_action( 'after_setup_theme', [ $this, 'register_assets' ] );
|
||||
}
|
||||
|
||||
@@ -16,13 +15,16 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
|
||||
$base_path = plugin_dir_url( __FILE__ ); // In Plugins
|
||||
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/'; // In Theme
|
||||
|
||||
wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', [ 'assets-style' ], self::VERSION );
|
||||
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', [ 'assets-script' ], self::VERSION, true );
|
||||
$style_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::style_deps', [ 'assets-style' ] );
|
||||
wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', $style_deps, self::VERSION );
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
$script_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::script_deps', [ 'assets-script' ] );
|
||||
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', $script_deps, self::VERSION, true );
|
||||
|
||||
<% if (!isElementor) { %>if ( ! is_admin() ) {
|
||||
wp_enqueue_style( 'block-<%= blockFilename %>' );
|
||||
wp_enqueue_script( 'block-<%= blockFilename %>' );
|
||||
}
|
||||
}<% } %>
|
||||
}
|
||||
|
||||
public function get_content( $args = [] ): string {
|
||||
@@ -40,9 +42,9 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
|
||||
}
|
||||
|
||||
function register_elementor_widget( $widgets_manager ): void {
|
||||
require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php";
|
||||
$widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() );
|
||||
}
|
||||
require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php";
|
||||
$widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() );
|
||||
}
|
||||
<% } %>
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
||||
|
||||
class <%= blockClassModel %>_Component extends \Core\Component {
|
||||
const VERSION = '<%= version %>';
|
||||
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
|
||||
|
||||
public function get_content( $args = [] ): string {
|
||||
$default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical.
|
||||
|
||||
@@ -10,13 +10,13 @@ const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export async function buildWordPress(blockName, args = {}) {
|
||||
const isBlock = !!args.block;
|
||||
const isElementor = !!args.elementor;
|
||||
const isComponentManager = !!args.componentManager;
|
||||
const isBlock = args.platform === 'wordpress-acf-block';
|
||||
const isElementor = args.platform === 'wordpress-elementor';
|
||||
const isComponentManager = args.platform === 'wordpress-component-manager'
|
||||
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
|
||||
const distPath = path.join(projectPath, 'exports', 'wordpress');
|
||||
const distPath = path.join(projectPath, 'exports', args.platform);
|
||||
// await mkdir(distPath, {recursive: true})
|
||||
await mkdir(path.join(distPath, 'templates'), {recursive: true})
|
||||
|
||||
@@ -51,7 +51,12 @@ export async function buildWordPress(blockName, args = {}) {
|
||||
|
||||
const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
|
||||
await execCommand(`cd ${phpGeneratorPath} && composer install`);
|
||||
await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'build', {blockName, backPath, projectPath});
|
||||
await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'build', {
|
||||
blockName,
|
||||
backPath,
|
||||
projectPath,
|
||||
platform: args.platform
|
||||
});
|
||||
|
||||
await copyStaticFile(
|
||||
path.join(projectPath, 'src', 'styles', `${data.blockFilename}.min.css`),
|
||||
|
||||
Reference in New Issue
Block a user