marilena
Advanced tools
Comparing version 1.0.3 to 1.0.7
@@ -14,4 +14,6 @@ #!/usr/bin/env node | ||
require("../dist/lib/buildAllEmails"); | ||
} else if (argv["create-example"]) { | ||
require("../dist/create-example.js"); | ||
} else { | ||
logger.info("please use --build or --server commands"); | ||
logger.info("please use --build or --server or --create-example commands"); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CONFIG_FILE_NAME = exports.EVENT_NAME_NEED_REFRESH_WEBSOCKET = exports.FILE_NAME_EMAIL_METADATA = exports.FILE_NAME_EMAIL_VARIABLES = exports.FILE_NAME_COMMON_VARIABLES = void 0; | ||
exports.FILE_NAME_COMMON_VARIABLES = "common"; | ||
exports.FILE_NAME_EMAIL_VARIABLES = "variables"; | ||
exports.FILE_NAME_EMAIL_METADATA = "metadata"; | ||
exports.EVENT_NAME_NEED_REFRESH_WEBSOCKET = "need_refresh"; | ||
exports.CONFIG_FILE_NAME = "marilena.config.js"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var const_exports = {}; | ||
__export(const_exports, { | ||
CONFIG_FILE_NAME: () => CONFIG_FILE_NAME, | ||
EVENT_NAME_NEED_REFRESH_WEBSOCKET: () => EVENT_NAME_NEED_REFRESH_WEBSOCKET, | ||
FILE_NAME_COMMON_VARIABLES: () => FILE_NAME_COMMON_VARIABLES, | ||
FILE_NAME_EMAIL_METADATA: () => FILE_NAME_EMAIL_METADATA, | ||
FILE_NAME_EMAIL_VARIABLES: () => FILE_NAME_EMAIL_VARIABLES, | ||
SERVER_PORT: () => SERVER_PORT | ||
}); | ||
module.exports = __toCommonJS(const_exports); | ||
const FILE_NAME_COMMON_VARIABLES = "common"; | ||
const FILE_NAME_EMAIL_VARIABLES = "variables"; | ||
const FILE_NAME_EMAIL_METADATA = "metadata"; | ||
const EVENT_NAME_NEED_REFRESH_WEBSOCKET = "need_refresh"; | ||
const CONFIG_FILE_NAME = "marilena.config.mjs"; | ||
const SERVER_PORT = 8080; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
CONFIG_FILE_NAME, | ||
EVENT_NAME_NEED_REFRESH_WEBSOCKET, | ||
FILE_NAME_COMMON_VARIABLES, | ||
FILE_NAME_EMAIL_METADATA, | ||
FILE_NAME_EMAIL_VARIABLES, | ||
SERVER_PORT | ||
}); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var baseConfig_exports = {}; | ||
__export(baseConfig_exports, { | ||
default: () => baseConfig_default | ||
}); | ||
module.exports = __toCommonJS(baseConfig_exports); | ||
const config = { | ||
inputFolder: "input", | ||
outputFolder: "output", | ||
locales: ["en"], | ||
inputFolder: "input", | ||
outputFolder: "output", | ||
locales: ["en"] | ||
}; | ||
exports.default = config; | ||
var baseConfig_default = config; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../utils"); | ||
const buildWithConfig_1 = require("./buildWithConfig"); | ||
var import_utils = require("../utils"); | ||
var import_buildWithConfig = require("./buildWithConfig"); | ||
async function buildAllEmail() { | ||
const config = await (0, utils_1.loadConfig)(); | ||
(0, buildWithConfig_1.build)(config); | ||
const config = await (0, import_utils.loadConfig)(); | ||
(0, import_buildWithConfig.build)(config); | ||
} | ||
buildAllEmail(); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildSingle = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const inputOutputHtml_1 = require("./inputOutputHtml"); | ||
const loadVariables_1 = __importDefault(require("./loadVariables")); | ||
const node_color_log_1 = __importDefault(require("node-color-log")); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var buildSingleWithConfig_exports = {}; | ||
__export(buildSingleWithConfig_exports, { | ||
buildSingle: () => buildSingle | ||
}); | ||
module.exports = __toCommonJS(buildSingleWithConfig_exports); | ||
var import_fs = __toESM(require("fs")); | ||
var import_path = __toESM(require("path")); | ||
var import_inputOutputHtml = require("./inputOutputHtml"); | ||
var import_loadVariables = require("./loadVariables"); | ||
var import_node_color_log = __toESM(require("node-color-log")); | ||
var import_utils = require("../utils"); | ||
async function buildSingle(config, emailName) { | ||
const { inputFolder, outputFolder, locales, mjmlParsingOptions, textVersion, } = config; | ||
const inputFolderPath = path_1.default.join(inputFolder); | ||
const outputFolderPath = path_1.default.join(outputFolder); | ||
const inputEmailFilePath = path_1.default.join(inputFolderPath, emailName, `index.html`); | ||
const mjmlTemplate = fs_1.default.readFileSync(inputEmailFilePath, "utf-8"); | ||
// create folder for each email and locale if not exist | ||
for (const locale of locales) { | ||
const emailFolderPath = path_1.default.join(outputFolderPath, emailName, locale); | ||
if (!fs_1.default.existsSync(emailFolderPath)) { | ||
fs_1.default.mkdirSync(emailFolderPath, { recursive: true }); | ||
} | ||
const variables = (0, loadVariables_1.default)({ config, locale, emailName }); | ||
const html = await (0, inputOutputHtml_1.inputOutputHtml)({ | ||
inputHtml: mjmlTemplate, | ||
variables, | ||
templateOptions: config.templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion: false, | ||
const { | ||
inputFolder, | ||
outputFolder, | ||
locales, | ||
mjmlParsingOptions, | ||
textVersion, | ||
templateOptions | ||
} = config; | ||
const inputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", inputFolder); | ||
const outputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", outputFolder); | ||
const inputEmailFilePath = import_path.default.join( | ||
inputFolderPath, | ||
emailName, | ||
`index.html` | ||
); | ||
const mjmlTemplate = import_fs.default.readFileSync(inputEmailFilePath, "utf-8"); | ||
for (const locale of locales) { | ||
const emailFolderPath = import_path.default.join(outputFolderPath, emailName, locale); | ||
if (!import_fs.default.existsSync(emailFolderPath)) { | ||
import_fs.default.mkdirSync(emailFolderPath, { recursive: true }); | ||
} | ||
const variables = templateOptions ? import_loadVariables.VARIABLES_LOADER.loadAll({ config, locale }, emailName) : {}; | ||
const html = await (0, import_inputOutputHtml.inputOutputHtml)({ | ||
inputHtml: mjmlTemplate, | ||
variables, | ||
templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion: false | ||
}); | ||
const folderEmailPathLang = import_path.default.join(outputFolderPath, emailName, locale); | ||
if (!import_fs.default.existsSync(folderEmailPathLang)) { | ||
import_fs.default.mkdirSync(folderEmailPathLang, { recursive: true }); | ||
} | ||
try { | ||
import_fs.default.writeFileSync(import_path.default.join(folderEmailPathLang, "index.html"), html, { | ||
encoding: "utf-8" | ||
}); | ||
import_node_color_log.default.info("writed", emailName, locale); | ||
} catch (e) { | ||
import_node_color_log.default.error("failed writing", emailName, e); | ||
} | ||
if (textVersion) { | ||
try { | ||
const htmlOnlyText = await (0, import_inputOutputHtml.inputOutputHtml)({ | ||
inputHtml: mjmlTemplate, | ||
variables, | ||
templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion: true | ||
}); | ||
const folderEmailPathLang = path_1.default.join(outputFolderPath, emailName, locale); | ||
if (!fs_1.default.existsSync(folderEmailPathLang)) { | ||
fs_1.default.mkdirSync(folderEmailPathLang, { recursive: true }); | ||
} | ||
try { | ||
fs_1.default.writeFileSync(path_1.default.join(folderEmailPathLang, "index.html"), html, { | ||
encoding: "utf-8", | ||
}); | ||
node_color_log_1.default.info("writed", emailName, locale); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error("failed writing", emailName, e); | ||
} | ||
// text version | ||
if (textVersion) { | ||
try { | ||
const htmlOnlyText = await (0, inputOutputHtml_1.inputOutputHtml)({ | ||
inputHtml: mjmlTemplate, | ||
variables, | ||
templateOptions: config.templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion: true, | ||
}); | ||
fs_1.default.writeFileSync(path_1.default.join(folderEmailPathLang, textVersion(emailName, locale)), htmlOnlyText, { | ||
encoding: "utf-8", | ||
}); | ||
node_color_log_1.default.info("writed", emailName, locale, "text version"); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error("failed writing text version", emailName, e); | ||
} | ||
} | ||
import_fs.default.writeFileSync( | ||
import_path.default.join(folderEmailPathLang, textVersion(emailName, locale)), | ||
htmlOnlyText, | ||
{ | ||
encoding: "utf-8" | ||
} | ||
); | ||
import_node_color_log.default.info("writed", emailName, locale, "text version"); | ||
} catch (e) { | ||
import_node_color_log.default.error("failed writing text version", emailName, e); | ||
} | ||
} | ||
} | ||
} | ||
exports.buildSingle = buildSingle; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
buildSingle | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.build = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const buildSingleWithConfig_1 = require("./buildSingleWithConfig"); | ||
const utils_1 = require("../utils"); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var buildWithConfig_exports = {}; | ||
__export(buildWithConfig_exports, { | ||
build: () => build | ||
}); | ||
module.exports = __toCommonJS(buildWithConfig_exports); | ||
var import_fs = __toESM(require("fs")); | ||
var import_path = __toESM(require("path")); | ||
var import_buildSingleWithConfig = require("./buildSingleWithConfig"); | ||
var import_utils = require("../utils"); | ||
async function build(config) { | ||
const { inputFolder, outputFolder } = config; | ||
const inputFolderPath = path_1.default.join(inputFolder); | ||
const outputFolderPath = path_1.default.join(outputFolder); | ||
// create folder if not exist | ||
if (!fs_1.default.existsSync(outputFolderPath)) { | ||
fs_1.default.mkdirSync(outputFolderPath, { recursive: true }); | ||
} | ||
let list; | ||
try { | ||
const files = fs_1.default.readdirSync(inputFolderPath, { withFileTypes: true }); | ||
list = files | ||
.filter((f) => (0, utils_1.isEmailDirectory)(inputFolder, f)) | ||
.map((f) => f.name); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
list = []; | ||
} | ||
for (const emailName of list) { | ||
await (0, buildSingleWithConfig_1.buildSingle)(config, emailName); | ||
} | ||
const { inputFolder, outputFolder } = config; | ||
const inputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", inputFolder); | ||
const outputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", outputFolder); | ||
if (!import_fs.default.existsSync(outputFolderPath)) { | ||
import_fs.default.mkdirSync(outputFolderPath, { recursive: true }); | ||
} | ||
let list; | ||
try { | ||
const files = import_fs.default.readdirSync(inputFolderPath, { withFileTypes: true }); | ||
list = files.filter((f) => (0, import_utils.isEmailDirectory)(inputFolderPath, f)).map((f) => f.name); | ||
} catch (e) { | ||
console.error(e); | ||
list = []; | ||
} | ||
for (const emailName of list) { | ||
await (0, import_buildSingleWithConfig.buildSingle)(config, emailName); | ||
} | ||
} | ||
exports.build = build; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
build | ||
}); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.inject = void 0; | ||
const node_html_parser_1 = require("node-html-parser"); | ||
const const_1 = require("../const"); | ||
// this method append before body script mandatory to catch refresh by server via websocket | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var injectWebSocketNodeScript_exports = {}; | ||
__export(injectWebSocketNodeScript_exports, { | ||
inject: () => inject | ||
}); | ||
module.exports = __toCommonJS(injectWebSocketNodeScript_exports); | ||
var import_node_html_parser = require("node-html-parser"); | ||
var import_const = require("../const"); | ||
function inject(html) { | ||
const root = (0, node_html_parser_1.parse)(html); | ||
const scriptString = ` | ||
const root = (0, import_node_html_parser.parse)(html); | ||
const scriptString = ` | ||
<script> | ||
@@ -16,3 +35,3 @@ const socket = new WebSocket("ws://localhost:8080/socket"); | ||
const message = event.data; | ||
if(message === "${const_1.EVENT_NAME_NEED_REFRESH_WEBSOCKET}"){ | ||
if(message === "${import_const.EVENT_NAME_NEED_REFRESH_WEBSOCKET}"){ | ||
window.location.reload(); | ||
@@ -23,5 +42,8 @@ } | ||
`; | ||
root.insertAdjacentHTML("beforeend", scriptString); | ||
return root.innerHTML; | ||
root.insertAdjacentHTML("beforeend", scriptString); | ||
return root.innerHTML; | ||
} | ||
exports.inject = inject; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
inject | ||
}); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.inputOutputHtml = void 0; | ||
const mjml_1 = __importDefault(require("mjml")); | ||
const eta_1 = __importDefault(require("eta")); | ||
// import handlebars from "handlebars"; | ||
const node_color_log_1 = __importDefault(require("node-color-log")); | ||
const const_1 = require("../const"); | ||
const string_strip_html_1 = require("string-strip-html"); | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var inputOutputHtml_exports = {}; | ||
__export(inputOutputHtml_exports, { | ||
inputOutputHtml: () => inputOutputHtml | ||
}); | ||
module.exports = __toCommonJS(inputOutputHtml_exports); | ||
var import_mjml = __toESM(require("mjml")); | ||
var import_node_color_log = __toESM(require("node-color-log")); | ||
var import_const = require("../const"); | ||
var import_string_strip_html = require("string-strip-html"); | ||
const isTextExecution = process.env.NODE_ENV === "test"; | ||
async function inputOutputHtml({ inputHtml, variables, templateOptions, mjmlParsingOptions, isTextVersion, }) { | ||
async function rendereWithVars() { | ||
if (!templateOptions) { | ||
return inputHtml; | ||
} | ||
const { prepareEngine } = templateOptions; | ||
if (!prepareEngine) { | ||
node_color_log_1.default.error(`templateOptions options is defined, but prepareEngine is null. Please check method under ${const_1.CONFIG_FILE_NAME}`); | ||
} | ||
switch (templateOptions.engine) { | ||
case "eta": { | ||
if (!!prepareEngine) { | ||
prepareEngine(eta_1.default); | ||
} | ||
return eta_1.default.render(inputHtml, variables); | ||
} | ||
case "handlebars": { | ||
const handlebars = await Promise.resolve().then(() => __importStar(require("handlebars"))); | ||
if (!!prepareEngine) { | ||
prepareEngine(handlebars); | ||
} | ||
return handlebars.compile(inputHtml)(variables); | ||
} | ||
default: { | ||
node_color_log_1.default.info(`engine ${templateOptions.engine} not supported, so template will be parsed without fill variables. Please contribute to the repo :)`); | ||
return inputHtml; | ||
} | ||
} | ||
async function inputOutputHtml({ | ||
inputHtml, | ||
variables, | ||
templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion | ||
}) { | ||
async function rendereWithVars() { | ||
if (!templateOptions) { | ||
return inputHtml; | ||
} | ||
const mjmlTenplateWithVars = await rendereWithVars(); | ||
if (isTextVersion) { | ||
return (0, string_strip_html_1.stripHtml)(mjmlTenplateWithVars).result; | ||
const { prepareEngine } = templateOptions; | ||
if (!prepareEngine) { | ||
throw new Error( | ||
`templateOptions options is defined, but prepareEngine is null. Please check method under ${import_const.CONFIG_FILE_NAME}` | ||
); | ||
} | ||
if (isTextExecution) { | ||
return mjmlTenplateWithVars; | ||
switch (templateOptions.engine) { | ||
case "eta": { | ||
const { Eta } = await import("eta"); | ||
const eta = new Eta(); | ||
prepareEngine(eta); | ||
return await eta.renderStringAsync(inputHtml, variables); | ||
} | ||
case "handlebars": { | ||
const handlebars = await import("handlebars"); | ||
if (!!prepareEngine) { | ||
prepareEngine(handlebars); | ||
} | ||
return handlebars.compile(inputHtml)(variables); | ||
} | ||
default: { | ||
import_node_color_log.default.error( | ||
`engine ${templateOptions.engine} not supported, so template will be parsed without fill variables. Please contribute to the repo :)` | ||
); | ||
return inputHtml; | ||
} | ||
} | ||
const html = (0, mjml_1.default)(mjmlTenplateWithVars, mjmlParsingOptions).html; | ||
return html; | ||
} | ||
const mjmlTenplateWithVars = await rendereWithVars(); | ||
if (isTextVersion) { | ||
return (0, import_string_strip_html.stripHtml)(mjmlTenplateWithVars).result; | ||
} | ||
if (isTextExecution) { | ||
return mjmlTenplateWithVars; | ||
} | ||
const html = (0, import_mjml.default)(mjmlTenplateWithVars, mjmlParsingOptions).html; | ||
return html; | ||
} | ||
exports.inputOutputHtml = inputOutputHtml; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
inputOutputHtml | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const const_1 = require("../const"); | ||
const node_color_log_1 = __importDefault(require("node-color-log")); | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
function default_1(options) { | ||
const { inputFolder, templateOptions } = options.config; | ||
const locale = options.locale; | ||
const variablesType = templateOptions?.variablesType || "json"; | ||
let emailVariables = {}; | ||
let common = {}; | ||
switch (variablesType) { | ||
case "json": { | ||
try { | ||
common = JSON.parse(fs_1.default.readFileSync(path_1.default.join(inputFolder, `${const_1.FILE_NAME_COMMON_VARIABLES}-${locale}.json`), "utf-8")); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error(e); | ||
node_color_log_1.default.error(`cannot load common variables for email ${options.emailName} ${options.locale}. Please create ${const_1.FILE_NAME_COMMON_VARIABLES}-${locale}.json file under ${inputFolder}`); | ||
} | ||
try { | ||
emailVariables = JSON.parse(fs_1.default.readFileSync(path_1.default.join(inputFolder, options.emailName, locale, `${const_1.FILE_NAME_EMAIL_VARIABLES}.json`), "utf-8")); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error(e); | ||
node_color_log_1.default.error(`cannot load variables for email ${options.emailName} ${options.locale}. Please create ${const_1.FILE_NAME_EMAIL_VARIABLES}.json file under ${inputFolder}/${options.emailName}/${options.locale}`); | ||
} | ||
break; | ||
} | ||
case "yml": { | ||
try { | ||
common = js_yaml_1.default.load(fs_1.default.readFileSync(path_1.default.join(inputFolder, `${const_1.FILE_NAME_COMMON_VARIABLES}-${locale}.yml`), "utf-8")); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error(e); | ||
node_color_log_1.default.error(`cannot load common variables for email ${options.emailName} ${options.locale}. Please create ${const_1.FILE_NAME_COMMON_VARIABLES}-${locale}.yml file under ${inputFolder}`); | ||
} | ||
try { | ||
emailVariables = js_yaml_1.default.load(fs_1.default.readFileSync(path_1.default.join(inputFolder, options.emailName, locale, `${const_1.FILE_NAME_EMAIL_VARIABLES}.yml`), "utf-8")); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error(e); | ||
node_color_log_1.default.error(`cannot load variables for email ${options.emailName} ${options.locale}. Please create ${const_1.FILE_NAME_EMAIL_VARIABLES}.yml file under ${inputFolder}/${options.emailName}/${options.locale}`); | ||
} | ||
break; | ||
} | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var loadVariables_exports = {}; | ||
__export(loadVariables_exports, { | ||
VARIABLES_LOADER: () => VARIABLES_LOADER | ||
}); | ||
module.exports = __toCommonJS(loadVariables_exports); | ||
var import_path = __toESM(require("path")); | ||
var import_fs = __toESM(require("fs")); | ||
var import_const = require("../const"); | ||
var import_node_color_log = __toESM(require("node-color-log")); | ||
var import_js_yaml = __toESM(require("js-yaml")); | ||
var import_utils = require("../utils"); | ||
function loadCommon(options) { | ||
const { locale, config } = options; | ||
const { inputFolder } = config; | ||
const inputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", inputFolder); | ||
try { | ||
return import_js_yaml.default.load( | ||
import_fs.default.readFileSync( | ||
import_path.default.join( | ||
inputFolderPath, | ||
`${import_const.FILE_NAME_COMMON_VARIABLES}-${locale}.yml` | ||
), | ||
"utf-8" | ||
) | ||
); | ||
} catch (e) { | ||
try { | ||
const vars = JSON.parse( | ||
import_fs.default.readFileSync( | ||
import_path.default.join( | ||
inputFolderPath, | ||
`${import_const.FILE_NAME_COMMON_VARIABLES}-${locale}.json` | ||
), | ||
"utf-8" | ||
) | ||
); | ||
return vars; | ||
} catch { | ||
import_node_color_log.default.error( | ||
`cannot load common variables for "${locale}" locale. | ||
Please create file "${import_const.FILE_NAME_COMMON_VARIABLES}-${locale}" with .json or .yml extesnion file under ${inputFolderPath}. | ||
Using empty variables now.` | ||
); | ||
return {}; | ||
} | ||
} | ||
} | ||
function loadSingle(options, emailName) { | ||
const { config, locale } = options; | ||
const { inputFolder } = config; | ||
const inputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", inputFolder); | ||
let vars = {}; | ||
let founded = false; | ||
try { | ||
const ymlVarisblaes = import_js_yaml.default.load( | ||
import_fs.default.readFileSync( | ||
import_path.default.join( | ||
inputFolderPath, | ||
emailName, | ||
locale, | ||
`${import_const.FILE_NAME_EMAIL_VARIABLES}.yml` | ||
), | ||
"utf-8" | ||
) | ||
); | ||
vars = { ...vars, ...ymlVarisblaes }; | ||
founded = true; | ||
} catch (e) { | ||
} | ||
try { | ||
const jsonVariables = JSON.parse( | ||
import_fs.default.readFileSync( | ||
import_path.default.join( | ||
inputFolderPath, | ||
emailName, | ||
locale, | ||
`${import_const.FILE_NAME_EMAIL_VARIABLES}.json` | ||
), | ||
"utf-8" | ||
) | ||
); | ||
vars = { ...vars, ...jsonVariables }; | ||
founded = true; | ||
} catch (e) { | ||
} | ||
if (!founded) { | ||
import_node_color_log.default.error( | ||
`cannot load variables for email "${emailName}" ${locale}. Please create file "${import_const.FILE_NAME_EMAIL_VARIABLES}" with .json or .yml extension file under ${inputFolderPath}/${emailName}/${locale}` | ||
); | ||
} | ||
return vars; | ||
} | ||
const VARIABLES_LOADER = { | ||
loadCommon, | ||
loadSingle, | ||
loadAll: function(options, emailName) { | ||
return { | ||
...common, | ||
...emailVariables, | ||
...loadCommon(options), | ||
...loadSingle(options, emailName) | ||
}; | ||
} | ||
exports.default = default_1; | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
VARIABLES_LOADER | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setupWatcher = void 0; | ||
const node_watch_1 = __importDefault(require("node-watch")); | ||
const path_1 = __importDefault(require("path")); | ||
const const_1 = require("../const"); | ||
const setupWatcher = function (config, callbacks) { | ||
const { inputFolder, templateOptions } = config; | ||
const variablesType = templateOptions?.variablesType || "json"; | ||
const regex = new RegExp(`.*(.json|.yml|.html|.css)`); | ||
return (0, node_watch_1.default)([path_1.default.join(inputFolder), const_1.CONFIG_FILE_NAME], { recursive: true, filter: regex }, function (evt, name) { | ||
if (evt === "update") { | ||
const parts = name.split("/"); | ||
const emailName = parts[1]; | ||
if (name.endsWith(const_1.CONFIG_FILE_NAME)) { | ||
callbacks.handleEditConfig(emailName); | ||
} | ||
else if (name.endsWith(`${const_1.FILE_NAME_EMAIL_VARIABLES}.${variablesType}`)) { | ||
// chnged email variables | ||
const locale = parts[2]; | ||
callbacks.handleEditVariables(emailName, locale); | ||
} | ||
else if (name.endsWith(".html")) { | ||
// changed email template | ||
callbacks.handleEmailChange(emailName); | ||
} | ||
else if (name.startsWith(path_1.default.join(inputFolder, `${const_1.FILE_NAME_COMMON_VARIABLES}`))) { | ||
// changed common variables | ||
callbacks.handleEditVariables(emailName); | ||
} | ||
else if (name.endsWith(".css")) { | ||
// changed css | ||
callbacks.handleEditCss(emailName); | ||
} | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var watcher_exports = {}; | ||
__export(watcher_exports, { | ||
setupWatcher: () => setupWatcher | ||
}); | ||
module.exports = __toCommonJS(watcher_exports); | ||
var import_node_watch = __toESM(require("node-watch")); | ||
var import_path = __toESM(require("path")); | ||
var import_const = require("../const"); | ||
var import_utils = require("../utils"); | ||
const setupWatcher = function(config, callbacks) { | ||
const { inputFolder } = config; | ||
const regex = new RegExp(`.*(.json|.yml|.html|.css|.eta|.hbs)`); | ||
const pathConfig = (0, import_utils.getPathConfig)(); | ||
const inputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", inputFolder); | ||
return (0, import_node_watch.default)( | ||
[inputFolderPath, pathConfig], | ||
{ recursive: true, filter: regex }, | ||
function(evt, name) { | ||
if (evt === "update") { | ||
const baseName = import_path.default.basename(name); | ||
if (baseName.endsWith(import_const.CONFIG_FILE_NAME)) { | ||
callbacks.handleEditConfig(); | ||
} else if (baseName.endsWith(`.json`) || baseName.endsWith(`.yml`)) { | ||
callbacks.handleEditVariables(); | ||
} else if (baseName.endsWith(".html")) { | ||
callbacks.handleEmailChange(); | ||
} else if (baseName.endsWith(".css")) { | ||
callbacks.handleEditCss(); | ||
} | ||
}); | ||
} | ||
} | ||
); | ||
}; | ||
exports.setupWatcher = setupWatcher; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
setupWatcher | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handler = void 0; | ||
const utils_1 = require("../utils"); | ||
const fs_1 = __importDefault(require("fs")); | ||
const inputOutputHtml_1 = require("../lib/inputOutputHtml"); | ||
const loadVariables_1 = __importDefault(require("../lib/loadVariables")); | ||
const injectWebSocketNodeScript_1 = require("../lib/injectWebSocketNodeScript"); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var email_exports = {}; | ||
__export(email_exports, { | ||
handler: () => handler | ||
}); | ||
module.exports = __toCommonJS(email_exports); | ||
var import_utils = require("../utils"); | ||
var import_fs = __toESM(require("fs")); | ||
var import_inputOutputHtml = require("../lib/inputOutputHtml"); | ||
var import_loadVariables = require("../lib/loadVariables"); | ||
var import_injectWebSocketNodeScript = require("../lib/injectWebSocketNodeScript"); | ||
var import_path = __toESM(require("path")); | ||
const handler = async (request, reply) => { | ||
const config = await (0, utils_1.loadConfig)(); | ||
const { inputFolder, mjmlParsingOptions } = config; | ||
const email = request.params.email; | ||
const locale = request.params.locale; | ||
const mjmlTemplate = fs_1.default.readFileSync(`${inputFolder}/${email}/index.html`, "utf-8"); | ||
const html = await (0, inputOutputHtml_1.inputOutputHtml)({ | ||
inputHtml: mjmlTemplate, | ||
variables: (0, loadVariables_1.default)({ config, emailName: email, locale }), | ||
templateOptions: config.templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion: false, | ||
}); | ||
const htmlWithWebsocketScript = (0, injectWebSocketNodeScript_1.inject)(html); | ||
reply.header("content-type", "text/html"); | ||
reply.send(htmlWithWebsocketScript); | ||
const config = await (0, import_utils.loadConfig)(); | ||
const { inputFolder, mjmlParsingOptions } = config; | ||
const email = request.params.email; | ||
const locale = request.params.locale; | ||
const filePath = import_path.default.resolve( | ||
(0, import_utils.getPathConfig)(), | ||
"..", | ||
inputFolder, | ||
email, | ||
"index.html" | ||
); | ||
const mjmlTemplate = import_fs.default.readFileSync(filePath, "utf-8"); | ||
const html = await (0, import_inputOutputHtml.inputOutputHtml)({ | ||
inputHtml: mjmlTemplate, | ||
variables: import_loadVariables.VARIABLES_LOADER.loadAll({ config, locale }, email), | ||
templateOptions: config.templateOptions, | ||
mjmlParsingOptions, | ||
isTextVersion: false | ||
}); | ||
const htmlWithWebsocketScript = (0, import_injectWebSocketNodeScript.inject)(html); | ||
reply.header("content-type", "text/html"); | ||
reply.send(htmlWithWebsocketScript); | ||
}; | ||
exports.handler = handler; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
handler | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handler = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
const utils_1 = require("../utils"); | ||
const fs_1 = __importDefault(require("fs")); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var home_exports = {}; | ||
__export(home_exports, { | ||
handler: () => handler | ||
}); | ||
module.exports = __toCommonJS(home_exports); | ||
var import_path = __toESM(require("path")); | ||
var import_utils = require("../utils"); | ||
var import_fs = __toESM(require("fs")); | ||
const handler = async (request, reply) => { | ||
const { inputFolder } = await (0, utils_1.loadConfig)(); | ||
const inputFolderPath = path_1.default.join(inputFolder); | ||
let list = []; | ||
try { | ||
const folders = fs_1.default.readdirSync(inputFolderPath, { withFileTypes: true }); | ||
list = folders | ||
.filter((f) => (0, utils_1.isEmailDirectory)(inputFolder, f)) | ||
.map((folder) => ({ | ||
emailName: folder.name, | ||
url: path_1.default.join(inputFolderPath, folder.name), | ||
})); | ||
} | ||
catch { } | ||
console.log("xxx", list); | ||
const pathView = path_1.default.join(__dirname, "../pages/email-list.html"); | ||
reply.view(pathView, { list }); | ||
const { inputFolder } = await (0, import_utils.loadConfig)(); | ||
const inputFolderPath = import_path.default.resolve((0, import_utils.getPathConfig)(), "..", inputFolder); | ||
let list = []; | ||
try { | ||
const folders = import_fs.default.readdirSync(inputFolderPath, { withFileTypes: true }); | ||
list = folders.filter((f) => (0, import_utils.isEmailDirectory)(inputFolderPath, f)).map((folder) => ({ | ||
emailName: folder.name, | ||
url: import_path.default.join(folder.name) | ||
})); | ||
} catch { | ||
} | ||
const pathView = import_path.default.join("../pages/email-list.html"); | ||
reply.view(pathView, { list }); | ||
}; | ||
exports.handler = handler; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
handler | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handler = void 0; | ||
const utils_1 = require("../utils"); | ||
const path_1 = __importDefault(require("path")); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var list_languages_exports = {}; | ||
__export(list_languages_exports, { | ||
handler: () => handler | ||
}); | ||
module.exports = __toCommonJS(list_languages_exports); | ||
var import_utils = require("../utils"); | ||
var import_path = __toESM(require("path")); | ||
const handler = async (request, reply) => { | ||
const { locales } = await (0, utils_1.loadConfig)(); | ||
const email = request.params.email; | ||
/** this is a FEATURE | ||
if (locales.length === 1) { | ||
// single language so we redirect to /[locale] | ||
const locale = locales[0]; | ||
reply.redirect(`/input/${email}/${locale}`); | ||
} */ | ||
let list = []; | ||
locales.forEach((locale) => { | ||
list.push({ locale, url: `${email}/${locale}/index.html` }); | ||
}); | ||
const pathView = path_1.default.join(__dirname, "../pages/email-variants.html"); | ||
reply.view(pathView, { list }); | ||
const { locales } = await (0, import_utils.loadConfig)(); | ||
const email = request.params.email; | ||
let list = []; | ||
locales.forEach((locale) => { | ||
list.push({ locale, url: `${email}/${locale}/index.html` }); | ||
}); | ||
const pathView = import_path.default.join("../pages/email-variants.html"); | ||
reply.view(pathView, { list }); | ||
}; | ||
exports.handler = handler; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
handler | ||
}); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fastify_1 = __importDefault(require("fastify")); | ||
const view_1 = __importDefault(require("@fastify/view")); | ||
const websocket_1 = __importDefault(require("@fastify/websocket")); | ||
const eta_1 = __importDefault(require("eta")); | ||
const utils_1 = require("./utils"); | ||
const home_1 = require("./routes/home"); | ||
const list_languages_1 = require("./routes/list-languages"); | ||
const email_1 = require("./routes/email"); | ||
const node_color_log_1 = __importDefault(require("node-color-log")); | ||
const const_1 = require("./const"); | ||
const watcher_1 = require("./lib/watcher"); | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var import_fastify = __toESM(require("fastify")); | ||
var import_view = __toESM(require("@fastify/view")); | ||
var import_websocket = __toESM(require("@fastify/websocket")); | ||
var import_eta = require("eta"); | ||
var import_utils = require("./utils"); | ||
var import_home = require("./routes/home"); | ||
var import_list_languages = require("./routes/list-languages"); | ||
var import_email = require("./routes/email"); | ||
var import_node_color_log = __toESM(require("node-color-log")); | ||
var import_const = require("./const"); | ||
var import_watcher = require("./lib/watcher"); | ||
var import_path = __toESM(require("path")); | ||
async function startServer() { | ||
const config = await (0, utils_1.loadConfig)(); | ||
const { inputFolder } = config; | ||
let websocket; | ||
const server = (0, fastify_1.default)({ | ||
const config = await (0, import_utils.loadConfig)(); | ||
const eta = new import_eta.Eta(); | ||
const { inputFolder } = config; | ||
let websocket; | ||
const server = (0, import_fastify.default)({ | ||
// logger: true, | ||
}); | ||
server.register(import_view.default, { | ||
engine: { | ||
eta | ||
}, | ||
templates: import_path.default.join(__dirname, "pages") | ||
}); | ||
server.register(import_websocket.default); | ||
server.register(async function() { | ||
server.get("/socket", { websocket: true }, (connection, req) => { | ||
websocket = connection.socket; | ||
connection.socket.on("message", (message) => { | ||
connection.socket.send("hi from server"); | ||
}); | ||
connection.socket.on("close", () => { | ||
}); | ||
}); | ||
server.register(view_1.default, { | ||
engine: { | ||
eta: eta_1.default, | ||
}, | ||
}); | ||
server.register(websocket_1.default); | ||
server.register(async function () { | ||
server.get("/socket", { websocket: true }, (connection, req) => { | ||
websocket = connection.socket; | ||
connection.socket.on("message", (message) => { | ||
connection.socket.send("hi from server"); | ||
}); | ||
// Client disconnect | ||
connection.socket.on("close", () => { }); | ||
}); | ||
server.get("/", import_home.handler); | ||
server.get(`/:email`, import_list_languages.handler); | ||
server.get(`/:email/:locale/index.html`, import_email.handler); | ||
const watcher = (0, import_watcher.setupWatcher)(config, { | ||
handleEditVariables: function() { | ||
import_node_color_log.default.info("new variables: need to refresh"); | ||
websocket?.send(import_const.EVENT_NAME_NEED_REFRESH_WEBSOCKET); | ||
}, | ||
handleEmailChange: function() { | ||
import_node_color_log.default.info("email changed: need to refresh"); | ||
websocket?.send(import_const.EVENT_NAME_NEED_REFRESH_WEBSOCKET); | ||
}, | ||
handleEditCss() { | ||
import_node_color_log.default.info("css changed: need to refresh"); | ||
websocket?.send(import_const.EVENT_NAME_NEED_REFRESH_WEBSOCKET); | ||
}, | ||
handleEditConfig: function() { | ||
import_node_color_log.default.error( | ||
"Config changed, please stop and restart server. In the future this will be automatic" | ||
); | ||
} | ||
}); | ||
server.addHook("onClose", (_, done) => { | ||
watcher.close(); | ||
done(); | ||
}); | ||
server.ready().then(() => { | ||
server.listen({ port: import_const.SERVER_PORT }, async (err, address) => { | ||
if (err) { | ||
import_node_color_log.default.error(err); | ||
process.exit(1); | ||
} | ||
import_node_color_log.default.info("load server with config:"); | ||
console.log(config); | ||
import_node_color_log.default.color("blue").log(`Server listening at http://localhost:${import_const.SERVER_PORT}`); | ||
if (process.env.NODE_ENV !== "development") { | ||
import("open").then((m) => { | ||
m.default(`http://localhost:${import_const.SERVER_PORT}`); | ||
}); | ||
} | ||
}); | ||
// render list of email founded | ||
server.get("/", home_1.handler); | ||
// render list of locales for 1 email | ||
server.get(`/${inputFolder}/:email`, list_languages_1.handler); | ||
// render 1 email for 1 language | ||
server.get(`/${inputFolder}/:email/:locale/index.html`, email_1.handler); | ||
// inject config on each endpoint. Now we load with loadConfig in other parts. | ||
// Maybe we need to create a kind of wrapper or decorator... | ||
// server.addHook("onRequest", (request, reply, done) => { | ||
// const ciccio = 3; | ||
// (request.params as any).config = 3; | ||
// done(); | ||
// }); | ||
const watcher = (0, watcher_1.setupWatcher)(config, { | ||
handleEditVariables: function (emailName, locale) { | ||
node_color_log_1.default.info("new variables: need to refresh", emailName, locale); | ||
websocket?.send(const_1.EVENT_NAME_NEED_REFRESH_WEBSOCKET); | ||
}, | ||
handleEmailChange: function (emailName) { | ||
node_color_log_1.default.info("email changed: need to refresh", emailName); | ||
websocket?.send(const_1.EVENT_NAME_NEED_REFRESH_WEBSOCKET); | ||
}, | ||
handleEditCss(emailName) { | ||
node_color_log_1.default.info("css changed: need to refresh", emailName); | ||
websocket?.send(const_1.EVENT_NAME_NEED_REFRESH_WEBSOCKET); | ||
}, | ||
handleEditConfig: function () { | ||
node_color_log_1.default.error("Config changed, please stop and restart server. In the future this will be automatic"); | ||
}, | ||
}); | ||
server.addHook("onClose", (_, done) => { | ||
watcher.close(); | ||
done(); | ||
}); | ||
const port = 8080; | ||
server.ready().then(() => { | ||
server.listen({ port }, (err, address) => { | ||
if (err) { | ||
node_color_log_1.default.error(err); | ||
process.exit(1); | ||
} | ||
node_color_log_1.default.info("load server with config:"); | ||
console.log(config); | ||
node_color_log_1.default.color("blue").log(`Server listening at http://localhost:${port}`); | ||
}); | ||
}); | ||
}); | ||
} | ||
startServer(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var types_exports = {}; | ||
module.exports = __toCommonJS(types_exports); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEmailDirectory = exports.removeExtension = exports.loadConfig = void 0; | ||
const baseConfig_1 = __importDefault(require("./lib/baseConfig")); | ||
const node_color_log_1 = __importDefault(require("node-color-log")); | ||
const path_1 = __importDefault(require("path")); | ||
const const_1 = require("./const"); | ||
const fs_1 = __importDefault(require("fs")); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var utils_exports = {}; | ||
__export(utils_exports, { | ||
getPathConfig: () => getPathConfig, | ||
isEmailDirectory: () => isEmailDirectory, | ||
loadConfig: () => loadConfig, | ||
removeExtension: () => removeExtension | ||
}); | ||
module.exports = __toCommonJS(utils_exports); | ||
var import_baseConfig = __toESM(require("./lib/baseConfig")); | ||
var import_node_color_log = __toESM(require("node-color-log")); | ||
var import_path = __toESM(require("path")); | ||
var import_const = require("./const"); | ||
var import_fs = __toESM(require("fs")); | ||
var import_minimist = __toESM(require("minimist")); | ||
async function loadConfig() { | ||
try { | ||
const pathConfig = path_1.default.join(process.cwd(), `./${const_1.CONFIG_FILE_NAME}`); | ||
const config = await require(pathConfig); | ||
return { | ||
...baseConfig_1.default, | ||
...config, | ||
}; | ||
try { | ||
const configDefault = await import(getPathConfig()); | ||
const config = configDefault.default; | ||
return { | ||
...import_baseConfig.default, | ||
...config | ||
}; | ||
} catch (e) { | ||
import_node_color_log.default.error(`error loading ${import_const.CONFIG_FILE_NAME}, so use default config`, e); | ||
import_node_color_log.default.error(e); | ||
return import_baseConfig.default; | ||
} | ||
} | ||
function getPathConfig() { | ||
const defaultPathConfig = import_path.default.join(process.cwd(), `./${import_const.CONFIG_FILE_NAME}`); | ||
const { project } = (0, import_minimist.default)(process.argv.slice(2)); | ||
if (!!project) { | ||
if (typeof project === "boolean") { | ||
import_node_color_log.default.error( | ||
`you used --project but without specify path for ${import_const.CONFIG_FILE_NAME}` | ||
); | ||
} else if (typeof project === "string") { | ||
return import_path.default.resolve(process.cwd(), project); | ||
} | ||
catch (e) { | ||
node_color_log_1.default.error(`error loading ${const_1.CONFIG_FILE_NAME}, so use default config`, e); | ||
return baseConfig_1.default; | ||
} | ||
} | ||
return defaultPathConfig; | ||
} | ||
exports.loadConfig = loadConfig; | ||
function removeExtension(filename) { | ||
return filename.substring(0, filename.lastIndexOf(".")) || filename; | ||
return filename.substring(0, filename.lastIndexOf(".")) || filename; | ||
} | ||
exports.removeExtension = removeExtension; | ||
function isEmailDirectory(inputFolder, f) { | ||
const isDirectory = f.isDirectory(); | ||
const hasIndexHtnml = isDirectory && | ||
fs_1.default.existsSync(path_1.default.resolve(process.cwd(), inputFolder, f.name, "index.html")); | ||
return hasIndexHtnml; | ||
function isEmailDirectory(inputFolderPath, f) { | ||
const isDirectory = f.isDirectory(); | ||
const hasIndexHtnml = isDirectory && import_fs.default.existsSync(import_path.default.resolve(inputFolderPath, f.name, "index.html")); | ||
return hasIndexHtnml; | ||
} | ||
exports.isEmailDirectory = isEmailDirectory; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
getPathConfig, | ||
isEmailDirectory, | ||
loadConfig, | ||
removeExtension | ||
}); |
{ | ||
"name": "marilena", | ||
"version": "1.0.3", | ||
"version": "1.0.7", | ||
"description": "a tool to build emails with cool tools like mjml and different template engine like handlebars or eta.js", | ||
"scripts": { | ||
"build": "tsc -p tsconfig.json && npm run copy", | ||
"build": "tsc && npm run copy && etsc && npm run generate-types", | ||
"copy": "mkdir -p dist/pages && cp src/pages/*.html dist/pages", | ||
"compile-dev": "npm run build && node ./dist/server.js", | ||
"start": "clear && nodemon -e ts --exec \"npm run compile-dev\"", | ||
"build-emails": "clear && npm run build && node ./dist/lib/buildAllEmails.js", | ||
"test": "jest --silent=true", | ||
"start": "node dist/server.js --project playground/marilena.config.mjs", | ||
"start:example": "node dist/server.js --project marilena.config.mjs", | ||
"dev": "npm run copy && nodemon --project playground/marilena.config.mjs", | ||
"build-emails": "clear && npm run build && node ./dist/lib/buildAllEmails.js --project playground/marilena.config.mjs", | ||
"test": "npm run test:unit && npm run test:server && npm run test:example", | ||
"test:unit": "jest --silent=true", | ||
"test:server": "start-server-and-test start :8080 cy:run-server", | ||
"test:example": "node dist/create-example.js && start-server-and-test start:example :8080 cy:run-example", | ||
"jest-clean-cache": "jest --clearCache", | ||
"cy:open": "cypress open", | ||
"cy:run-server": "cypress run --spec cypress/e2e/server.cy.ts", | ||
"cy:run-example": "cypress run --spec cypress/e2e/create-example.cy.ts", | ||
"prepare": "husky install", | ||
"release": "release-it" | ||
"release": "release-it", | ||
"generate-types": "tsc --declaration --declarationDir ./dist --outDir temp ./src/types.ts && rm -rf temp", | ||
"prettier:check": "npx prettier --check .", | ||
"prettier:fix": "npx prettier --write .", | ||
"postinstall": "node dist/create-example.js" | ||
}, | ||
"types": "dist/types.d.ts", | ||
"bin": { | ||
"marilena": "./bin/marilena.js" | ||
"marilena": "bin/marilena.js" | ||
}, | ||
"main": "dist/server.js", | ||
"repository": { | ||
@@ -38,6 +51,7 @@ "type": "github", | ||
"dependencies": { | ||
"@fastify/view": "^7.4.1", | ||
"@fastify/websocket": "^7.1.3", | ||
"@fastify/view": "^8.0.0", | ||
"@fastify/websocket": "^8.1.0", | ||
"ejs": "^3.1.9", | ||
"eta": "^2.0.1", | ||
"esbuild-node-tsc": "^2.0.5", | ||
"eta": "^3.0.3", | ||
"fastify": "^4.14.1", | ||
@@ -56,4 +70,7 @@ "js-yaml": "^4.1.0", | ||
"@types/js-yaml": "^4.0.5", | ||
"@types/minimist": "^1.2.2", | ||
"@types/mjml": "^4.7.0", | ||
"@types/node": "^18.15.0", | ||
"cypress": "^12.16.0", | ||
"esbuild": "0.18.11", | ||
"handlebars": "^4.7.7", | ||
@@ -63,7 +80,8 @@ "husky": "^8.0.3", | ||
"lint-staged": "^13.2.1", | ||
"nodemon": "^2.0.21", | ||
"prettier": "^2.8.7", | ||
"nodemon": "^3.0.1", | ||
"prettier": "^3.0.0", | ||
"release-it": "^15.10.1", | ||
"rimraf": "^5.0.1", | ||
"ts-jest": "^29.0.5", | ||
"start-server-and-test": "^2.0.0", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^4.9.5" | ||
@@ -79,10 +97,8 @@ }, | ||
"github": { | ||
"release": false | ||
"release": true | ||
}, | ||
"plugins": { | ||
"@release-it/keep-a-changelog": { | ||
"filename": "CHANGELOG.md" | ||
} | ||
"npm": { | ||
"publish": false | ||
} | ||
} | ||
} |
@@ -25,22 +25,36 @@ # Intro | ||
1 - create a `marilena.config.js` file under root of your project: | ||
1 - create a `marilena.config.mjs` file. Preferably under the root project: | ||
```js | ||
// this is an example of config structure | ||
module.exports = { | ||
inputFolder: "input", | ||
outputFolder: "output", | ||
locales: ["en", "it"], | ||
import path from "path"; | ||
// you can leverage your IDE's intellisense with jsdoc type hints | ||
/** @type {import('marilena').Config} */ | ||
export default { | ||
inputFolder: "./input", | ||
outputFolder: "./output", | ||
textVersion: (emailName, locale) => `${emailName}_text_version-${locale}.txt`, | ||
locales: ["it", "en"], | ||
templateOptions: { | ||
engine: "eta", | ||
variablesType: "json", | ||
prepareEngine: (xxx) => { | ||
// engine eta => xxx = eta | ||
// engine handlebars => xxx = handlebars | ||
// read below about this part | ||
prepareEngine: (eta) => { | ||
eta.configure({ | ||
views: path.join(process.cwd(), "playground/input"), | ||
}); | ||
}, | ||
}, | ||
mjmlParsingOptions: { | ||
keepComments: false, | ||
}, | ||
}; | ||
``` | ||
1A - if you put `marilena.config.mjs` in a different path folder you have to update scripts: | ||
```json | ||
"scripts": { | ||
"start": "marilena --server --project myFolder/marilena.config.mjs", | ||
"build": "marilena --build --project myFolder/marilena.config.mjs", | ||
}, | ||
``` | ||
2 - create a file structures based on your config. Please remember that each email template requires `index.html` as name, and variables are loaded only from `variables.json` or `variables.yml`. | ||
@@ -50,13 +64,13 @@ | ||
project | ||
| marilena.config.js | ||
| marilena.config.mjs | ||
β package.json | ||
β input | ||
β βββcommon-en.[variablesType] // common variables for all en emails | ||
β βββcommon-xx.[variablesType] // common variables for all xx emails | ||
β βββcommon-en.json // common json variables for all en emails | ||
β βββcommon-it.yaml // common yaml variables for all it emails | ||
β βββbuy // email name | ||
ββββββββββ index.html | ||
ββββββββββ en | ||
ββββββββββββββ variables.json | ||
ββββββββββββββ variables.json // json variables for en buy email | ||
ββββββββββ it | ||
ββββββββββββββ variables.json | ||
ββββββββββββββ variables.yaml // yaml variables for it buy email | ||
``` | ||
@@ -71,3 +85,3 @@ | ||
<mj-column> | ||
<!-- read below about template engine --> | ||
<!-- eta js example, read below about template engine --> | ||
<mj-text>hello <%= it.user %></mj-text> | ||
@@ -92,18 +106,14 @@ </mj-column> | ||
--- | ||
## Configuration | ||
Under the hood a default configuration will be loaded but a file `marilena.config.js` allow us to set: | ||
Under the hood a default configuration will be loaded but a file `marilena.config.mjs` allow us to set: | ||
| name | required | description | default | | ||
|--------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------| | ||
| inputFolder | X | folder where email are in the project | input | | ||
| outputFolder | X | folder used for generated email (when run build command) | output | | ||
| inputFolder | X | folder where email are in the project. Path is relative to `marilena.config.mjs` | input | | ||
| outputFolder | X | folder used for generated email (when run build command). Path is relative to `marilena.config.mjs` | output | | ||
| locales | X | array of languages used. If you company has only spanish email use an array of single value | ["en"] | | ||
| templateOptions | | if you chose to use one of supported engines, this part id required to setup custom partial and other settings for the template engine selected. Read below for some use cases | empty | | ||
| templateOptions | | if you chose to use one of supported engines, this part is mandatory to setup custom partial and other settings for the template engine selected. Read below for some use cases | empty | | ||
| mjmlParsingOptions | | options passed to mjml render. See: [mjml options](https://www.npmjs.com/package/mjml) | ||
| textVersion | | function of type `(emailName: string, locale: string) => string`. If set, this function allow to generate text version of email stripping all html. The function must return file name `es: ${emailName}-${locale}-text-version.txt` | ||
--- | ||
## About templateOptions | ||
@@ -114,3 +124,2 @@ | ||
- `engine`: `eta` or `handlebars` are supported. Apart `eta`, which is used also in the project library, all others requires dependency installed since `marilena` use lazy import for engines. | ||
- `variablesType`: define if variables are loaded from json file or yaml file. At this moment only `json` are supported. | ||
- `prepareEngine`: define a callback where we can setup our engine. Basically you can define all things before the render. For example: | ||
@@ -121,5 +130,4 @@ | ||
engine: "eta", | ||
variablesType: "json", | ||
prepareEngine: (eta) => { | ||
// we set out folder for templates/layout/partials | ||
// eta is an istance of new Eta() so you need to set at least views options for templates/layout/partials | ||
eta.configure({ | ||
@@ -129,4 +137,3 @@ views: path.join(process.cwd(), "input"), | ||
// we can register partial like: | ||
// eta is same of var eta = require("eta"); | ||
eta.templates.define("partial_1", eta.compile("this is partial 1")); | ||
eta.loadTemplate(...); | ||
}, | ||
@@ -139,3 +146,2 @@ }, | ||
engine: "handlebars", | ||
variablesType: "json", | ||
prepareEngine: (h) => { | ||
@@ -168,12 +174,12 @@ // we can register partial like: | ||
- [x] load variables with template engine | ||
- [x] eta.js, handlebars | ||
- [x] eta.js, handlebars (need to install if you use one of these engines) | ||
- [ ] ejs, nunjucks, mustache, dot, liquid | ||
- [x] fast-refresh on variables changes | ||
- [x] fast-refresh on template change | ||
- [x] fast-refresh on css change | ||
- [x] load varibles from yaml format | ||
- [x] load varibles from yaml/json format | ||
- [x] load common variables | ||
- [x] pass option to MJML render | ||
- [ ] config in typescript | ||
- [ ] ejs, nunjucks, mustache, dot, liquid | ||
- [ ] easy way to send a real email | ||
- [ ] fast-refresh on config change |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
67755
29
1432
177
13
19
1
16
1
+ Addedesbuild-node-tsc@^2.0.5
+ Added@esbuild/aix-ppc64@0.21.5(transitive)
+ Added@esbuild/android-arm@0.21.5(transitive)
+ Added@esbuild/android-arm64@0.21.5(transitive)
+ Added@esbuild/android-x64@0.21.5(transitive)
+ Added@esbuild/darwin-arm64@0.21.5(transitive)
+ Added@esbuild/darwin-x64@0.21.5(transitive)
+ Added@esbuild/freebsd-arm64@0.21.5(transitive)
+ Added@esbuild/freebsd-x64@0.21.5(transitive)
+ Added@esbuild/linux-arm@0.21.5(transitive)
+ Added@esbuild/linux-arm64@0.21.5(transitive)
+ Added@esbuild/linux-ia32@0.21.5(transitive)
+ Added@esbuild/linux-loong64@0.21.5(transitive)
+ Added@esbuild/linux-mips64el@0.21.5(transitive)
+ Added@esbuild/linux-ppc64@0.21.5(transitive)
+ Added@esbuild/linux-riscv64@0.21.5(transitive)
+ Added@esbuild/linux-s390x@0.21.5(transitive)
+ Added@esbuild/linux-x64@0.21.5(transitive)
+ Added@esbuild/netbsd-x64@0.21.5(transitive)
+ Added@esbuild/openbsd-x64@0.21.5(transitive)
+ Added@esbuild/sunos-x64@0.21.5(transitive)
+ Added@esbuild/win32-arm64@0.21.5(transitive)
+ Added@esbuild/win32-ia32@0.21.5(transitive)
+ Added@esbuild/win32-x64@0.21.5(transitive)
+ Added@fastify/view@8.2.0(transitive)
+ Added@fastify/websocket@8.3.1(transitive)
+ Addedesbuild@0.21.5(transitive)
+ Addedesbuild-node-tsc@2.0.5(transitive)
+ Addedeta@3.4.0(transitive)
+ Addedtypescript@5.4.5(transitive)
- Removed@fastify/view@7.4.1(transitive)
- Removed@fastify/websocket@7.2.0(transitive)
- Removedeta@2.2.0(transitive)
Updated@fastify/view@^8.0.0
Updated@fastify/websocket@^8.1.0
Updatedeta@^3.0.3