Compare commits

...

11 Commits

  1. 9
      build.js
  2. 4
      package-lock.json
  3. 8
      package.json
  4. 40
      platforms/wordpress/templates/Template_Basic_Component.php
  5. 62
      platforms/wordpress/templates/Template_Component.php
  6. 14
      platforms/wordpress/templates/helpers/Template_API.php
  7. 17
      platforms/wordpress/templates/helpers/Template_Defaults.php
  8. 8
      platforms/wordpress/templates/helpers/Template_Elementor_Widget.php
  9. 65
      platforms/wordpress/wordpress-adapter.js
  10. 6
      server.js

9
build.js

@ -9,17 +9,8 @@ const {isDev, developmentBlockName} = getConfigs();
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName; const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
export const PLATFORM_OPTIONS = [{ export const PLATFORM_OPTIONS = [{
name: 'wordpress-acf-block',
title: 'WordPress AFC Block'
}, {
name: 'wordpress', name: 'wordpress',
title: 'WordPress' title: 'WordPress'
}, {
name: 'wordpress-component-manager',
title: 'WordPress (Component Manager)'
}, {
name: 'wordpress-elementor',
title: 'WordPress Elementor'
}, { }, {
name: 'hubspot', name: 'hubspot',
title: 'Hubspot' title: 'Hubspot'

4
package-lock.json

@ -1,12 +1,12 @@
{ {
"name": "@axe-web/block-dev-tool", "name": "@axe-web/block-dev-tool",
"version": "1.0.31", "version": "1.0.32",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@axe-web/block-dev-tool", "name": "@axe-web/block-dev-tool",
"version": "1.0.31", "version": "1.0.32",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@axe-web/create-block": "^1.1.30", "@axe-web/create-block": "^1.1.30",

8
package.json

@ -1,15 +1,15 @@
{ {
"name": "@axe-web/block-dev-tool", "name": "@axe-web/block-dev-tool",
"version": "1.0.31", "version": "1.0.32",
"author": { "author": {
"name": "AXE-WEB", "name": "AXE-WEB",
"email": "office@axe-web.com", "email": "office@axe-web.com",
"url": "https://axe-web.com/" "url": "https://axe-web.com/"
}, },
"scripts": { "scripts": {
"info": "BLOCK_NAME=swiper-test MODULE_PATH= node debug.js", "info": "BLOCK_NAME=ebooks-resources MODULE_PATH= node debug.js",
"dev": "BLOCK_NAME=swiper-test MODULE_PATH= node server.js", "dev": "BLOCK_NAME=ebooks-resources MODULE_PATH= node server.js",
"build-platform": "BLOCK_NAME=swiper-test MODULE_PATH= node ./build.js", "build-platform": "BLOCK_NAME=ebooks-resources MODULE_PATH= node ./build.js",
"dev-dev-tool": "rollup --config rollup.config.js --watch", "dev-dev-tool": "rollup --config rollup.config.js --watch",
"build-dev-tool": "rollup --config rollup.config.js" "build-dev-tool": "rollup --config rollup.config.js"
}, },

40
platforms/wordpress/templates/Template_Basic_Component.php

@ -2,19 +2,13 @@
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>; namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{ class <%= blockClassModel %>_Component extends \Core\Component {
const VERSION = '<%= version %>'; const VERSION = '<%= version %>';
public $block_project = '<%= ownerFilename %>'; public $block_project = '<%= ownerFilename %>';
public $block_name = '<%= blockFilename %>'; public $block_name = '<%= blockFilename %>';
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>'; public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
<% if (!isComponentManager && !isElementor) { %>public function __construct() { function register_assets(): void {
parent::__construct();
// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
add_action( 'after_setup_theme', [ $this, 'register_assets' ] );
}
<% } %>function register_assets(): void {
$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
@ -22,12 +16,14 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', $style_deps, self::VERSION ); wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', $style_deps, self::VERSION );
$script_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::script_deps', [ 'assets-script' ] ); $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) { %> wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', $script_deps, self::VERSION, true );
}
public function prepare_for_print() {
if ( ! is_admin() ) { 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 {
@ -38,7 +34,7 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class ); $output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output ); return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output );
}<% if (isElementor) { %> }
function register_custom_logic(): void { function register_custom_logic(): void {
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] ); add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] );
@ -47,9 +43,25 @@ 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() );
}<% } %> }
function register_acf_block() {
$this->register_block( __DIR__ . "/<%= blockFilename %>.block.json", [
'style_assets' => [
[
'name' => 'block-<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/styles/<%= blockFilename %>.min.css' ),
]
],
'script_assets' => [
[
'name' => 'block-<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/scripts/<%= blockFilename %>.min.js' ),
]
]
] );
}
} }
<% if (isComponentManager) { %><%= blockClassModel %>_Component::get_instance();<% } else { <%= blockClassModel %>_Component::get_instance();
%>new <%= blockClassModel %>_Component();<% } %> // new <%= blockClassModel %>_Component();

