Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 25862c4b1c | |||
| a61510f136 | |||
| 0d3ae8f03e | |||
| b58ef27f1e | |||
| 161e34e8ee | |||
| 8eb7bea2e8 | |||
| d9543bb22c | |||
| 02abf4652e | |||
| 1ed038ff02 | |||
| 0bb705ccdc | |||
| 9d25bdcb88 | |||
| 4d1d2337bf | |||
| 00866a8115 | |||
| 1d733fb952 | |||
| 295c6f82af | |||
| f0af682a43 |
@@ -17,6 +17,9 @@ export const PLATFORM_OPTIONS = [{
|
||||
}, {
|
||||
name: 'wordpress-blocks',
|
||||
title: 'WordPress Block'
|
||||
}, {
|
||||
name: 'wordpress-elementor',
|
||||
title: 'WordPress Elementor'
|
||||
}, {
|
||||
name: 'hubspot',
|
||||
title: 'Hubspot'
|
||||
@@ -42,14 +45,13 @@ console.log('--------------------\nDone!');
|
||||
//
|
||||
|
||||
export async function buildExportFiles(platform) {
|
||||
if (['wordpress', 'php'].includes(platform.name)) {
|
||||
|
||||
if (platform.name === 'wordpress') {
|
||||
await buildWordPress(blockName);
|
||||
if (platform.name.startsWith('wordpress')) {
|
||||
if (platform.name === 'wordpress-blocks') {
|
||||
await buildWordPress(blockName, true);
|
||||
} else if (platform.name === 'wordpress-elementor') {
|
||||
await buildWordPress(blockName, false, true);
|
||||
} else {
|
||||
if (platform.name === 'wordpress-blocks') {
|
||||
await buildWordPress(blockName, true);
|
||||
}
|
||||
await buildWordPress(blockName);
|
||||
}
|
||||
} else if (platform.name === 'hubspot-email') {
|
||||
await buildHubspotEmail(blockName)
|
||||
|
||||
+48
-2
@@ -4,6 +4,7 @@ import {fileURLToPath} from 'url';
|
||||
import memFs from 'mem-fs';
|
||||
import editor from 'mem-fs-editor';
|
||||
import fsExtra from "fs-extra";
|
||||
import archiver from "archiver";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -15,8 +16,8 @@ export function getConfigs() {
|
||||
return {
|
||||
isDev,
|
||||
developmentBlockName,
|
||||
modulesPath: isDev ? '' : 'node_modules/block-dev-tool',
|
||||
projectPath: isDev ? path.join('blocks', developmentBlockName) : '',
|
||||
modulesPath: process.env.MODULE_PATH ?? (isDev ? '' : 'node_modules/block-dev-tool'),
|
||||
projectPath: process.env.PROJECT_PATH ?? (isDev ? path.join('blocks', developmentBlockName) : ''),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -106,3 +107,48 @@ export function capitalize(str) {
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
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.');
|
||||
});
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{{> (include_partial "layouts/partials/head") }}
|
||||
|
||||
<body>
|
||||
<body class="{{#if iframeMode}}body--iframe{{/if}}">
|
||||
|
||||
<main>
|
||||
{{> (include_block_template) }}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{{> (include_partial "layouts/partials/head") }}
|
||||
|
||||
<body>
|
||||
<body class="{{#if iframeMode}}body--iframe{{/if}}">
|
||||
|
||||
<main>
|
||||
<div class="container">
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
</script>
|
||||
|
||||
<div class="preview">
|
||||
<iframe id="preview_frame" src="{{ previewFrameUrl }}" class="breakpoint"></iframe>
|
||||
<iframe id="preview_frame" src="{{ previewFrameUrl }}?iframe=true" class="breakpoint"></iframe>
|
||||
</div>
|
||||
|
||||
<script src="/scripts/dist/index.min.js"></script>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
!function(){let e;const t=2*window.outerHeight;function n(n){const o=document.querySelector("body > main").scrollHeight;if(e===o||o>t)return;e=o,window.parent.postMessage("resize:"+JSON.stringify({height:e}),"*")}n(),new ResizeObserver(n).observe(document.body)}();
|
||||
!function(){let e;function n(n){const t=document.querySelector("body > main").scrollHeight;if(e===t)return;e=t,window.parent.postMessage("resize:"+JSON.stringify({height:e}),"*")}n(),new ResizeObserver(n).observe(document.body)}();
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,9 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// Blocks Initialization.
|
||||
function initBlock(blockName = '', selector = '', cb) {
|
||||
document.querySelectorAll(selector).forEach((el) => cb(el));
|
||||
}
|
||||
|
||||
// Scrollbars / Frame resizes notifications.
|
||||
(function () {
|
||||
let height;
|
||||
const heightLimit = window.outerHeight * 2;
|
||||
const debug = false;
|
||||
|
||||
handleHeightChange(); // Initial frame's height setup.
|
||||
setupResizeListener(); // Listen to frame's height changes.
|
||||
@@ -17,13 +22,22 @@
|
||||
|
||||
function handleHeightChange(entries) {
|
||||
const updatedHeight = getCurrentHeight();
|
||||
if (height === updatedHeight || updatedHeight > heightLimit) {
|
||||
|
||||
if (debug) {
|
||||
console.log('Height Updates', 'Old vs New: ' + height, updatedHeight);
|
||||
}
|
||||
|
||||
if (height === updatedHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
const RESIZE_CODE = 'resize:';
|
||||
height = updatedHeight;
|
||||
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*');
|
||||
|
||||
if (debug) {
|
||||
console.log('Resize message sent: ', height)
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentHeight() {
|
||||
|
||||
@@ -98,7 +98,12 @@ function DataOptions(props = {}) {
|
||||
|
||||
async function changeDataOption(e) {
|
||||
const dataName = e.target.value;
|
||||
props.rootAttributes.previewFrame.src = window.devTool.previewFrameUrl + '?data=' + dataName;
|
||||
|
||||
const previewFrameUrl = new URL(window.devTool.previewFrameUrl);
|
||||
previewFrameUrl.searchParams.set('data', dataName);
|
||||
previewFrameUrl.searchParams.set('iframe', 'true');
|
||||
|
||||
props.rootAttributes.previewFrame.src = previewFrameUrl.href;
|
||||
|
||||
const dataOption = await fetchDataOptions(dataName);
|
||||
updateState(Object.assign({}, dataOption, {dataName}));
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<html lang="en">
|
||||
|
||||
{{> (include_partial "layouts/partials/head") }}
|
||||
|
||||
<body class="{{#if iframeMode}}body--iframe{{/if}}">
|
||||
|
||||
<main>
|
||||
<section class="fullscreen_layout"></section>
|
||||
{{> (include_block_template) }}
|
||||
<section class="fullscreen_layout"></section>
|
||||
</main>
|
||||
|
||||
{{> (include_partial "layouts/partials/scripts") }}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
.swiper {
|
||||
&-slide {
|
||||
width: initial;
|
||||
}
|
||||
|
||||
&-wrapper {
|
||||
height: initial;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ body {
|
||||
--size: 1.5rem;
|
||||
width: var(--size);
|
||||
height: var(--size);
|
||||
background-image: url("/scripts/toolbar/images/icon-open-new-tab.svg");
|
||||
background-image: url("/scripts/dist/toolbar/images/icon-open-new-tab.svg");
|
||||
background-repeat: no-repeat;
|
||||
background-size: calc(var(--size) - 0.15rem);
|
||||
background-position: center center;
|
||||
@@ -159,7 +159,7 @@ body {
|
||||
}
|
||||
|
||||
.palette {
|
||||
background-image: url("/scripts/toolbar/images/icon-palette.svg");
|
||||
background-image: url("/scripts/dist/toolbar/images/icon-palette.svg");
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=page--main.css.map */
|
||||
|
||||
@@ -92,7 +92,7 @@ body {
|
||||
width: var(--size);
|
||||
height: var(--size);
|
||||
|
||||
background-image: url("/scripts/toolbar/images/icon-open-new-tab.svg");
|
||||
background-image: url("/scripts/dist/toolbar/images/icon-open-new-tab.svg");
|
||||
background-repeat: no-repeat;
|
||||
background-size: calc(var(--size) - 0.15rem);
|
||||
background-position: center center;
|
||||
@@ -110,5 +110,5 @@ body {
|
||||
|
||||
.palette {
|
||||
@extend .open_in_new_tab;
|
||||
background-image: url("/scripts/toolbar/images/icon-palette.svg");
|
||||
background-image: url("/scripts/dist/toolbar/images/icon-palette.svg");
|
||||
}
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
body {
|
||||
margin: 0;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
main {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
min-height: 100%;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
main .swiper-slide {
|
||||
width: initial;
|
||||
}
|
||||
main .swiper-wrapper {
|
||||
height: initial;
|
||||
}
|
||||
|
||||
.body--iframe {
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.body--iframe main {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.fullscreen_layout {
|
||||
background-color: #9cc3ff;
|
||||
min-height: 100%;
|
||||
background-image: url("https://i.ibb.co/pjwL8D1/shapelined-JBKdviwe-XI-unsplash.jpg");
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=page--view.css.map */
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sourceRoot":"","sources":["page--view.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;;AAGF;EACE;EACA","file":"page--view.css"}
|
||||
{"version":3,"sourceRoot":"","sources":["page--view.scss","_page--view-swiper.scss"],"names":[],"mappings":"AAAA;EACE;;;AAGF;EACE;EACA;EACA;EACA;;ACPA;EACE;;AAGF;EACE;;;ADSJ;EACE;;AAEA;EAGE;;;AAIJ;EACE;EACA;EACA;EACA","file":"page--view.css"}
|
||||
@@ -1,18 +1,32 @@
|
||||
body {
|
||||
margin: 0;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
main {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
min-height: 100%;
|
||||
overflow-x: hidden;
|
||||
|
||||
// Fixes scrolling issues of swiperJS. Should be included in all projects.
|
||||
@import "page--view-swiper";
|
||||
}
|
||||
|
||||
// iFrame mode
|
||||
.body--iframe {
|
||||
overflow-y: hidden;
|
||||
|
||||
main {
|
||||
// If you change to "overflow: initial", the margin-top/bottom of first/last element will be not included.
|
||||
// Test on fresh block setup where heading has margin-top.
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.fullscreen_layout {
|
||||
background-color: #9cc3ff;
|
||||
min-height: 100%;
|
||||
background-image: url('https://i.ibb.co/pjwL8D1/shapelined-JBKdviwe-XI-unsplash.jpg');
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
// Container rules must be provided by the projectStyles (theme).
|
||||
//.container {
|
||||
// max-width: 1200px;
|
||||
// margin-left: auto;
|
||||
// margin-right: auto;
|
||||
// padding-left: 15px;
|
||||
// padding-right: 15px;
|
||||
//}
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.20",
|
||||
"version": "1.0.22",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.20",
|
||||
"version": "1.0.22",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@braintree/sanitize-url": "^6.0.0",
|
||||
|
||||
+4
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.20",
|
||||
"version": "1.0.22",
|
||||
"author": {
|
||||
"name": "AXE-WEB",
|
||||
"email": "office@axe-web.com",
|
||||
@@ -68,6 +68,9 @@
|
||||
"layouts/**/*.hbs",
|
||||
"layouts/styles/*.css*",
|
||||
"layouts/scripts/dist/*.js*",
|
||||
"layouts/scripts/dist/**/*.jpg",
|
||||
"layouts/scripts/dist/**/*.png",
|
||||
"layouts/scripts/dist/**/*.svg",
|
||||
"platforms/**/*"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ import path from "path";
|
||||
import {readFile, writeFile, mkdir, copyFile} from "fs/promises";
|
||||
import {capitalize, getConfigs} from "../../helpers.js";
|
||||
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
|
||||
export async function buildHubspotEmail(blockName) {
|
||||
const distPath = await createDistFolder(blockName);
|
||||
|
||||
@@ -217,6 +215,7 @@ export function convertToHubspotField(field = {}) {
|
||||
}
|
||||
|
||||
export async function buildHubspotJSONFiles(distPath, metaData) {
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
await writeFile(path.join(distPath, 'meta.json'), JSON.stringify(metaData, null, 4));
|
||||
|
||||
const blockJSON = await readFile(path.join(projectPath, 'block.json'), "utf8");
|
||||
|
||||
@@ -3,9 +3,8 @@ import {copyFile, readFile, writeFile} from "fs/promises";
|
||||
import {capitalize, getConfigs} from "../../helpers.js";
|
||||
import {buildHubspotJSONFiles, createDistFolder, handlebarsToHubl,} from "./hubspot-email-adapter.js";
|
||||
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
|
||||
export async function buildHubspotPage(blockName) {
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
const distPath = await createDistFolder(blockName);
|
||||
|
||||
const srcPath = path.join(projectPath, 'src');
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
||||
|
||||
use Core\Global_Functions;
|
||||
|
||||
class <%= blockClassModel %>_Component {
|
||||
|
||||
public function __construct() {
|
||||
@@ -12,20 +10,26 @@ class <%= blockClassModel %>_Component {
|
||||
}
|
||||
|
||||
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 = plugin_dir_url( __FILE__ ); // In Plugins
|
||||
$base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/';
|
||||
|
||||
wp_register_style( '<%= blockFilename %>',
|
||||
get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/styles/<%= blockFilename %>.min.css',
|
||||
$base_path . 'templates/styles/<%= blockFilename %>.min.css',
|
||||
[ 'style-wp' ],
|
||||
Global_Functions::get_current_version_number()
|
||||
$version
|
||||
);
|
||||
wp_enqueue_style( '<%= blockFilename %>' )
|
||||
wp_enqueue_style( '<%= blockFilename %>' );
|
||||
|
||||
wp_register_script( 'script-<%= blockFilename %>',
|
||||
get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/scripts/<%= blockFilename %>.min.js',
|
||||
$base_path . 'templates/scripts/<%= blockFilename %>.min.js',
|
||||
[ 'jquery', 'swiper' ],
|
||||
Global_Functions::get_current_version_number(),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
wp_enqueue_script( 'script-<%= blockFilename %>' )
|
||||
wp_enqueue_script( 'script-<%= blockFilename %>' );
|
||||
}
|
||||
|
||||
public function render( $args = [] ): void {
|
||||
@@ -35,4 +39,11 @@ class <%= blockClassModel %>_Component {
|
||||
echo apply_filters( 'the_content', wpautop( $output ) );
|
||||
}
|
||||
|
||||
<% if (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() );
|
||||
}<% } %>
|
||||
|
||||
}
|
||||
|
||||
// ( new <%= blockClassModel %>_Component() ); // Initialization
|
||||
|
||||
@@ -5,23 +5,27 @@ namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
||||
class <%= blockClassModel %>_Component extends \Core\Component {
|
||||
|
||||
public function get_content( $args = [] ): string {
|
||||
$args = array_merge( Helpers\<%= blockClassModel %>_Defaults::default_args(), $args );
|
||||
$args = Helpers\<%= blockClassModel %>_API::prepare_args( $args );
|
||||
$default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical.
|
||||
|
||||
<% if (templateFormat === 'hbs') { %>return $this->get_component_template( __DIR__ . '/templates/<%= blockFilename %>.template.hbs', $args );<% } %>
|
||||
<% if (templateFormat === 'php') { %>
|
||||
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( array_merge( [], $args ), self::class );
|
||||
echo apply_filters( 'the_content', wpautop( $output ) );
|
||||
<% } %>
|
||||
$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) { %>
|
||||
public function register_assets() {
|
||||
$this->add_style( __DIR__ . '/templates/styles/<%= blockFilename %>.min.css' );
|
||||
<% if (include_script) { %>$this->add_script( __DIR__ . '/templates/scripts/<%= blockFilename %>.js' );<% } %>
|
||||
}
|
||||
<% 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
|
||||
|
||||
<% } %><% if (include_elementor_widget) { %> function register_custom_logic(): void {
|
||||
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/';
|
||||
wp_enqueue_style( 'block-<%= blockFilename %>', plugins_url( 'templates/styles/<%= blockFilename %>.min.css', __FILE__ ), ['assets-style'], get_blocks_version() );<% if (include_script) { %>
|
||||
wp_enqueue_script( 'block-<%= blockFilename %>', plugins_url( 'templates/scripts/<%= blockFilename %>.min.js', __FILE__ ), ['assets-script'], get_blocks_version(), true );<% } %>
|
||||
|
||||
wp_enqueue_script( 'script-block-<%= blockFilename %>' );
|
||||
}<% } %>
|
||||
|
||||
<% if (include_elementor_widget) { %>function register_custom_logic(): void {
|
||||
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] );
|
||||
}
|
||||
|
||||
@@ -31,22 +35,18 @@ class <%= blockClassModel %>_Component extends \Core\Component {
|
||||
|
||||
<% } %><% if (include_acf_block) { %> function register_acf_block() {
|
||||
$this->register_block( __DIR__ . "/<%= blockFilename %>.block.json", [
|
||||
'enqueue_assets' => function () {
|
||||
wp_enqueue_style( '<%= blockFilename %>', \Core\Global_Functions::get_file_url( __DIR__ . '/templates/styles/<%= blockFilename %>.min.css', true ), [], get_blocks_version() );<% if (include_script) { %>
|
||||
wp_enqueue_script( '<%= blockFilename %>', \Core\Global_Functions::get_file_url( __DIR__ . '/templates/scripts/<%= blockFilename %>.js', true ), ['assets-script'], get_blocks_version() );<% } %>
|
||||
},
|
||||
'default' => Helpers\<%= blockClassModel %>_Defaults::default_args(),
|
||||
'supports' => [
|
||||
//'jsx' => true,
|
||||
'color' => [
|
||||
'background' => true,
|
||||
'text' => true,
|
||||
],
|
||||
'spacing' => [
|
||||
'margin' => [ 'top', 'bottom' ],
|
||||
'padding' => [ 'top', 'bottom' ]
|
||||
],
|
||||
]
|
||||
'style_assets' => [
|
||||
[
|
||||
'name' => '<%= blockFilename %>',
|
||||
'url' => plugins_url( 'templates/styles/<%= blockFilename %>.min.css', __FILE__ ),
|
||||
]
|
||||
],
|
||||
'script_assets' => [
|
||||
[
|
||||
'name' => '<%= blockFilename %>',
|
||||
'url' => plugins_url( 'templates/scripts/<%= blockFilename %>.min.js', __FILE__ ),
|
||||
]
|
||||
]
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -66,3 +66,5 @@ class <%= blockClassModel %>_Component extends \Core\Component {
|
||||
}<% } %>
|
||||
|
||||
}
|
||||
|
||||
<%= blockClassModel %>_Component::get_instance();
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
|
||||
|
||||
class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base {
|
||||
const PLUGIN_NAME = '<%= blockFilename %>';
|
||||
|
||||
public function get_name() {
|
||||
return self::PLUGIN_NAME;
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return '<%= blockClassModel %>';
|
||||
}
|
||||
|
||||
public function get_icon() {
|
||||
return 'eicon-plus-square-o';
|
||||
}
|
||||
|
||||
protected function _register_controls() {
|
||||
$this->start_controls_section( 'section_content', [ 'label' => 'Content' ] );
|
||||
|
||||
$repeater = new \Elementor\Repeater();
|
||||
|
||||
// $repeater->add_control(
|
||||
// 'video_url', [
|
||||
// 'label' => 'YouTube URL',
|
||||
// 'type' => \Elementor\Controls_Manager::URL,
|
||||
// 'label_block' => true,
|
||||
// 'condition' => [
|
||||
// 'type' => 'video',
|
||||
// ],
|
||||
// ]
|
||||
// );
|
||||
|
||||
$this->end_controls_section();
|
||||
}
|
||||
|
||||
function get_style_depends() {
|
||||
return [ '<%= blockFilename %>' ];
|
||||
}
|
||||
|
||||
function get_script_depends() {
|
||||
return [ 'script-<%= blockFilename %>' ];
|
||||
}
|
||||
|
||||
protected function render() {
|
||||
$settings = $this->get_settings_for_display();
|
||||
|
||||
$component = new \AXEWEB_Blocks\Blocks\Scytale\<%= blockClassModel %>\<%= blockClassModel %>_Component();
|
||||
|
||||
$args = self::prepare( $settings );
|
||||
$component->render( $args );
|
||||
}
|
||||
|
||||
public static function prepare( $args ): array {
|
||||
// Prepare $args for render function.
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,14 @@ import execPhp from "exec-php";
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
export async function buildWordPress(blockName, isBlock = false, isElementor = false) {
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
|
||||
export async function buildWordPress(blockName, isBlock = false) {
|
||||
const distPath = path.join(projectPath, 'exports', 'wordpress');
|
||||
// await mkdir(distPath, {recursive: true})
|
||||
await mkdir(path.join(distPath, 'templates'), {recursive: true})
|
||||
|
||||
const blockFilePath = path.join(projectPath, 'block.json');
|
||||
await copyFile(blockFilePath, path.join(distPath, 'block.json'));
|
||||
|
||||
let data = await readJSONFile(blockFilePath);
|
||||
Object.assign(data, getBlockName(data.name));
|
||||
@@ -34,12 +33,15 @@ export async function buildWordPress(blockName, isBlock = false) {
|
||||
ownerClass: owner.replace(/ /ig, '_'),
|
||||
ownerFilename: owner.toLowerCase().replace(/ /ig, '-'),
|
||||
templateFormat: 'php',
|
||||
include_acf_block: false,
|
||||
include_acf_block: isBlock,
|
||||
include_native_gutenberg_block: false,
|
||||
include_script: true,
|
||||
include_elementor_widget: false,
|
||||
include_elementor_widget: isElementor,
|
||||
isElementor,
|
||||
});
|
||||
|
||||
await copyFile(blockFilePath, path.join(distPath, data.blockFilename + '.block.json'));
|
||||
|
||||
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : '';
|
||||
|
||||
const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
|
||||
@@ -65,13 +67,23 @@ export async function buildWordPress(blockName, isBlock = false) {
|
||||
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(Object.assign({}, data, {defaultData: phpDataObject}), [{
|
||||
// from: `templates/helpers/Template_Defaults.php`,
|
||||
// to: `helpers/${data.blockClassModel}_Defaults.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, [{
|
||||
@@ -82,13 +94,13 @@ export async function buildWordPress(blockName, isBlock = false) {
|
||||
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)
|
||||
});
|
||||
// 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`,
|
||||
@@ -103,7 +115,7 @@ export async function buildWordPress(blockName, isBlock = false) {
|
||||
export function execCommand(cmd = '') {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
exec(cmd, function (error, stdout) {
|
||||
exec(cmd, function (error) {
|
||||
if (error) {
|
||||
console.log('Error:', error)
|
||||
reject(error);
|
||||
@@ -124,7 +136,7 @@ function execPHPFile(file = '', functionName = '', args = {}) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
php[functionName.toLowerCase()](args, (err, res, out, print) => {
|
||||
php[functionName.toLowerCase()](args, (err, res, out) => {
|
||||
if (err) {
|
||||
console.error(out);
|
||||
return reject(err);
|
||||
|
||||
@@ -4,7 +4,6 @@ import path from 'path';
|
||||
import fetch from "node-fetch";
|
||||
import express from 'express';
|
||||
import {create} from 'express-handlebars';
|
||||
import fsExtra from 'fs-extra';
|
||||
import browserSync from 'browser-sync';
|
||||
import config from 'config';
|
||||
import gulp from 'gulp';
|
||||
@@ -19,8 +18,7 @@ import open from "open";
|
||||
import {sanitizeUrl} from "@braintree/sanitize-url";
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
import {escape} from "lodash-es";
|
||||
import archiver from 'archiver';
|
||||
import {getBlockConfigs, getConfigs, readJSONFile} from "./helpers.js";
|
||||
import {getBlockConfigs, getConfigs, readJSONFile, zipProject} from "./helpers.js";
|
||||
import PluginError from 'plugin-error';
|
||||
|
||||
/**
|
||||
@@ -99,7 +97,11 @@ app.get('/view/:baseView', async (req, res) => {
|
||||
include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath),
|
||||
include_block_template: () => handlebarLayoutsPath(projectPath, 'src', `${blockName}.template`),
|
||||
section_class: `${blockName}--${jsonFileName}`,
|
||||
base_url: '/'
|
||||
base_url: '/',
|
||||
}
|
||||
|
||||
if (!!req.query.iframe) {
|
||||
data.iframeMode = true;
|
||||
}
|
||||
|
||||
const baseView = req.params.baseView ?? 'container';
|
||||
@@ -130,7 +132,7 @@ app.get('/publish', async (req, res) => {
|
||||
}
|
||||
|
||||
if (responseData.uploadUrl) {
|
||||
await zipProject();
|
||||
await zipProject(path.join(projectPath, 'src'));
|
||||
const body = await fs.readFile(path.join(projectPath, 'dist.zip'));
|
||||
const response = await fetch(`${responseData.uploadUrl}`, {
|
||||
method: 'PUT',
|
||||
@@ -339,52 +341,6 @@ function prepareListOfDataFiles(dataFiles) {
|
||||
.sort();
|
||||
}
|
||||
|
||||
|
||||
async function zipProject() {
|
||||
// create a file to stream archive data to.
|
||||
const output = await fsExtra.createWriteStream('dist.zip');
|
||||
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.');
|
||||
});
|
||||
|
||||
// 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(path.join(projectPath, 'src'), 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();
|
||||
}
|
||||
|
||||
function handleSyntaxErrors(err, req, res, next) {
|
||||
if (err) {
|
||||
return res.render('error', {
|
||||
|
||||
Reference in New Issue
Block a user