Browse Source

- Update export dir of wordpress projects.

test-gpt-generated
Roman Axelrod 3 years ago
parent
commit
3a78aee088
  1. 10
      helpers.js
  2. 6
      package.json
  3. 27
      platforms/php/build.php
  4. 26
      platforms/wordpress/templates/Template_Basic_Component.php
  5. 1
      platforms/wordpress/templates/Template_Component.php
  6. 15
      platforms/wordpress/wordpress-adapter.js

10
helpers.js

@ -156,15 +156,7 @@ export async function zipProject(srcDir, outputFileName = 'dist.zip') {
export async function buildExportFiles(blockName, platform) { export async function buildExportFiles(blockName, platform) {
if (platform.name.startsWith('wordpress')) { if (platform.name.startsWith('wordpress')) {
if (platform.name === 'wordpress-acf-block') { await buildWordPress(blockName, {platform: platform.name});
await buildWordPress(blockName, {block: true});
} else if (platform.name === 'wordpress-elementor') {
await buildWordPress(blockName, {elementor: true});
} else if (platform.name === 'wordpress-component-manager') {
await buildWordPress(blockName, {componentManager: true});
} else {
await buildWordPress(blockName);
}
} else if (platform.name === 'hubspot-email') { } else if (platform.name === 'hubspot-email') {
await buildHubspotEmail(blockName) await buildHubspotEmail(blockName)
} else if (platform.name === 'hubspot') { } else if (platform.name === 'hubspot') {

6
package.json

@ -7,9 +7,9 @@
"url": "https://axe-web.com/" "url": "https://axe-web.com/"
}, },
"scripts": { "scripts": {
"info": "NODE_ENV=development BLOCK_NAME=header MODULE_PATH= node debug.js", "info": "NODE_ENV=development BLOCK_NAME=drinks-slider MODULE_PATH= node debug.js",
"dev": "NODE_ENV=development BLOCK_NAME=header MODULE_PATH= node server.js", "dev": "NODE_ENV=development BLOCK_NAME=drinks-slider MODULE_PATH= node server.js",
"build-platform": "NODE_ENV=development BLOCK_NAME=header MODULE_PATH= node ./build.js", "build-platform": "NODE_ENV=development BLOCK_NAME=drinks-slider MODULE_PATH= node ./build.js",
"dev-dev-tool": "NODE_ENV=development rollup --config rollup.config.js --watch", "dev-dev-tool": "NODE_ENV=development rollup --config rollup.config.js --watch",
"build-dev-tool": "rollup --config rollup.config.js" "build-dev-tool": "rollup --config rollup.config.js"
}, },

27
platforms/php/build.php

@ -11,7 +11,7 @@ use Brick\VarExporter\VarExporter;
trait Custom_Handlebars { trait Custom_Handlebars {
public array $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 ) { $this->add_handlebar( 'esc_url', function ( $context ) {
if ( function_exists( 'esc_url' ) ) { if ( function_exists( 'esc_url' ) ) {
return esc_url( $context ); 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; $this->custom_handlebars[ $key ] = $func;
} }
} }
@ -56,11 +56,14 @@ class Component_Builder {
public string $component_name = ''; public string $component_name = '';
public string $module_path = ''; public string $module_path = '';
public string $project_path = ''; public string $project_path = '';
private string $dist_path = '';
function __construct( $component_name, $module_path, $project_path ) { function __construct( $args = [] ) {
$this->module_path = $module_path; $this->module_path = $args['backPath'];
$this->project_path = $project_path; $this->project_path = $args['projectPath'];
$this->component_name = $component_name; $this->component_name = $args['blockName'];
$this->dist_path = __DIR__ . '/' . $this->module_path . '../../' . $this->project_path . '/exports' . '/' . $args['platform'];
$this->register_default_handlebar_helpers(); $this->register_default_handlebar_helpers();
} }
@ -70,10 +73,10 @@ class Component_Builder {
$this->buildTemplatePhpFile( $root_path ); $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" ); $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" ); 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();
} }
/** /**

26
platforms/wordpress/templates/Template_Basic_Component.php

@ -3,12 +3,11 @@
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>; namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{
const VERSION = '<%= version %>';<% if (isComponentManager) { %> const VERSION = '<%= version %>';
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';<% } %>
<% if (!isComponentManager) { %>public function __construct() { <% if (!isComponentManager && !isElementor) { %>public function __construct() {
<% if (isElementor) { %>parent::__construct(); parent::__construct();
<% } %>// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] ); // add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
add_action( 'after_setup_theme', [ $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 = plugin_dir_url( __FILE__ ); // In Plugins
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/'; // In Theme // $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 ); $style_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::style_deps', [ 'assets-style' ] );
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', [ 'assets-script' ], self::VERSION, true ); 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_style( 'block-<%= blockFilename %>' );
wp_enqueue_script( 'block-<%= blockFilename %>' ); wp_enqueue_script( 'block-<%= blockFilename %>' );
} }<% } %>
} }
public function get_content( $args = [] ): string { public function get_content( $args = [] ): string {
@ -40,9 +42,9 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
} }
function register_elementor_widget( $widgets_manager ): void { function register_elementor_widget( $widgets_manager ): void {
require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php"; require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php";
$widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() ); $widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() );
} }
<% } %> <% } %>
} }

1
platforms/wordpress/templates/Template_Component.php

@ -4,7 +4,6 @@ namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
class <%= blockClassModel %>_Component extends \Core\Component { class <%= blockClassModel %>_Component extends \Core\Component {
const VERSION = '<%= version %>'; const VERSION = '<%= version %>';
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
public function get_content( $args = [] ): string { public function get_content( $args = [] ): string {
$default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical. $default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical.

15
platforms/wordpress/wordpress-adapter.js

@ -10,13 +10,13 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
export async function buildWordPress(blockName, args = {}) { export async function buildWordPress(blockName, args = {}) {
const isBlock = !!args.block; const isBlock = args.platform === 'wordpress-acf-block';
const isElementor = !!args.elementor; const isElementor = args.platform === 'wordpress-elementor';
const isComponentManager = !!args.componentManager; const isComponentManager = args.platform === 'wordpress-component-manager'
const {modulesPath, projectPath} = getConfigs(); 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(distPath, {recursive: true})
await mkdir(path.join(distPath, 'templates'), {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'); const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
await execCommand(`cd ${phpGeneratorPath} && composer install`); 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( await copyStaticFile(
path.join(projectPath, 'src', 'styles', `${data.blockFilename}.min.css`), path.join(projectPath, 'src', 'styles', `${data.blockFilename}.min.css`),

Loading…
Cancel
Save