Provided a way to Generate basic WordPress Class.
This commit is contained in:
@@ -20,7 +20,7 @@ class buildGenerator extends Generator {
|
|||||||
type: "list",
|
type: "list",
|
||||||
name: "platform",
|
name: "platform",
|
||||||
message: "Choose Platform",
|
message: "Choose Platform",
|
||||||
choices: ['WordPress', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'],
|
choices: ['WordPress', 'WordPress Block', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'],
|
||||||
default: 'WordPress'
|
default: 'WordPress'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
@@ -46,6 +46,10 @@ class buildGenerator extends Generator {
|
|||||||
if (this.data.platform === 'WordPress') {
|
if (this.data.platform === 'WordPress') {
|
||||||
return buildWordPress();
|
return buildWordPress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.data.platform === 'WordPress Block') {
|
||||||
|
return buildWordPress(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (this.data.platform === 'Hubspot Email') {
|
} else if (this.data.platform === 'Hubspot Email') {
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Core\Global_Functions;
|
||||||
|
|
||||||
|
class <%= blockClassModel %>_Component {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
function register_assets(): void {
|
||||||
|
wp_enqueue_style( '<%= blockFilename %>',
|
||||||
|
get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/styles/<%= blockFilename %>.min.css',
|
||||||
|
[ 'style-wp' ],
|
||||||
|
Global_Functions::get_current_version_number()
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_enqueue_script( '<%= blockFilename %>',
|
||||||
|
get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/scripts/<%= blockFilename %>.min.js',
|
||||||
|
[ 'jquery', 'swiper' ],
|
||||||
|
Global_Functions::get_current_version_number(),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render( $args = [] ): void {
|
||||||
|
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( array_merge( [], $args ), self::class );
|
||||||
|
echo apply_filters( 'the_content', wpautop( $output ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,9 +6,9 @@ import {fileURLToPath} from 'url';
|
|||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const {projectPath, modulesPath} = getConfigs();
|
const {projectPath} = getConfigs();
|
||||||
|
|
||||||
export async function buildWordPress(blockName) {
|
export async function buildWordPress(isBlock = false) {
|
||||||
const distPath = path.join(projectPath, 'exports', 'wordpress');
|
const distPath = path.join(projectPath, 'exports', 'wordpress');
|
||||||
await mkdir(distPath, {recursive: true})
|
await mkdir(distPath, {recursive: true})
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ export async function buildWordPress(blockName) {
|
|||||||
include_elementor_widget: false,
|
include_elementor_widget: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isBlock) {
|
||||||
await createFiles(data, [{
|
await createFiles(data, [{
|
||||||
from: `templates/Template_Component.php`,
|
from: `templates/Template_Component.php`,
|
||||||
to: `${data.blockClassModel}_Component.php`,
|
to: `${data.blockClassModel}_Component.php`,
|
||||||
@@ -60,4 +61,13 @@ export async function buildWordPress(blockName) {
|
|||||||
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)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user