Socket
Socket
Sign inDemoInstall

marilena

Package Overview
Dependencies
220
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    marilena

a tool to build emails with cool tools like mjml and different template engine like handlebars or eta.js


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.0.3

22 June 2023

Readme

Source

Intro

Emails are hard to develop. There are some awesome library that makes the development more easy. But each library allow us to do a single thing without focus on a full development flow. This project wants to mix up MJML, a template engine for variables/logic and a web server, to create a basic an opinioned simple tool to generate email with a simple flow and command. Please Remember that market offers some cool services like Stripo, Mailchimp and others.

🚀 Usage

Install (require node >=18)

npm i marilena

How to use it

0 - setup your package.json:

"scripts": {
  "start": "marilena --server",
  "build": "marilena --build",
  ...other
},

1 - create a marilena.config.js file under root of your project:

// this is an example of config structure
module.exports = {
  inputFolder: "input",
  outputFolder: "output",
  locales: ["en", "it"],
  templateOptions: {
    engine: "eta",
    variablesType: "json",
    prepareEngine: (xxx) => {
      // engine eta => xxx = eta
      // engine handlebars => xxx = handlebars
      // read below about this part
    },
  },
};

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.

project
| marilena.config.js
│ package.json
│ input
│ └──common-en.[variablesType] // common variables for all en emails
│ └──common-xx.[variablesType] // common variables for all xx emails
│ └──buy // email name
││││││└─── index.html
││││││└─── en
│││││││││││└── variables.json
││││││└─── it
│││││││││││└── variables.json

3 - fill your emails template with MJML syntax

<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <!-- read below about template engine -->
        <mj-text>hello <%= it.user %></mj-text>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>

4 - run one of these 2 commands

# open a server on http://localhost:8080
npm run start
# build all emails based on config (template engine, output folder, and locales)
npm run build

Configuration

Under the hood a default configuration will be loaded but a file marilena.config.js allow us to set:

namerequireddescriptiondefault
inputFolderXfolder where email are in the projectinput
outputFolderXfolder used for generated email (when run build command)output
localesXarray of languages used. If you company has only spanish email use an array of single value["en"]
templateOptionsif 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 casesempty
mjmlParsingOptionsoptions passed to mjml render. See: mjml options
textVersionfunction 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

This project can producte output html from input template. But in a real word probably we store variables in some part and render some content multiple times (example a footer). In this case templateOptions can define:

  • 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:
	templateOptions: {
		engine:  "eta",
		variablesType:  "json",
		prepareEngine: (eta) => {
            // we set out folder for templates/layout/partials
            eta.configure({
              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"));
		},
	},
	templateOptions: {
		engine:  "handlebars",
		variablesType:  "json",
		prepareEngine: (h) => {
            // we can register partial like:
            // handlebars is same of var h = require("handlebars");
            h.registerPartial("myPartial", "partial with {{ user }}");
		},
	},

Use css

If you want to add a css file import in mj-include tag. Path start from root directory of the project (like package json):

<mjml>
  <mj-body>
    <mj-include path="input/styles.css" type="css" css-inline="inline"/>
    <!-- other mjml nodes -->
  </mj-body>
</mjml>

🚀 features

  • MJML support
  • load variables with template engine
  • eta.js, handlebars
  • fast-refresh on variables changes
  • fast-refresh on template change
  • fast-refresh on css change
  • load varibles from yaml format
  • load common variables
  • 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

Keywords

FAQs

Last updated on 22 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc