Compare commits
117 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a22a179eff | |||
| 95e0cae3ed | |||
| 92e4f1ea2d | |||
| 0062bb4506 | |||
| 5dd326be0f | |||
| 00efc1677d | |||
| 38c49a64ad | |||
| 044f721d34 | |||
| 74f4b11ad6 | |||
| 1b2cf2697f | |||
| bcad45d1e8 | |||
| 3daa725309 | |||
| 438619c4d9 | |||
| 1b2795fa40 | |||
| 31786581bd | |||
| e25f1aa4f1 | |||
| f3cd0e5876 | |||
| d6b0ff866b | |||
| 4a7ddf7d29 | |||
| 03a8833f46 | |||
| bf8f0e857d | |||
| b76f83d4fa | |||
| 977ec0003c | |||
| 0e91c42e89 | |||
| 0a4fd3608f | |||
| 11152dda87 | |||
| 246c9ddd35 | |||
| 164ef7433a | |||
| a6decb9cfb | |||
| 9c85a89a8f | |||
| 58ed3de9dc | |||
| 3de4a4abb6 | |||
| 256450226b | |||
| 51db3da072 | |||
| 05c5697bc2 | |||
| 01e4160040 | |||
| 81f5166043 | |||
| a1929fe33c | |||
| 840c002834 | |||
| f4474fb7e4 | |||
| 8ca6cb0365 | |||
| e2553358be | |||
| 34dbff5701 | |||
| c408f2f5b3 | |||
| 15dbe26220 | |||
| 9818067013 | |||
| 996d222436 | |||
| e964892e65 | |||
| 6d1ab34b2b | |||
| 18d89a9a19 | |||
| 5c7ea9df3c | |||
| 010154797a | |||
| 98d0720bc0 | |||
| 378038b244 | |||
| 090978e8f8 | |||
| aae474901b | |||
| a4193d63e1 | |||
| 9f5c157e54 | |||
| b399d2fc89 | |||
| c899f8c229 | |||
| 80464a61d7 | |||
| 3a78aee088 | |||
| 0f60a0ac30 | |||
| 7dcaa80d71 | |||
| 0a8cdf1504 | |||
| 1718157b4e | |||
| df7866b8b5 | |||
| 50d743140b | |||
| f86afc8394 | |||
| 269fbbc401 | |||
| f236674c1e | |||
| e9827fdd88 | |||
| b441ac613d | |||
| 394d5a42d9 | |||
| 6885db162e | |||
| 1a19d63192 | |||
| 3c163b8e76 | |||
| c627c873f9 | |||
| ec61e01950 | |||
| 682299445c | |||
| ddbc713603 | |||
| 4abdd29709 | |||
| a0def8467b | |||
| bd5cafa549 | |||
| dd860ec473 | |||
| c1340f2035 | |||
| b43a4d6b4f | |||
| 1a98a60fac | |||
| de0b6740d1 | |||
| f9c0852ede | |||
| cdbb4d3064 | |||
| 8d7ce53e46 | |||
| e42643f182 | |||
| 05b5ccb2b5 | |||
| 54523ed903 | |||
| f611185a47 | |||
| 7024c2bfcb | |||
| b882c9a1c3 | |||
| 1dc8d192f7 | |||
| d8c3d4c54b | |||
| 6626ecff2a | |||
| 25862c4b1c | |||
| a61510f136 | |||
| 0d3ae8f03e | |||
| b58ef27f1e | |||
| 161e34e8ee | |||
| 8eb7bea2e8 | |||
| d9543bb22c | |||
| 02abf4652e | |||
| 1ed038ff02 | |||
| 0bb705ccdc | |||
| 9d25bdcb88 | |||
| 4d1d2337bf | |||
| 00866a8115 | |||
| 1d733fb952 | |||
| 295c6f82af | |||
| f0af682a43 |
@@ -18,6 +18,10 @@ indent_size = 2
|
|||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.php]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import prompts from "prompts";
|
import prompts from "prompts";
|
||||||
import {buildHubspotEmail} from "./platforms/hubspot/hubspot-email-adapter.js";
|
import {buildExportFiles, getConfigs} from "./helpers.js";
|
||||||
import {getConfigs} from "./helpers.js";
|
|
||||||
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js";
|
|
||||||
import {buildHubspotPage} from "./platforms/hubspot/hubspot-page-adapter.js";
|
|
||||||
|
|
||||||
const {isDev, developmentBlockName} = getConfigs();
|
const {isDev, developmentBlockName} = getConfigs();
|
||||||
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
||||||
@@ -14,9 +11,6 @@ const blockName = !isDev && config.has('blockName') ? config.get('blockName') :
|
|||||||
export const PLATFORM_OPTIONS = [{
|
export const PLATFORM_OPTIONS = [{
|
||||||
name: 'wordpress',
|
name: 'wordpress',
|
||||||
title: 'WordPress'
|
title: 'WordPress'
|
||||||
}, {
|
|
||||||
name: 'wordpress-blocks',
|
|
||||||
title: 'WordPress Block'
|
|
||||||
}, {
|
}, {
|
||||||
name: 'hubspot',
|
name: 'hubspot',
|
||||||
title: 'Hubspot'
|
title: 'Hubspot'
|
||||||
@@ -33,7 +27,7 @@ export const PLATFORM_OPTIONS = [{
|
|||||||
|
|
||||||
const data = await getExportData();
|
const data = await getExportData();
|
||||||
const selectedPlatform = PLATFORM_OPTIONS[data['platform']];
|
const selectedPlatform = PLATFORM_OPTIONS[data['platform']];
|
||||||
await buildExportFiles(selectedPlatform);
|
await buildExportFiles(blockName, selectedPlatform);
|
||||||
|
|
||||||
console.log('--------------------\nDone!');
|
console.log('--------------------\nDone!');
|
||||||
|
|
||||||
@@ -41,23 +35,6 @@ console.log('--------------------\nDone!');
|
|||||||
// Functions
|
// Functions
|
||||||
//
|
//
|
||||||
|
|
||||||
export async function buildExportFiles(platform) {
|
|
||||||
if (['wordpress', 'php'].includes(platform.name)) {
|
|
||||||
|
|
||||||
if (platform.name === 'wordpress') {
|
|
||||||
await buildWordPress(blockName);
|
|
||||||
} else {
|
|
||||||
if (platform.name === 'wordpress-blocks') {
|
|
||||||
await buildWordPress(blockName, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (platform.name === 'hubspot-email') {
|
|
||||||
await buildHubspotEmail(blockName)
|
|
||||||
} else if (platform.name === 'hubspot') {
|
|
||||||
await buildHubspotPage(blockName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getExportData() {
|
function getExportData() {
|
||||||
return prompts([
|
return prompts([
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since this file overwrites environment variables for `config` lib,
|
||||||
|
* it's important to "import" this file before all scripts in entry point file,
|
||||||
|
* especially before `config` module import.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export constant variables
|
||||||
|
*/
|
||||||
|
export const PRODUCTION_REGISTRY_URL = 'https://blocks-registery.axe-web.com';
|
||||||
|
export const IS_DEV = process.env.NODE_ENV === 'development';
|
||||||
|
export const BLOCK_NAME = process.env.BLOCK_NAME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrite env variables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
process.env.NODE_CONFIG_DIR = path.join(getProjectPath(), 'config');
|
||||||
|
|
||||||
|
|
||||||
|
export function getModulePath() {
|
||||||
|
let modulePath = 'node_modules/block-dev-tool';
|
||||||
|
|
||||||
|
if (typeof process.env.MODULE_PATH !== 'undefined') {
|
||||||
|
modulePath = process.env.MODULE_PATH;
|
||||||
|
} else if (process.env.BLOCK_NAME) {
|
||||||
|
modulePath = 'node_modules/@axe-web/block-dev-tool';
|
||||||
|
}
|
||||||
|
|
||||||
|
return modulePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProjectPath() {
|
||||||
|
let projectPath = '';
|
||||||
|
|
||||||
|
if (typeof process.env.PROJECT_PATH !== 'undefined') {
|
||||||
|
projectPath = path.join(process.env.PROJECT_PATH ?? '', process.env.BLOCK_NAME ?? '')
|
||||||
|
} else if (process.env.BLOCK_NAME) {
|
||||||
|
projectPath = path.join('blocks', process.env.BLOCK_NAME ?? '')
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectPath;
|
||||||
|
}
|
||||||
+230
-17
@@ -1,22 +1,29 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {BLOCK_NAME, getModulePath, getProjectPath, IS_DEV} from "./env.js";
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
import memFs from 'mem-fs';
|
import memFs from 'mem-fs';
|
||||||
import editor from 'mem-fs-editor';
|
import editor from 'mem-fs-editor';
|
||||||
import fsExtra from "fs-extra";
|
import fsExtra from "fs-extra";
|
||||||
|
import archiver from "archiver";
|
||||||
|
import {buildWordPress} from "./platforms/wordpress/wordpress-adapter.js";
|
||||||
|
import {buildHubspotEmail} from "./platforms/hubspot/hubspot-email-adapter.js";
|
||||||
|
import {buildHubspotPage} from "./platforms/hubspot/hubspot-page-adapter.js";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import {constants} from "fs";
|
||||||
|
import fetch from "node-fetch";
|
||||||
|
import mime from "mime-types";
|
||||||
|
import {exec} from "child_process";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
export function getConfigs() {
|
export function getConfigs() {
|
||||||
const isDev = process.env.NODE_ENV === 'development'; // Check README file in case you get "missing files" error.
|
|
||||||
const developmentBlockName = process.env.BLOCK_NAME;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDev,
|
isDev: IS_DEV,
|
||||||
developmentBlockName,
|
developmentBlockName: BLOCK_NAME,
|
||||||
modulesPath: isDev ? '' : 'node_modules/block-dev-tool',
|
modulesPath: getModulePath(),
|
||||||
projectPath: isDev ? path.join('blocks', developmentBlockName) : '',
|
projectPath: getProjectPath(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +31,7 @@ export async function readJSONFile(jsonFile) {
|
|||||||
let data = {};
|
let data = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await fs.access(jsonFile, constants.F_OK | constants.R_OK);
|
||||||
data = await fsExtra.readJson(jsonFile);
|
data = await fsExtra.readJson(jsonFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
@@ -41,27 +49,35 @@ function getErrorHtml(message = '', errorMessage = '') {
|
|||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBlockConfigs(jsonFileName = 'default',
|
export async function getBlockData(jsonFileName = 'default', {projectPath} = {jsonFileName: 'default'}) {
|
||||||
{includeConfigs, projectPath, modulesPath, dataFiles} = {}) {
|
const filePath = path.join(projectPath, 'data', `${jsonFileName}.json`);
|
||||||
let data = await readJSONFile(path.join(projectPath, 'data', `${jsonFileName}.json`));
|
const data = await readJSONFile(filePath);
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
|
console.log(filePath, data.errorMessage.replace(/<[^>]*>?/gm, ''));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeConfigs) {
|
export function getBlockConfigs(args = {modulesPath: '', dataFiles: []}) {
|
||||||
Object.assign(data, {
|
const updatedConfig = Object.assign(JSON.parse(JSON.stringify(config)), // The entire config object.
|
||||||
config: Object.assign(JSON.parse(JSON.stringify(config)), // The entire config object.
|
|
||||||
{
|
{
|
||||||
projectDir: modulesPath, activeDataFile: jsonFileName, dataFiles: dataFiles.map((name) => {
|
projectDir: args.modulesPath, dataFiles: args.dataFiles.map((name) => {
|
||||||
return {
|
return {
|
||||||
name, active: jsonFileName === name,
|
name,
|
||||||
};
|
};
|
||||||
}), remToPx: config.has('remToPx') ? config.get('remToPx') : 16,
|
}), remToPx: config.has('remToPx') ? config.get('remToPx') : 16,
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Avoid cache conflict on Global Project css/js files.
|
||||||
|
if (updatedConfig.project) {
|
||||||
|
updatedConfig.project.css = updatedConfig.project.css ? updatedConfig.project.css + '?cache=' + Date.now() : undefined;
|
||||||
|
updatedConfig.project.js = updatedConfig.project.js ? updatedConfig.project.js + '?cache=' + Date.now() : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return updatedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBlockName(name = '') {
|
export function getBlockName(name = '') {
|
||||||
@@ -106,3 +122,200 @@ export function capitalize(str) {
|
|||||||
})
|
})
|
||||||
.join(' ');
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function zipProject(srcDir, outputFileName = 'dist.zip') {
|
||||||
|
// create a file to stream archive data to.
|
||||||
|
const output = await fsExtra.createWriteStream(outputFileName);
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function buildExportFiles(blockName, platform) {
|
||||||
|
if (platform.name.startsWith('wordpress')) {
|
||||||
|
await buildWordPress(blockName, {platform: platform.name});
|
||||||
|
} else if (platform.name === 'hubspot-email') {
|
||||||
|
await buildHubspotEmail(blockName)
|
||||||
|
} else if (platform.name === 'hubspot') {
|
||||||
|
await buildHubspotPage(blockName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeCommentsFromCss(content) {
|
||||||
|
return content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeCommentsFromJs(content) {
|
||||||
|
return content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function uploadFile(filePath, uploadUrl, validator) {
|
||||||
|
const options = {};
|
||||||
|
|
||||||
|
const contentType = mime.lookup(filePath);
|
||||||
|
if (['text/css', 'application/javascript'].includes(contentType)) {
|
||||||
|
options.encoding = 'utf8';
|
||||||
|
}
|
||||||
|
|
||||||
|
let body = await fs.readFile(filePath, options);
|
||||||
|
|
||||||
|
if (validator) {
|
||||||
|
body = validator(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(uploadUrl, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: body,
|
||||||
|
headers: {'Content-Type': contentType}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.status !== 200;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
const fileName = filePath.split('/').pop();
|
||||||
|
throw new Error(`Can't upload "${fileName}" file. Server permission error.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getImagesList(rootFolder, subFolder = '') {
|
||||||
|
const imagesPath = path.join(rootFolder, subFolder);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.access(imagesPath);
|
||||||
|
} catch (err) {
|
||||||
|
// Folder doesn't exist.
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const images = await fs.readdir(imagesPath);
|
||||||
|
const imagesList = [];
|
||||||
|
|
||||||
|
for (const image of images) {
|
||||||
|
const stats = await fs.stat(path.join(imagesPath, image));
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
const subImages = await getImagesList(rootFolder, image);
|
||||||
|
imagesList.push(...subImages);
|
||||||
|
} else {
|
||||||
|
imagesList.push(path.join(subFolder, image));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return imagesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function isFileEmpty(filePath, ignoreComments = false) {
|
||||||
|
const fileContent = await fs.readFile(filePath, 'utf8');
|
||||||
|
const lines = fileContent.split('\n');
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (ignoreComments && line.trim().startsWith('//')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.trim().length > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function replaceNames(content, images, uploadedImages) {
|
||||||
|
images.forEach((image, index) => {
|
||||||
|
content = content.replaceAll(image, uploadedImages[index].fileName);
|
||||||
|
});
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getBlockFromCloud(blockName, blocksRegistry) {
|
||||||
|
const queryString = new URLSearchParams();
|
||||||
|
queryString.append('blockName', blockName);
|
||||||
|
queryString.append('includeDevConfig', 'true');
|
||||||
|
|
||||||
|
const response = await fetch(`${blocksRegistry}?${queryString.toString()}`);
|
||||||
|
const responseData = await response.json();
|
||||||
|
if (!responseData || !responseData.name) {
|
||||||
|
const message = "⚠️ Block not found, please contact administrator."
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseData.statusCode && responseData.statusCode !== 200) {
|
||||||
|
const message = ["⚠️ [ERROR]", responseData.message || "Server side error."].join(' ');
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function verifyVersion(projectPath, blocksRegistry) {
|
||||||
|
const blockJson = await readJSONFile(path.join(projectPath, `block.json`));
|
||||||
|
const blockName = getBlockName(blockJson.name);
|
||||||
|
|
||||||
|
if (typeof blockJson.version === 'undefined' || !blockName.name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This block is managed on cloud.
|
||||||
|
* Let's detect the latest version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const block = await getBlockFromCloud('@' + blockJson.name, blocksRegistry);
|
||||||
|
return block.version === blockJson.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncFilesWithCloud(jsonBlockPath, bs, sourceFiles = false) {
|
||||||
|
const blockJson = await readJSONFile(jsonBlockPath);
|
||||||
|
const blockName = blockJson.name.startsWith('@') ? blockJson.name : `@${blockJson.name}`;
|
||||||
|
|
||||||
|
bs.pause();
|
||||||
|
|
||||||
|
// Looks like it takes time to pause the browser-sync server, so delay(setTimeout) is necessary.
|
||||||
|
await new Promise((resolve) => setTimeout(() => resolve(), 1000));
|
||||||
|
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
const args = sourceFiles ? '--source' : '';
|
||||||
|
const createBlockModulePath = `./node_modules/@axe-web/create-block`;
|
||||||
|
|
||||||
|
// exec(`BLOCK_NAME=${blockName} node ${createBlockModulePath}/create-block.js sync ${args}`, (err, stdout, stderr) => {
|
||||||
|
exec(`node ${createBlockModulePath}/create-block.js sync ${args}`, (err, stdout, stderr) => {
|
||||||
|
if (err || stderr) {
|
||||||
|
const message = err || stderr;
|
||||||
|
console.error('Error:', message);
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(stdout);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
bs.resume();
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
{{> (include_partial "layouts/partials/head") }}
|
{{> (include_partial "layouts/partials/head") }}
|
||||||
|
|
||||||
<body>
|
<body class="{{#if iframeMode}}body--iframe{{/if}}">
|
||||||
|
|
||||||
<main>
|
<div id="hbs-container"></div>
|
||||||
{{> (include_block_template) }}
|
|
||||||
</main>
|
|
||||||
|
|
||||||
{{> (include_partial "layouts/partials/scripts") }}
|
{{> (include_partial "layouts/partials/scripts") }}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
{{> (include_partial "layouts/partials/head") }}
|
{{> (include_partial "layouts/partials/head") }}
|
||||||
|
|
||||||
<body>
|
<body class="{{#if iframeMode}}body--iframe{{/if}}">
|
||||||
|
|
||||||
<main>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{> (include_block_template) }}
|
<div id="hbs-container"></div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
|
||||||
|
|
||||||
{{> (include_partial "layouts/partials/scripts") }}
|
{{> (include_partial "layouts/partials/scripts") }}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -14,11 +14,14 @@
|
|||||||
<script>
|
<script>
|
||||||
window.devTool = {
|
window.devTool = {
|
||||||
previewFrameUrl: '{{ previewFrameUrl }}',
|
previewFrameUrl: '{{ previewFrameUrl }}',
|
||||||
|
{{#if publicUrl}}
|
||||||
|
publicUrl: true,
|
||||||
|
{{/if}}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="preview">
|
<div class="preview">
|
||||||
<iframe id="preview_frame" src="{{ previewFrameUrl }}" class="breakpoint"></iframe>
|
<iframe id="preview_frame" src="{{ previewFrameUrl }}?iframe=true" class="breakpoint"></iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/scripts/dist/index.min.js"></script>
|
<script src="/scripts/dist/index.min.js"></script>
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/swiper@8.4.5/swiper-bundle.min.css"/>
|
||||||
|
{{#if config.project.css }} <link rel="stylesheet" href="{{ config.project.css }}">
|
||||||
|
{{/if}}
|
||||||
{{#if config.cssUrl }}
|
{{#if config.cssUrl }}
|
||||||
{{#each config.cssUrl }}
|
{{#each config.cssUrl }}
|
||||||
<link rel="stylesheet" href="{{ this }}">
|
<link rel="stylesheet" href="{{ this }}">
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/if}}<link rel="stylesheet" href="/styles/page--view.css">{{# if config.blockName}}
|
{{/if}}<link rel="stylesheet" href="/styles/page--view.css">{{# if config.blockName}}
|
||||||
<link rel="stylesheet" href="/styles/{{ config.blockName }}.min.css">{{/if}}
|
<link rel="stylesheet" href="/styles/{{ config.blockName }}.min.css">{{/if}}
|
||||||
<link rel="stylesheet" href="https://unpkg.com/swiper@8/swiper-bundle.min.css"/>
|
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
|
||||||
<script src="/scripts/dist/frame-index.min.js"></script>
|
<script src="/scripts/dist/frame-index.min.js"></script>
|
||||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||||
<script src="https://unpkg.com/swiper@8/swiper-bundle.min.js"></script>{{#if config.jsUrl }}
|
<script src="https://unpkg.com/swiper@8.4.5/swiper-bundle.min.js"></script>
|
||||||
|
{{#if config.project.js }}<script src="{{ config.project.js }}"></script>
|
||||||
|
{{/if}}
|
||||||
|
{{#if config.jsUrl }}
|
||||||
{{#each config.jsUrl }}<script src="{{ this }}"></script>
|
{{#each config.jsUrl }}<script src="{{ this }}"></script>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
@@ -3,14 +3,17 @@
|
|||||||
<div class="page_toolbar__left"></div>
|
<div class="page_toolbar__left"></div>
|
||||||
|
|
||||||
<div class="page_toolbar__middle">
|
<div class="page_toolbar__middle">
|
||||||
<div>
|
<div style="display: none">
|
||||||
Sizes: <b>1rem = {{ config.remToPx }}px</b>
|
Version: {{ config.version }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page_toolbar__right">
|
<div class="page_toolbar__right">
|
||||||
{{#if config.styleGuideUrl}}
|
{{#if shareUrl}}
|
||||||
<a href="{{ config.styleGuideUrl }}" target="_blank" class="palette" title="Open Style Guide"></a>
|
<a href="{{ shareUrl }}" target="_blank" class="share" title="Share URL"></a>
|
||||||
|
{{/if}}
|
||||||
|
{{#if styleGuideUrl}}
|
||||||
|
<a href="{{ styleGuideUrl }}" target="_blank" class="palette" title="Open Style Guide"></a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<a href="{{ previewFrameUrl }}" target="_blank" class="open_in_new_tab" title="Open in New Window"></a>
|
<a href="{{ previewFrameUrl }}" target="_blank" class="open_in_new_tab" title="Open in New Window"></a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+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)}();
|
let e;window.initBlock=function(e="",n="",r){t=function(){document.querySelectorAll(n).forEach((e=>r(e)))},t()};let t,n={};function r(r={}){r.template&&(e=r.template),r.data&&(n=r.data),e&&function(e,n,r){const a=Handlebars.compile(e);let o;Handlebars.registerHelper("esc_attr",(function(e){return e})),Handlebars.registerHelper("esc_url",(function(e){return e})),Handlebars.registerHelper("esc_html",(function(e){return e})),Handlebars.registerHelper("base_url",(function(){return"/"})),Handlebars.registerHelper("inner_blocks",(function(e){const t=e.data.root.inner_blocks;return t?new Handlebars.SafeString(t):""}));try{o=a(n)}catch(e){o=`<div style="max-width: 1280px; margin: 1rem auto;">\n <h1 style="all: unset; font-size: 1.5rem; font-weight: bold; display: block;">Syntax Error:</h1>\n <pre style="all: unset; padding: 10px 15px; background-color: #ffe6e6; border: 1px solid red; border-radius: 0.25rem; overflow: auto; display: block; white-space: pre;">${e.toString()}</pre>\n </div>`}r.innerHTML=o,t&&t()}(e,n||{},document.getElementById("hbs-container"))}!function(){function e(){const e=new URLSearchParams(window.location.search),t={};for(const[n,r]of e)t[n]=r;return t}!function(){const t=new URLSearchParams({name:e().data||"default"});fetch(`/data?${t}`).then((e=>e.json())).then((e=>{n=e.data,r({data:n})}))}(),window.addEventListener("message",(function(e){const t=e.data,a="dataUpdate:";if("string"==typeof t&&t.startsWith(a))try{n=JSON.parse(t.substring(a.length)),r({data:n})}catch(e){console.log("Error parsing incoming data.",e)}}))}(),function(){const e=window.io.connect();e.on("error",(function(e){console.log(e)})),e.on("templateUpdate",(function(e){r({template:e.template})}))}();
|
||||||
|
|||||||
+1
File diff suppressed because one or more lines are too long
Vendored
+23
-6
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
Vendored
+21
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
|||||||
|
<svg width="478" height="506" viewBox="0 0 478 506" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M379.8 315.4C352.01 315.4 327.062 327.817 310.146 347.315L186.499 278.249C188.838 270.119 190.1 261.521 190.1 252.7C190.1 243.782 188.834 235.223 186.427 227.037L309.923 158.096C326.774 177.698 351.821 190.2 379.7 190.2C430.409 190.2 471.8 148.918 471.8 98.1C471.8 47.2863 430.514 6 379.7 6C328.886 6 287.6 47.2863 287.6 98.1C287.6 106.995 288.859 115.615 291.265 123.769L167.886 192.697C151.025 173.006 125.968 160.6 98.1 160.6C47.3908 160.6 6 201.882 6 252.7C6 303.523 47.3954 344.8 98.2 344.8C126.093 344.8 151.144 332.287 168.074 312.598L291.571 381.633C289.143 389.853 287.8 398.557 287.8 407.5C287.8 458.209 329.082 499.6 379.9 499.6C430.714 499.6 472 458.314 472 407.5C472 356.677 430.605 315.4 379.8 315.4ZM379.8 45.1C409.086 45.1 432.9 68.9137 432.9 98.2C432.9 127.486 409.086 151.3 379.8 151.3C350.514 151.3 326.7 127.486 326.7 98.2C326.7 68.9203 350.607 45.1 379.8 45.1ZM98.2 305.8C68.9137 305.8 45.1 281.986 45.1 252.7C45.1 223.414 68.9137 199.6 98.2 199.6C127.486 199.6 151.3 223.414 151.3 252.7C151.3 281.98 127.393 305.8 98.2 305.8ZM379.8 460.5C350.514 460.5 326.7 436.686 326.7 407.4C326.7 378.114 350.514 354.3 379.8 354.3C409.086 354.3 432.9 378.114 432.9 407.4C432.9 436.686 409.086 460.5 379.8 460.5Z" fill="#21252D" stroke="#21252D" stroke-width="12"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -1,17 +0,0 @@
|
|||||||
export function setupFrameResizeListener() {
|
|
||||||
const previewFrame = getPreviewFrame();
|
|
||||||
|
|
||||||
window.addEventListener('message', function (e) {
|
|
||||||
const RESIZE_CODE = 'resize:';
|
|
||||||
if (typeof e.data !== 'string' || !e.data.startsWith(RESIZE_CODE)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = JSON.parse(e.data.substring(RESIZE_CODE.length))
|
|
||||||
previewFrame.style.height = data.height + 'px'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPreviewFrame() {
|
|
||||||
return document.getElementById('preview_frame');
|
|
||||||
}
|
|
||||||
+133
-19
@@ -1,32 +1,146 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Scrollbars / Frame resizes notifications.
|
window.initBlock = initBlock;
|
||||||
(function () {
|
|
||||||
let height;
|
|
||||||
const heightLimit = window.outerHeight * 2;
|
|
||||||
|
|
||||||
handleHeightChange(); // Initial frame's height setup.
|
let template;
|
||||||
setupResizeListener(); // Listen to frame's height changes.
|
let data = {};
|
||||||
|
let reload;
|
||||||
|
|
||||||
///
|
// Blocks Initialization.
|
||||||
|
function initBlock(blockName = '', selector = '', cb) {
|
||||||
function setupResizeListener() {
|
reload = function () {
|
||||||
const resizeObserver = new ResizeObserver(handleHeightChange);
|
document.querySelectorAll(selector).forEach((el) => cb(el));
|
||||||
resizeObserver.observe(document.body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleHeightChange(entries) {
|
reload();
|
||||||
const updatedHeight = getCurrentHeight();
|
}
|
||||||
if (height === updatedHeight || updatedHeight > heightLimit) {
|
|
||||||
|
// Data Updates Listeners.
|
||||||
|
(function () {
|
||||||
|
loadDataOptions();
|
||||||
|
listenToDataOptionsUpdates();
|
||||||
|
|
||||||
|
function listenToDataOptionsUpdates() {
|
||||||
|
window.addEventListener('message', function (event) {
|
||||||
|
const message = event.data;
|
||||||
|
const prefix = 'dataUpdate:';
|
||||||
|
|
||||||
|
if (typeof message !== "string" || !message.startsWith(prefix)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RESIZE_CODE = 'resize:';
|
try {
|
||||||
height = updatedHeight;
|
data = JSON.parse(message.substring(prefix.length));
|
||||||
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*');
|
updateBlock({data});
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error parsing incoming data.', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentHeight() {
|
function getQueryParams() {
|
||||||
return document.querySelector('body > main').scrollHeight;
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const params = {};
|
||||||
|
|
||||||
|
for (const [key, value] of urlParams) {
|
||||||
|
params[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadDataOptions() {
|
||||||
|
const queryParameters = new URLSearchParams({name: getQueryParams().data || 'default'});
|
||||||
|
fetch(`/data?${queryParameters}`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((response) => {
|
||||||
|
data = response.data; // Update state.
|
||||||
|
updateBlock({data});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Listen to Template updates.
|
||||||
|
(function () {
|
||||||
|
initSocket();
|
||||||
|
|
||||||
|
function initSocket() {
|
||||||
|
const socket = window.io.connect();
|
||||||
|
|
||||||
|
socket.on('error', function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// socket.on('connect', function () {
|
||||||
|
// console.log('user connected', socket.id)
|
||||||
|
// });
|
||||||
|
|
||||||
|
socket.on('templateUpdate', function (args) {
|
||||||
|
updateBlock({template: args.template});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
function updateBlock(args = {}) {
|
||||||
|
if (args.template) {
|
||||||
|
template = args.template; // Update state.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.data) {
|
||||||
|
data = args.data; // Update state.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!template) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderBlock(template, data || {}, document.getElementById("hbs-container"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBlock(templateHbs, jsonData, target) {
|
||||||
|
const template = Handlebars.compile(templateHbs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlebars Helpers
|
||||||
|
*/
|
||||||
|
Handlebars.registerHelper('esc_attr', function (attr) {
|
||||||
|
return attr;
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper('esc_url', function (attr) {
|
||||||
|
return attr;
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper('esc_html', function (attr) {
|
||||||
|
return attr;
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper('base_url', function () {
|
||||||
|
return '/';
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper('inner_blocks', function (options) {
|
||||||
|
const content = options.data.root['inner_blocks'];
|
||||||
|
if (!content) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Handlebars.SafeString(content);
|
||||||
|
});
|
||||||
|
|
||||||
|
let html;
|
||||||
|
|
||||||
|
try {
|
||||||
|
html = template(jsonData);
|
||||||
|
} catch (e) {
|
||||||
|
html = `<div style="max-width: 1280px; margin: 1rem auto;">
|
||||||
|
<h1 style="all: unset; font-size: 1.5rem; font-weight: bold; display: block;">Syntax Error:</h1>
|
||||||
|
<pre style="all: unset; padding: 10px 15px; background-color: #ffe6e6; border: 1px solid red; border-radius: 0.25rem; overflow: auto; display: block; white-space: pre;">${e.toString()}</pre>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.innerHTML = html;
|
||||||
|
if (reload) {
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,13 +3,16 @@
|
|||||||
import {setupResponsiveness} from './toolbar/responsive.jsx';
|
import {setupResponsiveness} from './toolbar/responsive.jsx';
|
||||||
import {setupPublish} from "./toolbar/publish.jsx";
|
import {setupPublish} from "./toolbar/publish.jsx";
|
||||||
import {setupDataOptions} from "./toolbar/data-options/DataOptions.jsx";
|
import {setupDataOptions} from "./toolbar/data-options/DataOptions.jsx";
|
||||||
import {getPreviewFrame, setupFrameResizeListener} from "./frame/editor.js";
|
|
||||||
|
|
||||||
const rootAttributes = {
|
const rootAttributes = {
|
||||||
previewFrame: getPreviewFrame(),
|
previewFrame: getPreviewFrame(),
|
||||||
};
|
};
|
||||||
|
|
||||||
setupFrameResizeListener();
|
// setupFrameResizeListener();
|
||||||
setupResponsiveness(rootAttributes);
|
setupResponsiveness(rootAttributes);
|
||||||
setupDataOptions(rootAttributes);
|
setupDataOptions(rootAttributes);
|
||||||
setupPublish(rootAttributes);
|
setupPublish(rootAttributes);
|
||||||
|
|
||||||
|
function getPreviewFrame() {
|
||||||
|
return document.getElementById('preview_frame');
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import React, {useState} from "react";
|
||||||
|
import * as ReactDOM from "react-dom/client";
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
const wrapper = document.querySelector('#screen');
|
||||||
|
|
||||||
|
const root = ReactDOM.createRoot(wrapper);
|
||||||
|
const html = (<SyncScreen/>);
|
||||||
|
|
||||||
|
root.render(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SyncScreen() {
|
||||||
|
const [loading, setLoading] = useState(null);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
return <>
|
||||||
|
|
||||||
|
<section className="container py-5">
|
||||||
|
<h1 style={{marginBottom: '2rem'}}>Oops... Block not in sync.</h1>
|
||||||
|
{error && <p className="alert alert-danger">{error}</p>}
|
||||||
|
|
||||||
|
{loading ?
|
||||||
|
<>
|
||||||
|
{loading === 'syncing' &&
|
||||||
|
<p>Version upgrade in progress...</p>
|
||||||
|
}
|
||||||
|
<p>Please wait...</p>
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
<p>Your version of the block is not in sync with the cloud (not latest version).<br/>
|
||||||
|
Would you like to update it?</p>
|
||||||
|
<div className="options">
|
||||||
|
<button className="btn btn-primary" style={{marginRight: '0.5rem'}} onClick={runSyncLogic}>Yes, Update to
|
||||||
|
Latest
|
||||||
|
</button>
|
||||||
|
<button className="btn btn-secondary" onClick={ignoreVersionSync}>Ignore</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</>
|
||||||
|
|
||||||
|
async function ignoreVersionSync() {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
let data = {};
|
||||||
|
try {
|
||||||
|
const response = await fetch('/sync', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ignore: true}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
data = await response.json();
|
||||||
|
} catch (err) {
|
||||||
|
setError('Error: ' + err.message);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.status !== 200) {
|
||||||
|
setError(data.message);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => window.location.reload(), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runSyncLogic() {
|
||||||
|
setLoading('syncing');
|
||||||
|
|
||||||
|
let data = {};
|
||||||
|
try {
|
||||||
|
const response = await fetch('/sync', {method: 'POST'});
|
||||||
|
data = await response.json();
|
||||||
|
} catch (err) {
|
||||||
|
setError('Error: ' + err.message);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.status !== 200) {
|
||||||
|
setError(data.message);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => window.location.reload(), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
@@ -9,10 +9,21 @@ import {
|
|||||||
import {isClickOutside, isEscHit} from "../responsive-button/ResponsiveButton.jsx";
|
import {isClickOutside, isEscHit} from "../responsive-button/ResponsiveButton.jsx";
|
||||||
import {DesignPreview} from "./DesignPreview.jsx";
|
import {DesignPreview} from "./DesignPreview.jsx";
|
||||||
|
|
||||||
|
export const PRODUCTION_REGISTRY_URL = 'https://blocks-registery.axe-web.com';
|
||||||
|
|
||||||
function DataOptions(props = {}) {
|
function DataOptions(props = {}) {
|
||||||
props.rootAttributes = props.rootAttributes ?? {};
|
props.rootAttributes = props.rootAttributes ?? {};
|
||||||
|
|
||||||
const initialState = {dataName: 'default', data: {}, dataOptions: [], designPreview: []};
|
const initialState = {
|
||||||
|
dataName: 'default',
|
||||||
|
data: {},
|
||||||
|
dataText: '{}',
|
||||||
|
dataOptions: [],
|
||||||
|
designPreview: [],
|
||||||
|
errorMessage: null,
|
||||||
|
loading: false,
|
||||||
|
};
|
||||||
|
|
||||||
const [state, setState] = useState(initialState);
|
const [state, setState] = useState(initialState);
|
||||||
const [previewOption, setPreviewOption] = useState(getDesignPreviewImage(state.dataName, state.designPreview));
|
const [previewOption, setPreviewOption] = useState(getDesignPreviewImage(state.dataName, state.designPreview));
|
||||||
const updateState = (update) => setState(Object.assign({}, state, update));
|
const updateState = (update) => setState(Object.assign({}, state, update));
|
||||||
@@ -20,8 +31,7 @@ function DataOptions(props = {}) {
|
|||||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||||
|
|
||||||
useEffect(async () => {
|
useEffect(async () => {
|
||||||
const data = await fetchDataOptions(state.dataName);
|
await syncDataOptions(state.dataName);
|
||||||
updateState(data);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleCloseSidebarEscEvent = useCallback((e) => {
|
const handleCloseSidebarEscEvent = useCallback((e) => {
|
||||||
@@ -66,7 +76,7 @@ function DataOptions(props = {}) {
|
|||||||
<SidebarDataOptionsStyle>
|
<SidebarDataOptionsStyle>
|
||||||
<label htmlFor="data-options">Data Options</label>
|
<label htmlFor="data-options">Data Options</label>
|
||||||
|
|
||||||
<select name="data" id="data-options" onChange={(e) => changeDataOption(e)} value={state.dataName}>
|
<select name="data" id="data-options" onChange={(e) => changeDataOption(e)} value={state.dataName} disabled={state.loading}>
|
||||||
{state.dataOptions.map((item) => {
|
{state.dataOptions.map((item) => {
|
||||||
const isSelected = state.dataName === item;
|
const isSelected = state.dataName === item;
|
||||||
return <option value={item} selected={isSelected}>{item}</option>
|
return <option value={item} selected={isSelected}>{item}</option>
|
||||||
@@ -76,10 +86,21 @@ function DataOptions(props = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{state.data &&
|
{state.data &&
|
||||||
<pre>{JSON.stringify(state.data, null, 2)}</pre>
|
<textarea value={state.dataText} onChange={dataOptionUpdate} disabled={state.loading}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
<button className='btn btn--secondary' onClick={(e) => copyToClipboard(e, state.data)}>Copy to Clipboard</button>
|
{state.errorMessage &&
|
||||||
|
<p className={'alert alert--error'}>{state.errorMessage}</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
{state.loading &&
|
||||||
|
<p className={'alert'}>Loading, please wait...</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className={'actions'}>
|
||||||
|
<button className='btn btn--secondary' disabled={state.loading} onClick={(e) => copyToClipboard(e, state.data)}>Copy to Clipboard</button>
|
||||||
|
<button className='btn btn--secondary' disabled={state.loading} onClick={(e) => generateVariation(e, state.data)}>Generate Test</button>
|
||||||
|
</div>
|
||||||
</SidebarStyle>
|
</SidebarStyle>
|
||||||
</div>;
|
</div>;
|
||||||
|
|
||||||
@@ -87,6 +108,52 @@ function DataOptions(props = {}) {
|
|||||||
// Functions
|
// Functions
|
||||||
//
|
//
|
||||||
|
|
||||||
|
function generateVariation() {
|
||||||
|
const url = PRODUCTION_REGISTRY_URL + '/content-generator/';
|
||||||
|
|
||||||
|
const myHeaders = new Headers();
|
||||||
|
myHeaders.append("Content-Type", "application/json");
|
||||||
|
|
||||||
|
const requestOptions = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: myHeaders,
|
||||||
|
body: JSON.stringify({json: state.data}),
|
||||||
|
};
|
||||||
|
|
||||||
|
updateState({loading: true, errorMessage: null});
|
||||||
|
|
||||||
|
return fetch(url, requestOptions)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(result => {
|
||||||
|
console.log(result)
|
||||||
|
if (result.statusCode !== 200) {
|
||||||
|
throw new Error(result.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = result.variation;
|
||||||
|
updateState({dataText: JSON.stringify(data, null, 2), data, errorMessage: null, loading: false});
|
||||||
|
updateIframe(data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
updateState({loading: false, errorMessage: 'Something went wrong, please try again.'})
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function dataOptionUpdate(e) {
|
||||||
|
let data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
data = JSON.parse(e.target.value);
|
||||||
|
} catch (err) {
|
||||||
|
updateState({dataText: e.target.value, errorMessage: 'Invalid JSON, please review and try again.'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateState({dataText: e.target.value, data, errorMessage: null});
|
||||||
|
updateIframe(data);
|
||||||
|
}
|
||||||
|
|
||||||
function openSidebar() {
|
function openSidebar() {
|
||||||
setSidebarOpen(true);
|
setSidebarOpen(true);
|
||||||
setTimeout(() => document.querySelector('.sidebar-active').focus());
|
setTimeout(() => document.querySelector('.sidebar-active').focus());
|
||||||
@@ -98,10 +165,7 @@ function DataOptions(props = {}) {
|
|||||||
|
|
||||||
async function changeDataOption(e) {
|
async function changeDataOption(e) {
|
||||||
const dataName = e.target.value;
|
const dataName = e.target.value;
|
||||||
props.rootAttributes.previewFrame.src = window.devTool.previewFrameUrl + '?data=' + dataName;
|
await syncDataOptions(dataName);
|
||||||
|
|
||||||
const dataOption = await fetchDataOptions(dataName);
|
|
||||||
updateState(Object.assign({}, dataOption, {dataName}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchDataOptions(name = 'default') {
|
async function fetchDataOptions(name = 'default') {
|
||||||
@@ -133,6 +197,23 @@ function DataOptions(props = {}) {
|
|||||||
|
|
||||||
setPreviewOption(getDesignPreviewImage(state.dataName, state.designPreview));
|
setPreviewOption(getDesignPreviewImage(state.dataName, state.designPreview));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function syncDataOptions(dataName) {
|
||||||
|
const dataOptions = await fetchDataOptions(dataName);
|
||||||
|
updateIframe(dataOptions.data);
|
||||||
|
|
||||||
|
const newState = Object.assign({errorMessage: null},
|
||||||
|
dataOptions,
|
||||||
|
{dataName},
|
||||||
|
{dataText: JSON.stringify(dataOptions.data, null, 2)},
|
||||||
|
);
|
||||||
|
updateState(newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateIframe(data) {
|
||||||
|
const previewIframe = props.rootAttributes.previewFrame;
|
||||||
|
previewIframe.contentWindow.postMessage('dataUpdate:' + JSON.stringify(data || {}), '*');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyToClipboard(e, context) {
|
function copyToClipboard(e, context) {
|
||||||
|
|||||||
@@ -130,7 +130,8 @@ export function DesignPreview({previewOption = {widthDimension: 0}}) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const scrollbarOffset = 7;
|
// const scrollbarOffset = 7; // Looks like browser scrollbar is not included in the width calculation anymore.
|
||||||
|
const scrollbarOffset = 0;
|
||||||
return window.innerWidth / 2 - previewOption.widthDimension / 2 - scrollbarOffset;
|
return window.innerWidth / 2 - previewOption.widthDimension / 2 - scrollbarOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ export const SidebarStyle = styled.div`
|
|||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre, textarea {
|
||||||
|
height: 100%;
|
||||||
|
//min-height: 480px;
|
||||||
|
resize: vertical;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background-color: #EDF2F7;
|
background-color: #EDF2F7;
|
||||||
@@ -33,6 +36,20 @@ export const SidebarStyle = styled.div`
|
|||||||
border: 1px solid #cbd5e0;
|
border: 1px solid #cbd5e0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
display: block;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.alert--error {
|
||||||
|
color: red;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<svg width="478" height="506" viewBox="0 0 478 506" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M379.8 315.4C352.01 315.4 327.062 327.817 310.146 347.315L186.499 278.249C188.838 270.119 190.1 261.521 190.1 252.7C190.1 243.782 188.834 235.223 186.427 227.037L309.923 158.096C326.774 177.698 351.821 190.2 379.7 190.2C430.409 190.2 471.8 148.918 471.8 98.1C471.8 47.2863 430.514 6 379.7 6C328.886 6 287.6 47.2863 287.6 98.1C287.6 106.995 288.859 115.615 291.265 123.769L167.886 192.697C151.025 173.006 125.968 160.6 98.1 160.6C47.3908 160.6 6 201.882 6 252.7C6 303.523 47.3954 344.8 98.2 344.8C126.093 344.8 151.144 332.287 168.074 312.598L291.571 381.633C289.143 389.853 287.8 398.557 287.8 407.5C287.8 458.209 329.082 499.6 379.9 499.6C430.714 499.6 472 458.314 472 407.5C472 356.677 430.605 315.4 379.8 315.4ZM379.8 45.1C409.086 45.1 432.9 68.9137 432.9 98.2C432.9 127.486 409.086 151.3 379.8 151.3C350.514 151.3 326.7 127.486 326.7 98.2C326.7 68.9203 350.607 45.1 379.8 45.1ZM98.2 305.8C68.9137 305.8 45.1 281.986 45.1 252.7C45.1 223.414 68.9137 199.6 98.2 199.6C127.486 199.6 151.3 223.414 151.3 252.7C151.3 281.98 127.393 305.8 98.2 305.8ZM379.8 460.5C350.514 460.5 326.7 436.686 326.7 407.4C326.7 378.114 350.514 354.3 379.8 354.3C409.086 354.3 432.9 378.114 432.9 407.4C432.9 436.686 409.086 460.5 379.8 460.5Z" fill="#21252D" stroke="#21252D" stroke-width="12"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -5,6 +5,10 @@ function Publish(props = {}) {
|
|||||||
const [state, setState] = useState({loading: false});
|
const [state, setState] = useState({loading: false});
|
||||||
const updateState = (update) => setState(Object.assign({}, state, update));
|
const updateState = (update) => setState(Object.assign({}, state, update));
|
||||||
|
|
||||||
|
if (window.devTool.publicUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return <div>
|
return <div>
|
||||||
{state.loading &&
|
{state.loading &&
|
||||||
<div className="overlay overlay--loading">Loading, Please wait...</div>
|
<div className="overlay overlay--loading">Loading, Please wait...</div>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {ButtonStyling, ResponsiveButtonStyle, ResponsiveOptionsDropdown} from ".
|
|||||||
const responsiveOptions = {
|
const responsiveOptions = {
|
||||||
desktop: [1920, 1800, 1680, 1440, 1360, 1280, 1024],
|
desktop: [1920, 1800, 1680, 1440, 1360, 1280, 1024],
|
||||||
tablet: [992, 768, 600],
|
tablet: [992, 768, 600],
|
||||||
mobile: [480, 414, 375, 360],
|
mobile: [480, 414, 375, 360, 320],
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultResponsiveOptions = {
|
const defaultResponsiveOptions = {
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ function Responsive(props = {}) {
|
|||||||
function updateController() {
|
function updateController() {
|
||||||
let frameBreakpoint = breakpoint;
|
let frameBreakpoint = breakpoint;
|
||||||
if (typeof frameBreakpoint !== 'string') {
|
if (typeof frameBreakpoint !== 'string') {
|
||||||
frameBreakpoint = frameBreakpoint + 'px';
|
// const scrollbarWidth = 15; // Looks like browser's logic was changed and now scrollbar is not included in the width.
|
||||||
|
const scrollbarWidth = 0;
|
||||||
|
frameBreakpoint = (scrollbarWidth + frameBreakpoint) + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
previewFrame.style.setProperty('--breakpoint', frameBreakpoint);
|
previewFrame.style.setProperty('--breakpoint', frameBreakpoint);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
{{> (include_partial "layouts/partials/head") }}
|
||||||
|
|
||||||
|
<body class="{{#if iframeMode}}body--iframe{{/if}}">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<section class="fullscreen_layout"></section>
|
||||||
|
<div id="hbs-container"></div>
|
||||||
|
<section class="fullscreen_layout"></section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{> (include_partial "layouts/partials/scripts") }}
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
.preview {
|
.preview {
|
||||||
overflow-y: scroll;
|
|
||||||
height: calc(100% - var(--top_panel_height));
|
height: calc(100% - var(--top_panel_height));
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
@@ -9,17 +8,14 @@
|
|||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
|
//height: 100%;
|
||||||
|
|
||||||
--top_spacing: 0px;
|
--top_spacing: 0px;
|
||||||
--breakpoint_top_spacing: 30px;
|
--breakpoint_top_spacing: 30px;
|
||||||
|
|
||||||
margin-top: var(--top_spacing);
|
margin-top: var(--top_spacing);
|
||||||
height: 100%;
|
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
|
||||||
border: 0;
|
border: 0;
|
||||||
outline: 1px solid #E2E8F0;
|
|
||||||
|
|
||||||
transition: max-width .3s ease-in-out, width .3s ease-in-out, margin-top .3s ease-in-out;
|
transition: max-width .3s ease-in-out, width .3s ease-in-out, margin-top .3s ease-in-out;
|
||||||
|
|
||||||
&.has-breakpoint {
|
&.has-breakpoint {
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.preview {
|
.preview {
|
||||||
overflow-y: scroll;
|
|
||||||
height: calc(100% - var(--top_panel_height));
|
height: calc(100% - var(--top_panel_height));
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
@@ -127,10 +126,8 @@ body {
|
|||||||
--top_spacing: 0px;
|
--top_spacing: 0px;
|
||||||
--breakpoint_top_spacing: 30px;
|
--breakpoint_top_spacing: 30px;
|
||||||
margin-top: var(--top_spacing);
|
margin-top: var(--top_spacing);
|
||||||
height: 100%;
|
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border: 0;
|
border: 0;
|
||||||
outline: 1px solid #E2E8F0;
|
|
||||||
transition: max-width 0.3s ease-in-out, width 0.3s ease-in-out, margin-top 0.3s ease-in-out;
|
transition: max-width 0.3s ease-in-out, width 0.3s ease-in-out, margin-top 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
#preview_frame.has-breakpoint {
|
#preview_frame.has-breakpoint {
|
||||||
@@ -139,11 +136,11 @@ body {
|
|||||||
max-width: var(--breakpoint);
|
max-width: var(--breakpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
.open_in_new_tab, .palette {
|
.open_in_new_tab, .share, .palette {
|
||||||
--size: 1.5rem;
|
--size: 1.5rem;
|
||||||
width: var(--size);
|
width: var(--size);
|
||||||
height: 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-repeat: no-repeat;
|
||||||
background-size: calc(var(--size) - 0.15rem);
|
background-size: calc(var(--size) - 0.15rem);
|
||||||
background-position: center center;
|
background-position: center center;
|
||||||
@@ -159,7 +156,12 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.palette {
|
.palette {
|
||||||
background-image: url("/scripts/toolbar/images/icon-palette.svg");
|
background-image: url("/scripts/dist/toolbar/images/icon-palette.svg");
|
||||||
|
}
|
||||||
|
|
||||||
|
.share {
|
||||||
|
background-size: calc(var(--size) - 0.35rem);
|
||||||
|
background-image: url("/scripts/dist/toolbar/images/icon-share.svg");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*# sourceMappingURL=page--main.css.map */
|
/*# sourceMappingURL=page--main.css.map */
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"sourceRoot":"","sources":["page--main.scss","_buttons.scss","_overlay.scss","_page--preview.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;;AAGF;EACE;EACA;EAEA;;;ACTF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAGF;EACE;EACA;;AAGF;EACE;EACA;EACA;;;AC5BJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AFIF;EACE;EACA;EACA;EACA;EAEA;EACA;EACA;EAEA;EACA;EACA;EAEA;EACA;;AAEA;EACE;EACA;EACA;EACA;;AAEA;EACE;;AAEA;EAHF;IAII;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAKF;EADF;IAEI;;;AAKN;EAEE;EACA;EACA;EACA;;AAGF;EACE;;;AGlFJ;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EAEA;EACA;EAEA;EACA;EACA;EAEA;EACA;EAEA;;AAEA;EACE;EAEA;EACA;;;AH6DJ;EACE;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EAEE","file":"page--main.css"}
|
{"version":3,"sourceRoot":"","sources":["page--main.scss","_buttons.scss","_overlay.scss","_page--preview.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;;AAGF;EACE;EACA;EAEA;;;ACTF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAGF;EACE;EACA;;AAGF;EACE;EACA;EACA;;;AC5BJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AFIF;EACE;EACA;EACA;EACA;EAEA;EACA;EACA;EAEA;EACA;EACA;EAEA;EACA;;AAEA;EACE;EACA;EACA;EACA;;AAEA;EACE;;AAEA;EAHF;IAII;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAKF;EADF;IAEI;;;AAKN;EAEE;EACA;EACA;EACA;;AAGF;EACE;;;AGlFJ;EACE;EACA;;;AAGF;EACE;EACA;EACA;EACA;EAGA;EACA;EAEA;EACA;EACA;EACA;;AAEA;EACE;EAEA;EACA;;;AHiEJ;EACE;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EAEE;;;AAGF;EAEE;EACA","file":"page--main.css"}
|
||||||
@@ -92,7 +92,7 @@ body {
|
|||||||
width: var(--size);
|
width: var(--size);
|
||||||
height: 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-repeat: no-repeat;
|
||||||
background-size: calc(var(--size) - 0.15rem);
|
background-size: calc(var(--size) - 0.15rem);
|
||||||
background-position: center center;
|
background-position: center center;
|
||||||
@@ -110,5 +110,11 @@ body {
|
|||||||
|
|
||||||
.palette {
|
.palette {
|
||||||
@extend .open_in_new_tab;
|
@extend .open_in_new_tab;
|
||||||
background-image: url("/scripts/toolbar/images/icon-palette.svg");
|
background-image: url("/scripts/dist/toolbar/images/icon-palette.svg");
|
||||||
|
}
|
||||||
|
|
||||||
|
.share {
|
||||||
|
@extend .open_in_new_tab;
|
||||||
|
background-size: calc(var(--size) - 0.35rem);
|
||||||
|
background-image: url("/scripts/dist/toolbar/images/icon-share.svg");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
overflow-y: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
.body--iframe {
|
||||||
margin-left: auto;
|
overflow-y: scroll;
|
||||||
margin-right: 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 */
|
/*# 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"],"names":[],"mappings":"AAAA;EACE;;;AAIF;EACE;;;AAGF;EACE;EACA;EACA;EACA","file":"page--view.css"}
|
||||||
@@ -1,18 +1,15 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
overflow-y: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
// iFrame mode
|
||||||
margin-left: auto;
|
.body--iframe {
|
||||||
margin-right: auto;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container rules must be provided by the projectStyles (theme).
|
.fullscreen_layout {
|
||||||
//.container {
|
background-color: #9cc3ff;
|
||||||
// max-width: 1200px;
|
min-height: 100%;
|
||||||
// margin-left: auto;
|
background-image: url('https://i.ibb.co/pjwL8D1/shapelined-JBKdviwe-XI-unsplash.jpg');
|
||||||
// margin-right: auto;
|
background-size: cover;
|
||||||
// padding-left: 15px;
|
}
|
||||||
// padding-right: 15px;
|
|
||||||
//}
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Block Development Tool</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="screen">Loading...</div>
|
||||||
|
|
||||||
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
|
<script src="/scripts/dist/sync.min.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Generated
+570
-7855
File diff suppressed because it is too large
Load Diff
+22
-10
@@ -1,25 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "@axe-web/block-dev-tool",
|
"name": "@axe-web/block-dev-tool",
|
||||||
"version": "1.0.20",
|
"version": "1.0.36",
|
||||||
"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": {
|
||||||
"start": "component-dev",
|
"info": "BLOCK_NAME=ebooks-resources MODULE_PATH= node debug.js",
|
||||||
"info": "node debug.js",
|
"dev": "BLOCK_NAME=ebooks-resources MODULE_PATH= node server.js",
|
||||||
"dev": "NODE_ENV=development NODE_CONFIG_DIR=blocks/text-block/config BLOCK_NAME=text-block node server.js",
|
"build-platform": "BLOCK_NAME=ebooks-resources MODULE_PATH= node ./build.js",
|
||||||
"build": "rollup --config rollup.config.js",
|
"dev-dev-tool": "rollup --config rollup.config.js --watch",
|
||||||
"build-platform": "NODE_ENV=development NODE_CONFIG_DIR=blocks/text-block/config BLOCK_NAME=text-block node ./build.js",
|
"build-dev-tool": "rollup --config rollup.config.js"
|
||||||
"build-platform-cli": "component-build",
|
},
|
||||||
"dev-js": "NODE_ENV=development rollup --config rollup.config.js --watch"
|
"engines": {
|
||||||
|
"node": ">=14.17.3"
|
||||||
},
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@axe-web/create-block": "^1.1.30",
|
||||||
"@braintree/sanitize-url": "^6.0.0",
|
"@braintree/sanitize-url": "^6.0.0",
|
||||||
"archiver": "^5.3.1",
|
"archiver": "^5.3.1",
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
"browser-sync": "^2.27.9",
|
"browser-sync": "^2.27.9",
|
||||||
"config": "^3.3.7",
|
"config": "^3.3.7",
|
||||||
"escape-html": "^1.0.3",
|
"escape-html": "^1.0.3",
|
||||||
@@ -36,12 +39,15 @@
|
|||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"mem-fs": "^2.2.1",
|
"mem-fs": "^2.2.1",
|
||||||
"mem-fs-editor": "^9.5.0",
|
"mem-fs-editor": "^9.5.0",
|
||||||
|
"mime-types": "^2.1.35",
|
||||||
|
"ngrok": "^5.0.0-beta.2",
|
||||||
"node-fetch": "^3.2.10",
|
"node-fetch": "^3.2.10",
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.0",
|
||||||
"plugin-error": "^2.0.0",
|
"plugin-error": "^2.0.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"sanitize-html": "^2.7.1",
|
"sanitize-html": "^2.7.1",
|
||||||
"sass": "^1.50.1"
|
"sass": "^1.50.1",
|
||||||
|
"ws": "^8.13.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-react": "^7.18.6",
|
"@babel/preset-react": "^7.18.6",
|
||||||
@@ -56,18 +62,24 @@
|
|||||||
"rollup-plugin-copy": "^3.4.0",
|
"rollup-plugin-copy": "^3.4.0",
|
||||||
"rollup-plugin-jsx": "^1.0.3",
|
"rollup-plugin-jsx": "^1.0.3",
|
||||||
"rollup-plugin-terser": "^7.0.2",
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
|
"socket.io": "^4.6.2",
|
||||||
"styled-components": "^5.3.5"
|
"styled-components": "^5.3.5"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"component-dev": "./server.js",
|
"component-dev": "./server.js",
|
||||||
"component-build": "./build.js"
|
"component-build": "./build.js",
|
||||||
|
"component-info": "./debug.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
"env.js",
|
||||||
"helpers.js",
|
"helpers.js",
|
||||||
"debug.js",
|
"debug.js",
|
||||||
"layouts/**/*.hbs",
|
"layouts/**/*.hbs",
|
||||||
"layouts/styles/*.css*",
|
"layouts/styles/*.css*",
|
||||||
"layouts/scripts/dist/*.js*",
|
"layouts/scripts/dist/*.js*",
|
||||||
|
"layouts/scripts/dist/**/*.jpg",
|
||||||
|
"layouts/scripts/dist/**/*.png",
|
||||||
|
"layouts/scripts/dist/**/*.svg",
|
||||||
"platforms/**/*"
|
"platforms/**/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import path from "path";
|
|||||||
import {readFile, writeFile, mkdir, copyFile} from "fs/promises";
|
import {readFile, writeFile, mkdir, copyFile} from "fs/promises";
|
||||||
import {capitalize, getConfigs} from "../../helpers.js";
|
import {capitalize, getConfigs} from "../../helpers.js";
|
||||||
|
|
||||||
const {modulesPath, projectPath} = getConfigs();
|
|
||||||
|
|
||||||
export async function buildHubspotEmail(blockName) {
|
export async function buildHubspotEmail(blockName) {
|
||||||
const distPath = await createDistFolder(blockName);
|
const distPath = await createDistFolder(blockName);
|
||||||
|
|
||||||
@@ -20,14 +18,18 @@ export async function buildHubspotEmail(blockName) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createDistFolder(blockName) {
|
export async function createDistFolder(blockName, projectPath = '') {
|
||||||
const distPath = path.join('exports', 'hubspot', `${blockName}.module`);
|
const distPath = path.join(projectPath, 'exports', 'hubspot', `${blockName}.module`);
|
||||||
await mkdir(distPath, {recursive: true})
|
await mkdir(distPath, {recursive: true})
|
||||||
|
|
||||||
return distPath;
|
return distPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBlockFields(block = {}, type = 'content') {
|
export function getBlockFields(block = {}, type = 'content') {
|
||||||
|
if (!block['field_groups']) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const fields_group = block['field_groups'].find((group) => group.name === type);
|
const fields_group = block['field_groups'].find((group) => group.name === type);
|
||||||
const fields = [];
|
const fields = [];
|
||||||
|
|
||||||
@@ -217,6 +219,7 @@ export function convertToHubspotField(field = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function buildHubspotJSONFiles(distPath, metaData) {
|
export async function buildHubspotJSONFiles(distPath, metaData) {
|
||||||
|
const {modulesPath, projectPath} = getConfigs();
|
||||||
await writeFile(path.join(distPath, 'meta.json'), JSON.stringify(metaData, null, 4));
|
await writeFile(path.join(distPath, 'meta.json'), JSON.stringify(metaData, null, 4));
|
||||||
|
|
||||||
const blockJSON = await readFile(path.join(projectPath, 'block.json'), "utf8");
|
const blockJSON = await readFile(path.join(projectPath, 'block.json'), "utf8");
|
||||||
@@ -249,9 +252,11 @@ export async function buildHubspotJSONFiles(distPath, metaData) {
|
|||||||
|
|
||||||
|
|
||||||
export function handlebarsToHubl(handlebars) {
|
export function handlebarsToHubl(handlebars) {
|
||||||
|
handlebars = handlebars.replace(/{{ else }}/g, '{% else %}');
|
||||||
|
handlebars = handlebars.replace(/{{else}}/g, '{% else %}');
|
||||||
handlebars = handlebars.replace(/{{#if /g, '{% if module.');
|
handlebars = handlebars.replace(/{{#if /g, '{% if module.');
|
||||||
handlebars = handlebars.replace(/{{\/if}}/g, '{% endif %}');
|
handlebars = handlebars.replace(/{{\/if}}/g, '{% endif %}');
|
||||||
handlebars = handlebars.replace(/{{#each /g, '{% for module.');
|
handlebars = handlebars.replace(/{{#each /g, '{% for item in module.');
|
||||||
handlebars = handlebars.replace(/{{\/each}}/g, '{% endfor %}');
|
handlebars = handlebars.replace(/{{\/each}}/g, '{% endfor %}');
|
||||||
handlebars = handlebars.replace(/{{base_url}}/g, '');
|
handlebars = handlebars.replace(/{{base_url}}/g, '');
|
||||||
handlebars = handlebars.replace(/{esc_attr /g, '{');
|
handlebars = handlebars.replace(/{esc_attr /g, '{');
|
||||||
@@ -263,6 +268,7 @@ export function handlebarsToHubl(handlebars) {
|
|||||||
handlebars = handlebars.replace(/}}}/g, '}}');
|
handlebars = handlebars.replace(/}}}/g, '}}');
|
||||||
handlebars = handlebars.replace(/{{/g, '{{module.');
|
handlebars = handlebars.replace(/{{/g, '{{module.');
|
||||||
handlebars = handlebars.replace(/{{module. /g, '{{ module.');
|
handlebars = handlebars.replace(/{{module. /g, '{{ module.');
|
||||||
|
handlebars = handlebars.replace(/.url/g, '.src');
|
||||||
|
|
||||||
return handlebars;
|
return handlebars;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ import {copyFile, readFile, writeFile} from "fs/promises";
|
|||||||
import {capitalize, getConfigs} from "../../helpers.js";
|
import {capitalize, getConfigs} from "../../helpers.js";
|
||||||
import {buildHubspotJSONFiles, createDistFolder, handlebarsToHubl,} from "./hubspot-email-adapter.js";
|
import {buildHubspotJSONFiles, createDistFolder, handlebarsToHubl,} from "./hubspot-email-adapter.js";
|
||||||
|
|
||||||
const {modulesPath, projectPath} = getConfigs();
|
|
||||||
|
|
||||||
export async function buildHubspotPage(blockName) {
|
export async function buildHubspotPage(blockName) {
|
||||||
const distPath = await createDistFolder(blockName);
|
const {modulesPath, projectPath} = getConfigs();
|
||||||
|
const distPath = await createDistFolder(blockName, projectPath);
|
||||||
|
|
||||||
const srcPath = path.join(projectPath, 'src');
|
const srcPath = path.join(projectPath, 'src');
|
||||||
|
|
||||||
|
|||||||
+32
-20
@@ -11,7 +11,7 @@ use Brick\VarExporter\VarExporter;
|
|||||||
trait Custom_Handlebars {
|
trait Custom_Handlebars {
|
||||||
public array $custom_handlebars = [];
|
public array $custom_handlebars = [];
|
||||||
|
|
||||||
public function register_default_handlebar_helpers() {
|
public function register_default_handlebar_helpers(): void {
|
||||||
$this->add_handlebar( 'esc_url', function ( $context ) {
|
$this->add_handlebar( 'esc_url', function ( $context ) {
|
||||||
if ( function_exists( 'esc_url' ) ) {
|
if ( function_exists( 'esc_url' ) ) {
|
||||||
return esc_url( $context );
|
return esc_url( $context );
|
||||||
@@ -35,17 +35,9 @@ trait Custom_Handlebars {
|
|||||||
|
|
||||||
return $context;
|
return $context;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
$this->add_handlebar( 'safe_html', function ( $context ) {
|
|
||||||
if ( function_exists( 'wp_kses_post' ) ) {
|
|
||||||
return wp_kses_post( $context );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $context;
|
public function add_handlebar( $key, $func ): void {
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add_handlebar( $key, $func ) {
|
|
||||||
$this->custom_handlebars[ $key ] = $func;
|
$this->custom_handlebars[ $key ] = $func;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,12 +48,24 @@ class Component_Builder {
|
|||||||
public string $component_name = '';
|
public string $component_name = '';
|
||||||
public string $module_path = '';
|
public string $module_path = '';
|
||||||
public string $project_path = '';
|
public string $project_path = '';
|
||||||
|
private string $dist_path = '';
|
||||||
|
|
||||||
function __construct( $component_name, $module_path, $project_path ) {
|
function __construct( $args = [] ) {
|
||||||
$this->module_path = $module_path;
|
if ( ! isset( $args['backPath'] ) || ! isset( $args['projectPath'] ) || ! isset( $args['blockName'] ) || ! isset( $args['platform'] ) ) {
|
||||||
$this->project_path = $project_path;
|
throw new \Exception( 'Error: Missing arguments. Make sure all parameter passed.' );
|
||||||
$this->component_name = $component_name;
|
}
|
||||||
|
|
||||||
|
$this->module_path = $args['backPath'];
|
||||||
|
$this->project_path = $args['projectPath'];
|
||||||
|
$this->component_name = $args['blockName'];
|
||||||
|
|
||||||
|
$this->dist_path = __DIR__ . '/' . $this->module_path . '/../../' . $this->project_path . '/exports' . '/' . $args['platform'];
|
||||||
$this->register_default_handlebar_helpers();
|
$this->register_default_handlebar_helpers();
|
||||||
|
|
||||||
|
$this->add_handlebar( 'base_url', function ( $context ) {
|
||||||
|
$path = join( '/', [ $this->block_project, $this->block_name, 'templates' ] );
|
||||||
|
return join( '/', [ get_site_url(),'wp-content', 'axe-web-blocks', $path, '' ] );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
function build(): void {
|
function build(): void {
|
||||||
@@ -70,18 +74,20 @@ class Component_Builder {
|
|||||||
$this->buildTemplatePhpFile( $root_path );
|
$this->buildTemplatePhpFile( $root_path );
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildTemplatePhpFile( $root_path ) {
|
private function buildTemplatePhpFile( $root_path ): void {
|
||||||
$file_name = $this->get_handlebars_template( "$root_path/src/$this->component_name.template.hbs" );
|
$file_name = $this->get_handlebars_template( "$root_path/src/$this->component_name.template.hbs" );
|
||||||
|
|
||||||
$output_folder = $root_path . '/exports/wordpress/templates';
|
$output_folder = $this->dist_path . '/templates';
|
||||||
rename( $file_name, "$output_folder/$this->component_name.template.php" );
|
rename( $file_name, "$output_folder/$this->component_name.template.php" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_handlebars_template( $path = '' ): string {
|
private function get_handlebars_template( $path = '' ): string {
|
||||||
$template = file_get_contents( $path );
|
$template = file_get_contents( $path );
|
||||||
|
$template = preg_replace( '/{{inner_blocks}}/', '<InnerBlocks/>', $template );
|
||||||
|
|
||||||
$phpStr = LightnCandy::compile( $template,
|
$phpStr = LightnCandy::compile( $template,
|
||||||
[
|
[
|
||||||
'flags' => Flags::FLAG_NOESCAPE | Flags::FLAG_PARENT | Flags::FLAG_SPVARS | Flags::FLAG_ELSE | Flags::FLAG_JSLENGTH | Flags::FLAG_JSTRUE,
|
'flags' => Flags::FLAG_NOESCAPE | Flags::FLAG_PARENT | Flags::FLAG_SPVARS | Flags::FLAG_ELSE | Flags::FLAG_JSLENGTH | Flags::FLAG_JSTRUE | Flags::FLAG_THIS,
|
||||||
'helpers' => $this->custom_handlebars ?? [],
|
'helpers' => $this->custom_handlebars ?? [],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -106,21 +112,27 @@ class Component_Builder {
|
|||||||
* FILE INFO:
|
* FILE INFO:
|
||||||
* This file was generated by LightCandy::compile function.
|
* This file was generated by LightCandy::compile function.
|
||||||
* The original source is the .HBS(handlebars) file that is located next to this generated PHP file.
|
* The original source is the .HBS(handlebars) file that is located next to this generated PHP file.
|
||||||
|
*
|
||||||
|
* Compiled at " . date( 'Y-m-d h:i:s' ) . "
|
||||||
*/
|
*/
|
||||||
|
|
||||||
";
|
";
|
||||||
|
|
||||||
$t = file_put_contents( $file_path, '<?php ' . $comment . $content . ' ?>' );
|
$t = file_put_contents( $file_path, '<?php ' . $comment . $content . ' ?>' );
|
||||||
if ( $t === false ) {
|
if ( $t === false ) {
|
||||||
die( "Error: Can't generate HBS template to PHP file. Cache folder is not accessible." );
|
throw new \Exception( "Error: Can't generate HBS template to PHP file. Cache folder is not accessible." );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $file_path;
|
return $file_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function build( $args = [] ) {
|
/**
|
||||||
( new Component_Builder( $args['blockName'], $args['backPath'], $args['projectPath'] ) )->build();
|
* Functions below will be triggered by JavaScript (index.js).
|
||||||
|
*/
|
||||||
|
|
||||||
|
function build( $args = [] ): void {
|
||||||
|
( new Component_Builder( $args ) )->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,37 +2,66 @@
|
|||||||
|
|
||||||
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
||||||
|
|
||||||
use Core\Global_Functions;
|
class <%= blockClassModel %>_Component extends \Core\Component {
|
||||||
|
const VERSION = '<%= version %>';
|
||||||
class <%= blockClassModel %>_Component {
|
public $block_project = '<%= ownerFilename %>';
|
||||||
|
public $block_name = '<%= blockFilename %>';
|
||||||
public function __construct() {
|
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
|
||||||
// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
|
|
||||||
add_action( 'after_setup_theme', [ $this, 'register_assets' ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
function register_assets(): void {
|
function register_assets(): void {
|
||||||
wp_register_style( '<%= blockFilename %>',
|
$base_path = plugin_dir_url( __FILE__ ); // In Plugins
|
||||||
get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/styles/<%= blockFilename %>.min.css',
|
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/'; // In Theme
|
||||||
[ 'style-wp' ],
|
|
||||||
Global_Functions::get_current_version_number()
|
|
||||||
);
|
|
||||||
wp_enqueue_style( '<%= blockFilename %>' )
|
|
||||||
|
|
||||||
wp_register_script( 'script-<%= blockFilename %>',
|
$style_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::style_deps', [ 'assets-style' ] );
|
||||||
get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/scripts/<%= blockFilename %>.min.js',
|
wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', $style_deps, self::VERSION );
|
||||||
[ 'jquery', 'swiper' ],
|
|
||||||
Global_Functions::get_current_version_number(),
|
$script_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::script_deps', [ 'assets-script' ] );
|
||||||
true
|
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', $script_deps, self::VERSION, true );
|
||||||
);
|
|
||||||
wp_enqueue_script( 'script-<%= blockFilename %>' )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render( $args = [] ): void {
|
public function prepare_for_print() {
|
||||||
$args = array_merge( [], Helpers\<%= blockClassModel %>_Defaults::default_args( $args ), $args);
|
if ( ! is_admin() ) {
|
||||||
|
wp_enqueue_style( 'block-<%= blockFilename %>' );
|
||||||
|
wp_enqueue_script( 'block-<%= 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 );
|
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
|
||||||
|
|
||||||
echo apply_filters( 'the_content', wpautop( $output ) );
|
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' ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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' ),
|
||||||
|
]
|
||||||
|
]
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<%= blockClassModel %>_Component::get_instance();
|
||||||
|
// new <%= blockClassModel %>_Component();
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
<% 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 ) );
|
|
||||||
<% } %>
|
|
||||||
}
|
|
||||||
|
|
||||||
<% 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_elementor_widget) { %> function register_custom_logic(): void {
|
|
||||||
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
<% } %><% if (include_elementor_widget) { %> function register_elementor_widget( $widgets_manager ) {
|
|
||||||
$widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() );
|
|
||||||
}
|
|
||||||
|
|
||||||
<% } %><% 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' ]
|
|
||||||
],
|
|
||||||
]
|
|
||||||
] );
|
|
||||||
}
|
|
||||||
|
|
||||||
<% } %><% 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',
|
|
||||||
plugins_url( 'templates/gutenberg-block/build/front.js', __FILE__ ),
|
|
||||||
$asset_file_front['dependencies'],
|
|
||||||
$asset_file_front['version'],
|
|
||||||
true
|
|
||||||
);
|
|
||||||
} );<% } %>
|
|
||||||
}<% } %>
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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() {
|
||||||
|
return self::PLUGIN_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_title() {
|
||||||
|
return '<%= blockClassModel %>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_icon() {
|
||||||
|
return 'eicon-plus-square-o';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _register_controls() {
|
||||||
|
$block_data = \Core\Block::get_block_data( __DIR__ . '/../<%= blockFilename %>.block.json' );
|
||||||
|
\Core\Elementor_Block::register_groups( $block_data, $this );
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_style_depends() {
|
||||||
|
return [ 'block-<%= blockFilename %>' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_script_depends() {
|
||||||
|
return [ 'block-<%= blockFilename %>' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function render() {
|
||||||
|
$settings = $this->get_settings_for_display();
|
||||||
|
|
||||||
|
$component = new \AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\<%= blockClassModel %>_Component();
|
||||||
|
|
||||||
|
$args = $this->prepare( $settings );
|
||||||
|
$component->render( $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import {mkdir, copyFile} from "fs/promises";
|
import fs, {mkdir, copyFile} from "fs/promises";
|
||||||
import {capitalize, createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
|
import {capitalize, createFiles, getBlockName, getConfigs, readJSONFile} from "../../helpers.js";
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
import {copy} from "fs-extra";
|
import {copy} from "fs-extra";
|
||||||
@@ -9,15 +9,14 @@ import execPhp from "exec-php";
|
|||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
export async function buildWordPress(blockName, args = {}) {
|
||||||
const {modulesPath, projectPath} = getConfigs();
|
const {modulesPath, projectPath} = getConfigs();
|
||||||
|
|
||||||
export async function buildWordPress(blockName, isBlock = false) {
|
const distPath = path.join(projectPath, 'exports', args.platform);
|
||||||
const distPath = path.join(projectPath, 'exports', 'wordpress');
|
|
||||||
// await mkdir(distPath, {recursive: true})
|
// await mkdir(distPath, {recursive: true})
|
||||||
await mkdir(path.join(distPath, 'templates'), {recursive: true})
|
await mkdir(path.join(distPath, 'templates'), {recursive: true})
|
||||||
|
|
||||||
const blockFilePath = path.join(projectPath, 'block.json');
|
const blockFilePath = path.join(projectPath, 'block.json');
|
||||||
await copyFile(blockFilePath, path.join(distPath, 'block.json'));
|
|
||||||
|
|
||||||
let data = await readJSONFile(blockFilePath);
|
let data = await readJSONFile(blockFilePath);
|
||||||
Object.assign(data, getBlockName(data.name));
|
Object.assign(data, getBlockName(data.name));
|
||||||
@@ -34,17 +33,21 @@ export async function buildWordPress(blockName, isBlock = false) {
|
|||||||
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: false,
|
|
||||||
include_native_gutenberg_block: false,
|
|
||||||
include_script: true,
|
include_script: true,
|
||||||
include_elementor_widget: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await copyFile(blockFilePath, path.join(distPath, data.blockFilename + '.block.json'));
|
||||||
|
|
||||||
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : '';
|
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : '';
|
||||||
|
|
||||||
const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
|
const phpGeneratorPath = path.join(modulesPath, 'platforms', 'php');
|
||||||
await execCommand(`cd ${phpGeneratorPath} && composer install`);
|
await execCommand(`cd ${phpGeneratorPath} && composer install`);
|
||||||
await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'build', {blockName, backPath, projectPath});
|
await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'build', {
|
||||||
|
blockName,
|
||||||
|
backPath,
|
||||||
|
projectPath,
|
||||||
|
platform: args.platform
|
||||||
|
});
|
||||||
|
|
||||||
await copyStaticFile(
|
await copyStaticFile(
|
||||||
path.join(projectPath, 'src', 'styles', `${data.blockFilename}.min.css`),
|
path.join(projectPath, 'src', 'styles', `${data.blockFilename}.min.css`),
|
||||||
@@ -56,40 +59,30 @@ export async function buildWordPress(blockName, isBlock = false) {
|
|||||||
path.join(distPath, 'templates', 'scripts', `${data.blockFilename}.min.js`),
|
path.join(distPath, 'templates', 'scripts', `${data.blockFilename}.min.js`),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const imagesPath = path.join(projectPath, 'src', 'images');
|
||||||
|
await fs.access(imagesPath);
|
||||||
|
|
||||||
await copy(
|
await copy(
|
||||||
path.join(projectPath, 'src', 'images'),
|
path.join(imagesPath),
|
||||||
path.join(distPath, 'templates', 'images'),
|
path.join(distPath, 'templates', 'images'),
|
||||||
);
|
);
|
||||||
|
} catch (err) {
|
||||||
|
// Folder doesn't exist.
|
||||||
|
}
|
||||||
|
|
||||||
const phpDataObject = await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'jsonToPhp', {
|
const phpDataObject = await execPHPFile(path.join(phpGeneratorPath, 'build.php'), 'jsonToPhp', {
|
||||||
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}), [{
|
|
||||||
from: `templates/helpers/Template_Defaults.php`,
|
|
||||||
to: `helpers/${data.blockClassModel}_Defaults.php`,
|
|
||||||
}], {
|
|
||||||
pathDist: distPath,
|
|
||||||
generatorsPath: path.join(__dirname),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isBlock) {
|
|
||||||
await createFiles(data, [{
|
await createFiles(data, [{
|
||||||
from: `templates/Template_Component.php`,
|
from: `templates/helpers/Template_Elementor_Widget.php`,
|
||||||
to: `${data.blockClassModel}_Component.php`,
|
to: `helpers/${data.blockClassModel}_Elementor_Widget.php`,
|
||||||
}], {
|
}], {
|
||||||
pathDist: distPath,
|
pathDist: distPath,
|
||||||
generatorsPath: path.join(__dirname)
|
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, [{
|
await createFiles(data, [{
|
||||||
from: `templates/Template_Basic_Component.php`,
|
from: `templates/Template_Basic_Component.php`,
|
||||||
to: `${data.blockClassModel}_Component.php`,
|
to: `${data.blockClassModel}_Component.php`,
|
||||||
@@ -98,12 +91,11 @@ export async function buildWordPress(blockName, isBlock = false) {
|
|||||||
generatorsPath: path.join(__dirname)
|
generatorsPath: path.join(__dirname)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function execCommand(cmd = '') {
|
export function execCommand(cmd = '') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
exec(cmd, function (error, stdout) {
|
exec(cmd, function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('Error:', error)
|
console.log('Error:', error)
|
||||||
reject(error);
|
reject(error);
|
||||||
@@ -124,7 +116,7 @@ function execPHPFile(file = '', functionName = '', args = {}) {
|
|||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
php[functionName.toLowerCase()](args, (err, res, out, print) => {
|
php[functionName.toLowerCase()](args, (err, res, out) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(out);
|
console.error(out);
|
||||||
return reject(err);
|
return reject(err);
|
||||||
|
|||||||
@@ -47,4 +47,26 @@ export default [{
|
|||||||
commonjs(),
|
commonjs(),
|
||||||
!devMode && terser()
|
!devMode && terser()
|
||||||
]
|
]
|
||||||
|
}, {
|
||||||
|
input: 'layouts/scripts/sync.jsx',
|
||||||
|
output: {
|
||||||
|
file: 'layouts/scripts/dist/sync.min.js',
|
||||||
|
sourcemap: devMode
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
nodeResolve({
|
||||||
|
extensions: [".js"],
|
||||||
|
}),
|
||||||
|
replace({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||||
|
preventAssignment: true,
|
||||||
|
}),
|
||||||
|
babel({
|
||||||
|
compact: false,
|
||||||
|
babelHelpers: 'bundled',
|
||||||
|
presets: ["@babel/preset-react"],
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
!devMode && terser()
|
||||||
|
]
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import {PRODUCTION_REGISTRY_URL} from "./env.js";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {create} from 'express-handlebars';
|
import {create} from 'express-handlebars';
|
||||||
import fsExtra from 'fs-extra';
|
|
||||||
import browserSync from 'browser-sync';
|
import browserSync from 'browser-sync';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
@@ -19,28 +19,65 @@ import open from "open";
|
|||||||
import {sanitizeUrl} from "@braintree/sanitize-url";
|
import {sanitizeUrl} from "@braintree/sanitize-url";
|
||||||
import sanitizeHtml from 'sanitize-html';
|
import sanitizeHtml from 'sanitize-html';
|
||||||
import {escape} from "lodash-es";
|
import {escape} from "lodash-es";
|
||||||
import archiver from 'archiver';
|
import {
|
||||||
import {getBlockConfigs, getConfigs, readJSONFile} from "./helpers.js";
|
getBlockConfigs,
|
||||||
|
getBlockData,
|
||||||
|
getBlockName,
|
||||||
|
getConfigs,
|
||||||
|
getImagesList,
|
||||||
|
isFileEmpty,
|
||||||
|
readJSONFile,
|
||||||
|
removeCommentsFromCss,
|
||||||
|
removeCommentsFromJs,
|
||||||
|
replaceNames,
|
||||||
|
syncFilesWithCloud,
|
||||||
|
uploadFile,
|
||||||
|
verifyVersion,
|
||||||
|
zipProject
|
||||||
|
} from "./helpers.js";
|
||||||
import PluginError from 'plugin-error';
|
import PluginError from 'plugin-error';
|
||||||
|
import {Server} from "socket.io";
|
||||||
|
import {createServer} from 'http';
|
||||||
|
// import {authtoken, connect} from "ngrok";
|
||||||
|
import bodyParser from "body-parser";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const PRODUCTION_REGISTRY_URL = 'https://blocks-registery.axe-web.com';
|
|
||||||
|
|
||||||
const {isDev, modulesPath, projectPath, developmentBlockName} = getConfigs();
|
const {isDev, modulesPath, projectPath, developmentBlockName} = getConfigs();
|
||||||
const blocksRegistry = isDev ? 'http://localhost:3020' : PRODUCTION_REGISTRY_URL;
|
const blocksRegistry = isDev ? 'http://localhost:3020' : PRODUCTION_REGISTRY_URL;
|
||||||
|
const DevToolToken = 'D9lgz0TvzXCnp0xnwVBL109DaAR6Puk6F7YewDhgmP8='; // Temporary token for development purposes.
|
||||||
|
|
||||||
|
const dataFiles = await getDataFiles(projectPath);
|
||||||
|
const DEFAULT_VIEW_LAYOUT = 'alignfull';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State
|
||||||
|
*/
|
||||||
|
|
||||||
|
let port = 3000; // This variable is used in `*.hbs` and it will be updated once BrowserSync is ready.
|
||||||
|
let previewFrameUrl = `/`; // This variable is used in `*.hbs` and it will be updated once BrowserSync is ready.
|
||||||
|
let shareUrl = '';
|
||||||
|
const sessions = [];
|
||||||
|
let ignoreVersionSync = false;
|
||||||
|
let bs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init server
|
* Init server
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let port = 3000; // This variable is used in `*.hbs` and it will be updated once BrowserSync is ready.
|
|
||||||
let previewFrameUrl = `http://localhost:${port}`; // This variable is used in `*.hbs` and it will be updated once BrowserSync is ready.
|
|
||||||
const dataFiles = prepareListOfDataFiles(await fs.readdir(path.join(projectPath, 'data')));
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// parse application/x-www-form-urlencoded
|
||||||
|
app.use(bodyParser.urlencoded({extended: false}))
|
||||||
|
|
||||||
|
// parse application/json
|
||||||
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
|
const httpServer = createServer(app);
|
||||||
|
initSessionsServer(httpServer);
|
||||||
|
|
||||||
const sass = gulpSass(dartSass);
|
const sass = gulpSass(dartSass);
|
||||||
|
|
||||||
const hbs = create({
|
const hbs = create({
|
||||||
@@ -52,8 +89,6 @@ const hbs = create({
|
|||||||
}, esc_html(html) {
|
}, esc_html(html) {
|
||||||
// TODO: Check if we can remove this helper.
|
// TODO: Check if we can remove this helper.
|
||||||
return html;
|
return html;
|
||||||
}, safe_html(html) {
|
|
||||||
return sanitizeHtml(html);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -66,50 +101,85 @@ app.set('views', path.join(modulesPath, 'layouts'));
|
|||||||
// Routes
|
// Routes
|
||||||
//
|
//
|
||||||
|
|
||||||
app.get('/', async (req, res) => {
|
app.get('/', async (req, res, next) => {
|
||||||
let jsonFileName = req.query.data ? req.query.data : 'default';
|
const data = getBlockConfigs({modulesPath, dataFiles});
|
||||||
const data = await getBlockConfigs(jsonFileName, {includeConfigs: true, projectPath, modulesPath, dataFiles});
|
|
||||||
if (data.error && data.errorMessage) {
|
if (data.error && data.errorMessage) {
|
||||||
return res.send(data.errorMessage);
|
return res.send(data.errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseView = config.has('baseView') ? config.get('baseView') : 'container';
|
const baseView = config.has('baseView') ? config.get('baseView') : DEFAULT_VIEW_LAYOUT;
|
||||||
const baseViewUrl = `view/${baseView}`;
|
const baseViewUrl = `view/${baseView}`;
|
||||||
|
|
||||||
data.helpers = {
|
data.helpers = {
|
||||||
port,
|
|
||||||
include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath),
|
include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath),
|
||||||
baseView,
|
|
||||||
previewFrameUrl: `${previewFrameUrl}/${baseViewUrl}`,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const verifiedVersion = await verifyVersion(projectPath, blocksRegistry);
|
||||||
|
if (!verifiedVersion && !ignoreVersionSync) {
|
||||||
|
return res.render('sync', data);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = "Can't verify block version.";
|
||||||
|
console.log(errorMessage, err);
|
||||||
|
return next(new Error(errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
data.baseView = baseView;
|
||||||
|
data.port = `/${baseViewUrl}`;
|
||||||
|
data.previewFrameUrl = `${previewFrameUrl}/${baseViewUrl}`;
|
||||||
|
data.shareUrl = shareUrl;
|
||||||
|
|
||||||
|
// TODO: Need to review this logic, conflicts with the browsersync work after "/sync" action.
|
||||||
|
// if (req.headers.referer) {
|
||||||
|
// // NGROK, public URL
|
||||||
|
// data.shareUrl = undefined; // Link already shared.
|
||||||
|
// data.previewFrameUrl = `/${baseViewUrl}`;
|
||||||
|
// data.publicUrl = true;
|
||||||
|
// }
|
||||||
|
|
||||||
res.render('index', data);
|
res.render('index', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/view/:baseView', async (req, res) => {
|
app.get('/view/:baseView', (req, res) => {
|
||||||
let jsonFileName = req.query.data ? req.query.data : 'default';
|
const data = getDataOfFrame(!!req.query.iframe);
|
||||||
const data = await getBlockConfigs(jsonFileName, {includeConfigs: true, projectPath, modulesPath, dataFiles});
|
|
||||||
if (data.error && data.errorMessage) {
|
if (data.error && data.errorMessage) {
|
||||||
return res.send(data.errorMessage);
|
return res.send(data.errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockName = config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
const baseView = req.params.baseView ?? DEFAULT_VIEW_LAYOUT;
|
||||||
|
|
||||||
data.helpers = {
|
|
||||||
include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath),
|
|
||||||
include_block_template: () => handlebarLayoutsPath(projectPath, 'src', `${blockName}.template`),
|
|
||||||
section_class: `${blockName}--${jsonFileName}`,
|
|
||||||
base_url: '/'
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseView = req.params.baseView ?? 'container';
|
|
||||||
|
|
||||||
res.render(baseView, data)
|
res.render(baseView, data)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/publish', async (req, res) => {
|
app.get('/publish', async (req, res) => {
|
||||||
const data = await readJSONFile(path.join(projectPath, `block.json`));
|
const data = await readJSONFile(path.join(projectPath, `block.json`));
|
||||||
let responseData;
|
|
||||||
|
// Trigger build on the registry server only if the type of the unit is `foundation` or `component`.
|
||||||
|
const uploadStaticFiles = ['foundation', 'component'].includes(data.type);
|
||||||
|
|
||||||
|
// Prepare list of static files for the registry server.
|
||||||
|
if (uploadStaticFiles) {
|
||||||
|
data.static_files = {
|
||||||
|
css: getBlockName(data.name).name + '.min.css',
|
||||||
|
js: getBlockName(data.name).name + '.min.js',
|
||||||
|
images: await getImagesList(path.join(projectPath, 'src', 'images')),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await isFileEmpty(path.join(projectPath, `src/scripts`, data.static_files.js), true)) {
|
||||||
|
delete data.static_files.js;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.static_files.images.length) {
|
||||||
|
delete data.static_files.images;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let responseData = {
|
||||||
|
uploadBundleUrl: undefined,
|
||||||
|
staticFilesUrls: {}
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${blocksRegistry}`, {
|
const response = await fetch(`${blocksRegistry}`, {
|
||||||
@@ -129,35 +199,87 @@ app.get('/publish', async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseData.uploadUrl) {
|
// Start files uploading process.
|
||||||
await zipProject();
|
try {
|
||||||
const body = await fs.readFile(path.join(projectPath, 'dist.zip'));
|
if (responseData.uploadBundleUrl) {
|
||||||
const response = await fetch(`${responseData.uploadUrl}`, {
|
await zipProject(path.join(projectPath, 'src'), path.join(projectPath, 'dist.zip'));
|
||||||
method: 'PUT',
|
await uploadFile(path.join(projectPath, 'dist.zip'), responseData.uploadBundleUrl); // Bundle
|
||||||
body,
|
}
|
||||||
headers: {'Content-Type': 'application/zip'}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (uploadStaticFiles) {
|
||||||
res.json({success: false, message: "Can't upload the archive, permissions error."});
|
if (responseData.staticFilesUrls.css) {
|
||||||
|
await uploadFile(
|
||||||
|
path.join(projectPath, 'src/styles', data.static_files.css),
|
||||||
|
responseData.staticFilesUrls.css.uploadUrl,
|
||||||
|
(content) => {
|
||||||
|
if (responseData.staticFilesUrls.images) {
|
||||||
|
content = replaceNames(content, data.static_files.images, responseData.staticFilesUrls.images);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCommentsFromCss(content)
|
||||||
|
return content;
|
||||||
|
}); // CSS
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseData.staticFilesUrls.js) {
|
||||||
|
await uploadFile(
|
||||||
|
path.join(projectPath, 'src/scripts', data.static_files.js),
|
||||||
|
responseData.staticFilesUrls.js.uploadUrl,
|
||||||
|
(data) => removeCommentsFromJs(data)
|
||||||
|
); // JS
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseData.staticFilesUrls.images) {
|
||||||
|
for (let i = 0; i < data.static_files.images.length; i++) {
|
||||||
|
await uploadFile(
|
||||||
|
path.join(projectPath, 'src/images', data.static_files.images[i]),
|
||||||
|
responseData.staticFilesUrls.images[i].uploadUrl,
|
||||||
|
); // Images
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
// TODO: Need to update the registry server.
|
// TODO: Need to update the registry server.
|
||||||
await fs.unlink(path.join(projectPath, 'dist.zip'));
|
await fs.unlink(path.join(projectPath, 'dist.zip')); // Remove local bundle
|
||||||
|
|
||||||
|
res.json({success: false, message: err.message});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.unlink(path.join(projectPath, 'dist.zip')); // Remove local bundle
|
||||||
|
|
||||||
|
// Trigger project's global files build on the registry server.
|
||||||
|
if (uploadStaticFiles) {
|
||||||
|
try {
|
||||||
|
await triggerGlobalProjectFilesBuild(getBlockName(data.name).project);
|
||||||
|
} catch (err) {
|
||||||
|
res.json({success: false, message: 'Something wrong with Project Builder.'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await syncFilesWithCloud(path.join(projectPath, 'block.json'), bs);
|
||||||
|
} catch (err) {
|
||||||
|
res.json({success: false, message: err});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
res.json({success: true});
|
res.json({success: true});
|
||||||
|
|
||||||
await fs.unlink(path.join(projectPath, 'dist.zip'));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/data', async (req, res) => {
|
app.get('/data', async (req, res) => {
|
||||||
let jsonDataFileName = req.query.name ? req.query.name : 'default';
|
let jsonDataFileName = req.query.name ? req.query.name : 'default';
|
||||||
|
|
||||||
const dataFiles = prepareListOfDataFiles(await fs.readdir(path.join(projectPath, 'data')));
|
const dataFiles = await getDataFiles(projectPath);
|
||||||
const data = await getBlockConfigs(jsonDataFileName, {projectPath, modulesPath, dataFiles});
|
const data = await getBlockData(jsonDataFileName, {projectPath});
|
||||||
const designPreviewFiles = getListOfDesignPreviewFiles(jsonDataFileName, await fs.readdir(path.join(projectPath, 'design', 'preview')));
|
|
||||||
|
let designPreviewFiles = [];
|
||||||
|
try {
|
||||||
|
designPreviewFiles = getListOfDesignPreviewFiles(jsonDataFileName, await fs.readdir(path.join(projectPath, 'design', 'preview')));
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Preview Design doesn\'t exist');
|
||||||
|
}
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
dataOptions: dataFiles,
|
dataOptions: dataFiles,
|
||||||
@@ -166,6 +288,22 @@ app.get('/data', async (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/sync', async (req, res) => {
|
||||||
|
if (req.body['ignore']) {
|
||||||
|
ignoreVersionSync = true;
|
||||||
|
res.json({status: 200, message: 'Version upgrade is ignored.'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await syncFilesWithCloud(path.join(projectPath, `block.json`), bs, true);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({status: 500, message: err});
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({status: 200, message: 'Successfully synced!'});
|
||||||
|
});
|
||||||
|
|
||||||
// Errors handler
|
// Errors handler
|
||||||
app.use(handleSyntaxErrors);
|
app.use(handleSyntaxErrors);
|
||||||
|
|
||||||
@@ -174,10 +312,14 @@ app.use(express.static(path.join(projectPath, 'src')));
|
|||||||
app.use(express.static(path.join(projectPath, 'design')));
|
app.use(express.static(path.join(projectPath, 'design')));
|
||||||
app.use(express.static(path.join(modulesPath, 'layouts')));
|
app.use(express.static(path.join(modulesPath, 'layouts')));
|
||||||
|
|
||||||
|
// Custom Middleware
|
||||||
|
app.use(setHeaders);
|
||||||
|
|
||||||
// Setup Gulp
|
// Setup Gulp
|
||||||
await buildAssetFiles();
|
await buildAssetFiles();
|
||||||
|
|
||||||
// BrowserSync
|
// BrowserSync
|
||||||
|
shareUrl = await getShareableUrl();
|
||||||
const bsOptions = await startBrowserSync();
|
const bsOptions = await startBrowserSync();
|
||||||
port = bsOptions.port;
|
port = bsOptions.port;
|
||||||
previewFrameUrl = bsOptions.previewFrameUrl;
|
previewFrameUrl = bsOptions.previewFrameUrl;
|
||||||
@@ -206,14 +348,32 @@ function getListOfDesignPreviewFiles(jsonDataFileName, previewFiles) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDataOfFrame(isIframe = false) {
|
||||||
|
const data = {config: getBlockConfigs({modulesPath, dataFiles})};
|
||||||
|
if (data.error && data.errorMessage) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.helpers = {
|
||||||
|
include_partial: (filesPath) => handlebarLayoutsPath(modulesPath, filesPath),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isIframe) {
|
||||||
|
data.iframeMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
function startBrowserSync() {
|
function startBrowserSync() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const listener = app.listen(0, async () => {
|
const listener = httpServer.listen(0, async () => {
|
||||||
const PORT = listener.address().port;
|
const PORT = listener.address().port;
|
||||||
|
|
||||||
console.log(`The web server has started on port ${PORT}`);
|
console.log(`The web server has started on port ${PORT}`);
|
||||||
|
|
||||||
const bs = browserSync.create();
|
// BS is global variable.
|
||||||
|
bs = browserSync.create();
|
||||||
|
|
||||||
const files = getJSBundleFiles();
|
const files = getJSBundleFiles();
|
||||||
gulp.watch(files, {delay: 400}, gulp.series(['build-script-files', function (cb) {
|
gulp.watch(files, {delay: 400}, gulp.series(['build-script-files', function (cb) {
|
||||||
@@ -226,14 +386,22 @@ function startBrowserSync() {
|
|||||||
return cb();
|
return cb();
|
||||||
}]));
|
}]));
|
||||||
|
|
||||||
bs.watch("src/**/*.hbs", function (event, file) {
|
bs.watch(path.join(projectPath, "src/**/*.hbs"), function () {
|
||||||
browserSyncReload(bs, '', 'Template File Change: ' + file)
|
return syncTemplate(sessions);
|
||||||
});
|
});
|
||||||
|
|
||||||
bs.init({
|
const args = {
|
||||||
proxy: `http://localhost:${PORT}`,
|
proxy: `http://localhost:${PORT}`,
|
||||||
open: false
|
open: false
|
||||||
}, (err, bs) => {
|
};
|
||||||
|
|
||||||
|
if (shareUrl) {
|
||||||
|
args.socket = {
|
||||||
|
domain: shareUrl
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.init(args, (err, bs) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
@@ -288,8 +456,8 @@ function buildScriptFiles(done) {
|
|||||||
})
|
})
|
||||||
.pipe(gulp.src(path.join(projectPath, 'vendor/*.js')))
|
.pipe(gulp.src(path.join(projectPath, 'vendor/*.js')))
|
||||||
// .pipe(gulp.dest('src/'))
|
// .pipe(gulp.dest('src/'))
|
||||||
.pipe(uglify())
|
|
||||||
.pipe(rename({extname: '.min.js'}))
|
.pipe(rename({extname: '.min.js'}))
|
||||||
|
.pipe(uglify())
|
||||||
.pipe(sourcemaps.write('.'))
|
.pipe(sourcemaps.write('.'))
|
||||||
.pipe(gulp.dest(path.posix.join(projectPath, 'src')));
|
.pipe(gulp.dest(path.posix.join(projectPath, 'src')));
|
||||||
}
|
}
|
||||||
@@ -315,7 +483,7 @@ function buildAssetFiles() {
|
|||||||
|
|
||||||
// Run first build.
|
// Run first build.
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
gulp.series('build-script-files', 'build-styling-files', function (cb) {
|
gulp.series('build-script-files', 'build-styling-files', function () {
|
||||||
resolve();
|
resolve();
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
@@ -339,52 +507,6 @@ function prepareListOfDataFiles(dataFiles) {
|
|||||||
.sort();
|
.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) {
|
function handleSyntaxErrors(err, req, res, next) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.render('error', {
|
return res.render('error', {
|
||||||
@@ -402,3 +524,79 @@ function handlebarLayoutsPath() {
|
|||||||
return path.join(...arguments)
|
return path.join(...arguments)
|
||||||
.replace(/\\/g, '/'); // Windows path issue. Fix all "\" for Handlebars.
|
.replace(/\\/g, '/'); // Windows path issue. Fix all "\" for Handlebars.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initSessionsServer(httpServer) {
|
||||||
|
const io = new Server(httpServer);
|
||||||
|
io.on('connection', async (socket) => {
|
||||||
|
sessions.push(socket);
|
||||||
|
await syncTemplate(sessions);
|
||||||
|
});
|
||||||
|
|
||||||
|
return httpServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHeaders(req, res, next) {
|
||||||
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function syncTemplate(sessions = []) {
|
||||||
|
const blockName = config.has('blockName') ? config.get('blockName') : developmentBlockName;
|
||||||
|
const hbsTemplate = await fs.readFile(handlebarLayoutsPath(projectPath, 'src', `${blockName}.template.hbs`), 'utf8');
|
||||||
|
|
||||||
|
sessions.forEach(socket => {
|
||||||
|
socket.emit('templateUpdate', {template: hbsTemplate});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getShareableUrl() {
|
||||||
|
let domain = PRODUCTION_REGISTRY_URL;
|
||||||
|
let data = {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${domain}/dev-tool/?devToolToken=${DevToolToken}`);
|
||||||
|
data = await response.json();
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error:', `Can't load data from DevTool endpoint: ${domain}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.statusCode !== 200) {
|
||||||
|
console.log('Reply from DevTool endpoint:', data.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let url;
|
||||||
|
try {
|
||||||
|
// await authtoken(data.ngrokApiToken);
|
||||||
|
// url = await connect(port);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error:', `Can't connect to ngrok, probably wrong token.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function triggerGlobalProjectFilesBuild(project) {
|
||||||
|
const response = await fetch(`${blocksRegistry}/project-files`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({project}),
|
||||||
|
headers: {'Content-Type': 'application/json'}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDataFiles(projectPath) {
|
||||||
|
const dataFiles = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.access(path.join(projectPath, 'data'));
|
||||||
|
|
||||||
|
const files = prepareListOfDataFiles(await fs.readdir(path.join(projectPath, 'data')));
|
||||||
|
dataFiles.push(...files);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Warning: data folder not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataFiles;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* FUTURE TESTS.
|
||||||
|
*
|
||||||
|
* # ENV
|
||||||
|
* In `blocks-builder` service, we update MODULE_PATH and PROJECT_PATH environment variables before we run platform
|
||||||
|
* bundle build process. Actually before we call buildExportFiles().
|
||||||
|
*
|
||||||
|
* We have to make sure that this logic is working properly and stable.
|
||||||
|
*
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user