Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 92e4f1ea2d | |||
| 0062bb4506 | |||
| 5dd326be0f | |||
| bcad45d1e8 | |||
| 3daa725309 | |||
| 438619c4d9 | |||
| 1b2795fa40 | |||
| 31786581bd | |||
| e25f1aa4f1 | |||
| f3cd0e5876 | |||
| d6b0ff866b | |||
| 4a7ddf7d29 | |||
| 03a8833f46 | |||
| bf8f0e857d |
@@ -9,17 +9,8 @@ const {isDev, developmentBlockName} = getConfigs();
|
||||
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
||||
|
||||
export const PLATFORM_OPTIONS = [{
|
||||
name: 'wordpress-acf-block',
|
||||
title: 'WordPress AFC Block'
|
||||
}, {
|
||||
name: 'wordpress',
|
||||
title: 'WordPress'
|
||||
}, {
|
||||
name: 'wordpress-component-manager',
|
||||
title: 'WordPress (Component Manager)'
|
||||
}, {
|
||||
name: 'wordpress-elementor',
|
||||
title: 'WordPress Elementor'
|
||||
}, {
|
||||
name: 'hubspot',
|
||||
title: 'Hubspot'
|
||||
|
||||
+25
-38
@@ -126,46 +126,33 @@ export function capitalize(str) {
|
||||
export async function zipProject(srcDir, outputFileName = 'dist.zip') {
|
||||
// create a file to stream archive data to.
|
||||
const output = await fsExtra.createWriteStream(outputFileName);
|
||||
const archive = archiver('zip', {});
|
||||
|
||||
// listen for all archive data to be written
|
||||
// 'close' event is fired only when a file descriptor is involved
|
||||
output.on('close', function () {
|
||||
console.log(archive.pointer() + ' total bytes');
|
||||
console.log('archiver has been finalized and the output file descriptor has closed.');
|
||||
return new Promise((resolve, reject) => {
|
||||
// Create a file to write the archive data
|
||||
const archive = archiver('zip', {
|
||||
zlib: {level: 9} // Compression level
|
||||
});
|
||||
|
||||
// Listen for errors on the archiver
|
||||
archive.on('error', function (err) {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
// Handle closure of the output file stream
|
||||
output.on('close', function () {
|
||||
console.log(`Archive created successfully and it is ${archive.pointer()} total bytes`);
|
||||
resolve();
|
||||
});
|
||||
|
||||
// Pipe archive data to the file
|
||||
archive.pipe(output);
|
||||
|
||||
// Add files to the archive
|
||||
archive.directory(srcDir, false);
|
||||
|
||||
// Finalize the archive - this is very important to ensure the file stream is finished
|
||||
archive.finalize();
|
||||
});
|
||||
|
||||
// This event is fired when the data source is drained no matter what was the data source.
|
||||
// It is not part of this library but rather from the NodeJS Stream API.
|
||||
// @see: https://nodejs.org/api/stream.html#stream_event_end
|
||||
output.on('end', function () {
|
||||
console.log('Data has been drained');
|
||||
});
|
||||
|
||||
// good practice to catch warnings (ie stat failures and other non-blocking errors)
|
||||
archive.on('warning', function (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
// log warning
|
||||
} else {
|
||||
// throw error
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
// good practice to catch this error explicitly
|
||||
archive.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// pipe archive data to the file
|
||||
archive.pipe(output);
|
||||
|
||||
// append files from a subdirectory, putting its contents at the root of archive
|
||||
archive.directory(srcDir, false);
|
||||
|
||||
// finalize the archive (ie we are done appending files but streams have to finish yet)
|
||||
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
||||
await archive.finalize();
|
||||
}
|
||||
|
||||
export async function buildExportFiles(blockName, platform) {
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.31",
|
||||
"version": "1.0.36",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.31",
|
||||
"version": "1.0.36",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@axe-web/create-block": "^1.1.30",
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.31",
|
||||
"version": "1.0.36",
|
||||
"author": {
|
||||
"name": "AXE-WEB",
|
||||
"email": "office@axe-web.com",
|
||||
"url": "https://axe-web.com/"
|
||||
},
|
||||
"scripts": {
|
||||
"info": "BLOCK_NAME=swiper-test MODULE_PATH= node debug.js",
|
||||
"dev": "BLOCK_NAME=swiper-test MODULE_PATH= node server.js",
|
||||
"build-platform": "BLOCK_NAME=swiper-test MODULE_PATH= node ./build.js",
|
||||
"info": "BLOCK_NAME=ebooks-resources MODULE_PATH= node debug.js",
|
||||
"dev": "BLOCK_NAME=ebooks-resources MODULE_PATH= node server.js",
|
||||
"build-platform": "BLOCK_NAME=ebooks-resources MODULE_PATH= node ./build.js",
|
||||
"dev-dev-tool": "rollup --config rollup.config.js --watch",
|
||||
"build-dev-tool": "rollup --config rollup.config.js"
|
||||
},
|
||||
|
||||
@@ -2,19 +2,13 @@
|
||||
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
||||
|
||||
class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{
|
||||
class <%= blockClassModel %>_Component extends \Core\Component {
|
||||
const VERSION = '<%= version %>';
|
||||
public $block_project = '<%= ownerFilename %>';
|
||||
public $block_name = '<%= blockFilename %>';
|
||||
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
|
||||
|
||||
<% if (!isComponentManager && !isElementor) { %>public function __construct() {
|
||||
parent::__construct();
|
||||
// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
|
||||
add_action( 'after_setup_theme', [ $this, 'register_assets' ] );
|
||||
}
|
||||
|
||||
<% } %>function register_assets(): void {
|
||||
function register_assets(): void {
|
||||
$base_path = plugin_dir_url( __FILE__ ); // In Plugins
|
||||
// $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 );
|
||||
|
||||
$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() ) {
|
||||
wp_enqueue_style( 'block-<%= blockFilename %>' );
|
||||
wp_enqueue_script( 'block-<%= blockFilename %>' );
|
||||
}<% } %>
|
||||
}
|
||||
}
|
||||
|
||||
public function get_content( $args = [] ): string {
|
||||
@@ -37,8 +33,8 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
|
||||
|
||||
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
|
||||
|
||||
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output );
|
||||
}<% if (isElementor) { %>
|
||||
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output, $args );
|
||||
}
|
||||
|
||||
function register_custom_logic(): void {
|
||||
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 {
|
||||
require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php";
|
||||
$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 {
|
||||
%>new <%= blockClassModel %>_Component();<% } %>
|
||||
<%= blockClassModel %>_Component::get_instance();
|
||||
// new <%= blockClassModel %>_Component();
|
||||
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
|
||||
|
||||
class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base {
|
||||
use \Core\Traits\Elementor_Widget;
|
||||
|
||||
const PLUGIN_NAME = '<%= blockFilename %>';
|
||||
|
||||
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();
|
||||
|
||||
$args = self::prepare( $settings );
|
||||
$args = $this->prepare( $settings );
|
||||
$component->render( $args );
|
||||
}
|
||||
|
||||
public static function prepare( $args ): array {
|
||||
// Prepare $args for render function.
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,6 @@ const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
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 distPath = path.join(projectPath, 'exports', args.platform);
|
||||
@@ -37,12 +33,7 @@ export async function buildWordPress(blockName, args = {}) {
|
||||
ownerClass: owner.replace(/ /ig, '_'),
|
||||
ownerFilename: owner.toLowerCase().replace(/ /ig, '-'),
|
||||
templateFormat: 'php',
|
||||
include_acf_block: isBlock,
|
||||
include_native_gutenberg_block: false,
|
||||
include_script: true,
|
||||
include_elementor_widget: isElementor,
|
||||
isElementor,
|
||||
isComponentManager,
|
||||
});
|
||||
|
||||
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"),
|
||||
});
|
||||
|
||||
// await createFiles(Object.assign({}, data, {defaultData: phpDataObject}), [{
|
||||
// from: `templates/helpers/Template_Defaults.php`,
|
||||
// to: `helpers/${data.blockClassModel}_Defaults.php`,
|
||||
// }], {
|
||||
// pathDist: distPath,
|
||||
// generatorsPath: path.join(__dirname),
|
||||
// });
|
||||
await createFiles(data, [{
|
||||
from: `templates/helpers/Template_Elementor_Widget.php`,
|
||||
to: `helpers/${data.blockClassModel}_Elementor_Widget.php`,
|
||||
}], {
|
||||
pathDist: distPath,
|
||||
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, [{
|
||||
// from: `templates/helpers/Template_API.php`,
|
||||
// to: `helpers/${data.blockClassModel}_API.php`,
|
||||
// }], {
|
||||
// pathDist: distPath,
|
||||
// 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)
|
||||
});
|
||||
}
|
||||
await createFiles(data, [{
|
||||
from: `templates/Template_Basic_Component.php`,
|
||||
to: `${data.blockClassModel}_Component.php`,
|
||||
}], {
|
||||
pathDist: distPath,
|
||||
generatorsPath: path.join(__dirname)
|
||||
});
|
||||
}
|
||||
|
||||
export function execCommand(cmd = '') {
|
||||
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
import PluginError from 'plugin-error';
|
||||
import {Server} from "socket.io";
|
||||
import {createServer} from 'http';
|
||||
import {authtoken, connect} from "ngrok";
|
||||
// import {authtoken, connect} from "ngrok";
|
||||
import bodyParser from "body-parser";
|
||||
|
||||
/**
|
||||
@@ -569,8 +569,8 @@ async function getShareableUrl() {
|
||||
|
||||
let url;
|
||||
try {
|
||||
await authtoken(data.ngrokApiToken);
|
||||
url = await connect(port);
|
||||
// await authtoken(data.ngrokApiToken);
|
||||
// url = await connect(port);
|
||||
} catch (e) {
|
||||
console.log('Error:', `Can't connect to ngrok, probably wrong token.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user