62
platforms/wordpress/templates/Template_Component.php

@ -1,62 +0,0 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
class <%= blockClassModel %>_Component extends \Core\Component {
const VERSION = '<%= version %>';
public $block_project = '<%= ownerFilename %>';
public $block_name = '<%= blockFilename %>';
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.
$args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::prepare_args', array_merge( $default_args, $args ) );
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output );
}
<% if (!include_acf_block && !include_native_gutenberg_block) { %>function register_assets(): void {
$version = get_plugin_data( __DIR__ . "/../../scytale-custom-blocks.php" )['Version']; // In Plugins
// $version = \Core\Global_Functions::get_current_version_number(); // In Theme
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/';
wp_enqueue_style( 'block-<%= blockFilename %>', $this->get_assets_path_url( 'templates/styles/<%= blockFilename %>.min.css' ), ['assets-style'], self::VERSION );<% if (include_script) { %>
wp_enqueue_script( 'block-<%= blockFilename %>', $this->get_assets_path_url( 'templates/scripts/<%= blockFilename %>.min.js' ), ['assets-script'], self::VERSION, true );<% } %>
wp_enqueue_script( 'script-block-<%= blockFilename %>' );
}<% } %>
<% if (include_acf_block) { %> function register_acf_block() {
$this->register_block( __DIR__ . "/<%= blockFilename %>.block.json", [
'style_assets' => [
[
'name' => '<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/styles/<%= blockFilename %>.min.css' ),
]
],
'script_assets' => [
[
'name' => '<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/scripts/<%= blockFilename %>.min.js' ),
]
]
] );
}
<% } %><% if (include_native_gutenberg_block) { %> function register_native_gutenberg_block() {
register_block_type( __DIR__ . '/templates/gutenberg-block/block.json' );<% if (include_script) { %>
add_action( 'wp_enqueue_scripts', function () {
$asset_file_front = include( plugin_dir_path( __FILE__ ) . '/templates/gutenberg-block/build/front.asset.php' );
wp_enqueue_script(
'gutenberg-<%= blockFilename %>-scripts-front',
$this->get_assets_path_url( 'templates/gutenberg-block/build/front.js' ),
$asset_file_front['dependencies'],
$asset_file_front['version'],
true
);
} );<% } %>
}<% } %>
}
<%= blockClassModel %>_Component::get_instance();

14
platforms/wordpress/templates/helpers/Template_API.php

@ -1,14 +0,0 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
class <%= blockClassModel %>_API {
static function prepare_args( $args = [] ) {
// $args = array_merge( [], $args );
return $args;
}
}

17
platforms/wordpress/templates/helpers/Template_Defaults.php

@ -1,17 +0,0 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
/**
* Component's default args.
*/
class <%= blockClassModel %>_Defaults {
public static function default_args(): array {
$args = <%- defaultData %>;
// $args['base_url'] = \Core\Global_Functions::get_file_url( __DIR__ . '/../templates/' );
return $args;
}
}

8
platforms/wordpress/templates/helpers/Template_Elementor_Widget.php

