Merge pull request 'project-path-feat' (#7) from project-path-feat into master
Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
+5
-7
@@ -1,4 +1,5 @@
|
||||
import path from 'path';
|
||||
import {BLOCK_NAME, getModulePath, getProjectPath, IS_DEV} from "./env.js";
|
||||
import config from 'config';
|
||||
import {fileURLToPath} from 'url';
|
||||
import memFs from 'mem-fs';
|
||||
@@ -13,14 +14,11 @@ const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
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 {
|
||||
isDev,
|
||||
developmentBlockName,
|
||||
modulesPath: process.env.MODULE_PATH ?? (isDev ? '' : 'node_modules/block-dev-tool'),
|
||||
projectPath: process.env.PROJECT_PATH ?? (isDev ? path.join('blocks', developmentBlockName) : ''),
|
||||
isDev: IS_DEV,
|
||||
developmentBlockName: BLOCK_NAME,
|
||||
modulesPath: getModulePath(),
|
||||
projectPath: getProjectPath(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.25",
|
||||
"version": "1.0.26",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.25",
|
||||
"version": "1.0.26",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@braintree/sanitize-url": "^6.0.0",
|
||||
|
||||
+9
-9
@@ -1,19 +1,17 @@
|
||||
{
|
||||
"name": "@axe-web/block-dev-tool",
|
||||
"version": "1.0.25",
|
||||
"version": "1.0.26",
|
||||
"author": {
|
||||
"name": "AXE-WEB",
|
||||
"email": "office@axe-web.com",
|
||||
"url": "https://axe-web.com/"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "component-dev",
|
||||
"info": "node debug.js",
|
||||
"dev": "NODE_ENV=development NODE_CONFIG_DIR=blocks/header/config BLOCK_NAME=header node server.js",
|
||||
"build": "rollup --config rollup.config.js",
|
||||
"build-platform": "NODE_ENV=development NODE_CONFIG_DIR=blocks/header/config BLOCK_NAME=header node ./build.js",
|
||||
"build-platform-cli": "component-build",
|
||||
"dev-js": "NODE_ENV=development rollup --config rollup.config.js --watch"
|
||||
"info": "NODE_ENV=development BLOCK_NAME=header MODULE_PATH= node debug.js",
|
||||
"dev": "NODE_ENV=development BLOCK_NAME=header MODULE_PATH= node server.js",
|
||||
"build-platform": "NODE_ENV=development BLOCK_NAME=header MODULE_PATH= node ./build.js",
|
||||
"dev-dev-tool": "NODE_ENV=development rollup --config rollup.config.js --watch",
|
||||
"build-dev-tool": "rollup --config rollup.config.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17.3"
|
||||
@@ -63,9 +61,11 @@
|
||||
},
|
||||
"bin": {
|
||||
"component-dev": "./server.js",
|
||||
"component-build": "./build.js"
|
||||
"component-build": "./build.js",
|
||||
"component-info": "./debug.js"
|
||||
},
|
||||
"files": [
|
||||
"env.js",
|
||||
"helpers.js",
|
||||
"debug.js",
|
||||
"layouts/**/*.hbs",
|
||||
|
||||
@@ -18,8 +18,8 @@ export async function buildHubspotEmail(blockName) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function createDistFolder(blockName) {
|
||||
const distPath = path.join('exports', 'hubspot', `${blockName}.module`);
|
||||
export async function createDistFolder(blockName, projectPath = '') {
|
||||
const distPath = path.join(projectPath, 'exports', 'hubspot', `${blockName}.module`);
|
||||
await mkdir(distPath, {recursive: true})
|
||||
|
||||
return distPath;
|
||||
@@ -248,9 +248,11 @@ export async function buildHubspotJSONFiles(distPath, metaData) {
|
||||
|
||||
|
||||
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, '{% 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(/{{base_url}}/g, '');
|
||||
handlebars = handlebars.replace(/{esc_attr /g, '{');
|
||||
@@ -262,6 +264,7 @@ export function handlebarsToHubl(handlebars) {
|
||||
handlebars = handlebars.replace(/}}}/g, '}}');
|
||||
handlebars = handlebars.replace(/{{/g, '{{module.');
|
||||
handlebars = handlebars.replace(/{{module. /g, '{{ module.');
|
||||
handlebars = handlebars.replace(/.url/g, '.src');
|
||||
|
||||
return handlebars;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {buildHubspotJSONFiles, createDistFolder, handlebarsToHubl,} from "./hubs
|
||||
|
||||
export async function buildHubspotPage(blockName) {
|
||||
const {modulesPath, projectPath} = getConfigs();
|
||||
const distPath = await createDistFolder(blockName);
|
||||
const distPath = await createDistFolder(blockName, projectPath);
|
||||
|
||||
const srcPath = path.join(projectPath, 'src');
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import {PRODUCTION_REGISTRY_URL} from "./env.js";
|
||||
import path from 'path';
|
||||
import fetch from "node-fetch";
|
||||
import express from 'express';
|
||||
@@ -25,8 +26,6 @@ import PluginError from 'plugin-error';
|
||||
* Constants
|
||||
*/
|
||||
|
||||
const PRODUCTION_REGISTRY_URL = 'https://blocks-registery.axe-web.com';
|
||||
|
||||
const {isDev, modulesPath, projectPath, developmentBlockName} = getConfigs();
|
||||
const blocksRegistry = isDev ? 'http://localhost:3020' : PRODUCTION_REGISTRY_URL;
|
||||
|
||||
@@ -132,7 +131,7 @@ app.get('/publish', async (req, res) => {
|
||||
}
|
||||
|
||||
if (responseData.uploadUrl) {
|
||||
await zipProject(path.join(projectPath, 'src'));
|
||||
await zipProject(path.join(projectPath, 'src'), path.join(projectPath, 'dist.zip'));
|
||||
const body = await fs.readFile(path.join(projectPath, 'dist.zip'));
|
||||
const response = await fetch(`${responseData.uploadUrl}`, {
|
||||
method: 'PUT',
|
||||
@@ -228,7 +227,7 @@ function startBrowserSync() {
|
||||
return cb();
|
||||
}]));
|
||||
|
||||
bs.watch("src/**/*.hbs", function (event, file) {
|
||||
bs.watch(path.join(projectPath, "src/**/*.hbs"), function (event, file) {
|
||||
browserSyncReload(bs, '', 'Template File Change: ' + file)
|
||||
});
|
||||
|
||||
|
||||
@@ -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