16 Commits

Author SHA1 Message Date
roman 25862c4b1c 1.0.22 2022-12-08 05:00:43 +02:00
roman a61510f136 Updated build process of ACF Block.
Added initBlock function.
2022-12-08 04:56:45 +02:00
roman 0d3ae8f03e Added "scroll" layout for scrolling tests.
Added swiperjs rules that fix the height/vertical-scrolling issues of sliders.
2022-12-07 06:38:54 +02:00
roman b58ef27f1e Fix scrolling issues of iFrame. 2022-12-06 11:32:14 +02:00
roman 161e34e8ee 1.0.21 2022-12-05 14:26:08 +02:00
roman 8eb7bea2e8 Fix resizing issue. 2022-12-05 14:26:01 +02:00
roman d9543bb22c Provide option to rewrite project/module paths. 2022-12-03 21:58:34 +02:00
roman 02abf4652e Update enqueue asset names. 2022-12-01 09:49:19 +02:00
roman 1ed038ff02 Update build of ACF blocks. 2022-11-30 21:01:02 +02:00
roman 0bb705ccdc Update build of ACF blocks. 2022-11-30 17:44:46 +02:00
roman 9d25bdcb88 Update path to assets. 2022-11-25 19:48:14 +02:00
roman 4d1d2337bf Added Basic Elementor widget logic. 2022-11-25 19:42:28 +02:00
roman 00866a8115 Update WordPress Basic Template 2022-11-25 19:25:33 +02:00
roman 1d733fb952 Fix right side icons/buttons. 2022-11-25 15:40:29 +02:00
roman 295c6f82af Added Elementor option in build process.
Elementor build still not ready.
2022-11-25 11:48:41 +02:00
roman f0af682a43 Include jpg,png,svg of toolbar in prod package. 2022-11-24 07:50:53 +02:00
25 changed files with 317 additions and 148 deletions
+9 -7
View File
@@ -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
View File
@@ -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();
}
+1 -1
View File
@@ -2,7 +2,7 @@
{{> (include_partial "layouts/partials/head") }}
<body>
<body class="{{#if iframeMode}}body--iframe{{/if}}">
<main>
{{> (include_block_template) }}
+1 -1
View File
@@ -2,7 +2,7 @@
{{> (include_partial "layouts/partials/head") }}
<body>
<body class="{{#if iframeMode}}body--iframe{{/if}}">
<main>
<div class="container">
+1 -1
View File
@@ -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
View File
@@ -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)}();
+1 -1
View File
File diff suppressed because one or more lines are too long
+16 -2
View File
@@ -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}));
+16
View File
@@ -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>
+9
View File
@@ -0,0 +1,9 @@
.swiper {
&-slide {
width: initial;
}
&-wrapper {
height: initial;
}
}
+2 -2
View File
@@ -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 */
+2 -2
View File
@@ -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");
}
+22 -1
View File
@@ -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
View File
@@ -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"}
+23 -9
View File
@@ -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;
//}
+2 -2
View File
@@ -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
View File
@@ -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/**/*"
]
}
+1 -2
View File
@@ -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");
+1 -2
View File
@@ -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;
}
}
+33 -21
View File
@@ -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);
+7 -51
View File
@@ -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', {