@ -3,6 +3,8 @@
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers; namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base { class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base {
use \Core\Traits\Elementor_Widget;
const PLUGIN_NAME = '<%= blockFilename %>'; const PLUGIN_NAME = '<%= blockFilename %>';
public function get_name() { public function get_name() {
@ -35,12 +37,8 @@ class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base {
$component = new \AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\<%= blockClassModel %>_Component(); $component = new \AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\<%= blockClassModel %>_Component();
$args = self::prepare( $settings ); $args = $this->prepare( $settings );
$component->render( $args ); $component->render( $args );
} }
public static function prepare( $args ): array {
// Prepare $args for render function.
return $args;
}
} }

65
platforms/wordpress/wordpress-adapter.js

@ -10,10 +10,6 @@ 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.platform === 'wordpress-acf-block';
const isElementor = args.platform === 'wordpress-elementor';
const isComponentManager = args.platform === 'wordpress-component-manager'
const {modulesPath, projectPath} = getConfigs(); const {modulesPath, projectPath} = getConfigs();
const distPath = path.join(projectPath, 'exports', args.platform); const distPath = path.join(projectPath, 'exports', args.platform);
@ -37,12 +33,7 @@ export async function buildWordPress(blockName, args = {}) {
ownerClass: owner.replace(/ /ig, '_'), ownerClass: owner.replace(/ /ig, '_'),
ownerFilename: owner.toLowerCase().replace(/ /ig, '-'), ownerFilename: owner.toLowerCase().replace(/ /ig, '-'),
templateFormat: 'php', templateFormat: 'php',
include_acf_block: isBlock,
include_native_gutenberg_block: false,
include_script: true, include_script: true,
include_elementor_widget: isElementor,
isElementor,
isComponentManager,
}); });
await copyFile(blockFilePath, path.join(distPath, data.blockFilename + '.block.json')); await copyFile(blockFilePath, path.join(distPath, data.blockFilename + '.block.json'));
@ -84,49 +75,21 @@ export async function buildWordPress(blockName, args = {}) {
json: await readJSONFile(path.join(projectPath, 'data', 'default.json'), "utf8"), json: await readJSONFile(path.join(projectPath, 'data', 'default.json'), "utf8"),
}); });
// await createFiles(Object.assign({}, data, {defaultData: phpDataObject}), [{ await createFiles(data, [{
// from: `templates/helpers/Template_Defaults.php`, from: `templates/helpers/Template_Elementor_Widget.php`,
// to: `helpers/${data.blockClassModel}_Defaults.php`, to: `helpers/${data.blockClassModel}_Elementor_Widget.php`,
// }], { }], {
// pathDist: distPath, pathDist: distPath,
// generatorsPath: path.join(__dirname), generatorsPath: path.join(__dirname)
// }); });
if (isElementor) {
await createFiles(data, [{
from: `templates/helpers/Template_Elementor_Widget.php`,
to: `helpers/${data.blockClassModel}_Elementor_Widget.php`,
}], {
pathDist: distPath,
generatorsPath: path.join(__dirname)
});
}
if (isBlock) {
await createFiles(data, [{
from: `templates/Template_Component.php`,
to: `${data.blockClassModel}_Component.php`,
}], {
pathDist: distPath,
generatorsPath: path.join(__dirname)
});
// await createFiles(data, [{ await createFiles(data, [{
// from: `templates/helpers/Template_API.php`, from: `templates/Template_Basic_Component.php`,
// to: `helpers/${data.blockClassModel}_API.php`, to: `${data.blockClassModel}_Component.php`,
// }], { }], {
// pathDist: distPath, pathDist: distPath,
// generatorsPath: path.join(__dirname) generatorsPath: path.join(__dirname)
// }); });
} else {
await createFiles(data, [{
from: `templates/Template_Basic_Component.php`,
to: `${data.blockClassModel}_Component.php`,
}], {
pathDist: distPath,
generatorsPath: path.join(__dirname)
});
}
} }
export function execCommand(cmd = '') { export function execCommand(cmd = '') {

6
server.js

@ -38,7 +38,7 @@ import {
import PluginError from 'plugin-error'; import PluginError from 'plugin-error';
import {Server} from "socket.io"; import {Server} from "socket.io";
import {createServer} from 'http'; import {createServer} from 'http';
import {authtoken, connect} from "ngrok"; // import {authtoken, connect} from "ngrok";
import bodyParser from "body-parser"; import bodyParser from "body-parser";
/** /**
@ -569,8 +569,8 @@ async function getShareableUrl() {
let url; let url;
try { try {
await authtoken(data.ngrokApiToken); // await authtoken(data.ngrokApiToken);
url = await connect(port); // url = await connect(port);
} catch (e) { } catch (e) {
console.log('Error:', `Can't connect to ngrok, probably wrong token.`); console.log('Error:', `Can't connect to ngrok, probably wrong token.`);
} }

Loading…
Cancel
Save