mikser-io-post-mjml 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/index.js +33 -0
  4. package/package.json +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Almero Digital Marketing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # mikser-io-post-mjml
2
+
3
+ [MJML](https://www.npmjs.com/package/mjml) postprocessor for [Mikser](https://github.com/almero-digital-marketing/mikser-io). Compiles a rendered MJML document into responsive email-safe HTML.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install mikser-io-post-mjml
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ // mikser.config.js
15
+ export default {
16
+ plugins: ['post-mjml'],
17
+ 'post-mjml': {
18
+ options: { keepComments: false, minify: true }
19
+ }
20
+ }
21
+ ```
22
+
23
+ `'post-mjml'.options` is passed through to [`mjml2html`](https://www.npmjs.com/package/mjml). The plugin sets `validationLevel: 'soft'` by default.
24
+
25
+ ## Layout naming
26
+
27
+ Mikser's convention for layouts that need a postprocessor is `<name>.<format>-<postprocessor>.<template>`. Use the `-mjml` suffix to opt in:
28
+
29
+ | Layout file | Renderer output | Final output |
30
+ |---|---|---|
31
+ | `welcome.html-mjml.hbs` | MJML markup (rendered via HBS) | `welcome.html` |
32
+ | `welcome.html-mjml.liquid` | MJML markup (rendered via Liquid) | `welcome.html` |
33
+
34
+ The renderer's job is to produce **MJML markup**; the `format` segment (`html` above) is mostly a no-op for naming. The plugin reads the rendered file, compiles MJML → HTML, and writes the result to `<name>.html`.
35
+
36
+ ### Why not just `welcome.mjml.hbs`?
37
+
38
+ Without the `-mjml` postprocessor suffix, Mikser treats the rendered output as the final file (`welcome.mjml`) — no compilation happens. The suffix is what hooks the postprocessor into the pipeline.
39
+
40
+ ## Example layout
41
+
42
+ ```hbs
43
+ <mjml>
44
+ <mj-body>
45
+ <mj-section>
46
+ <mj-column>
47
+ <mj-text font-size="20px">{{document.meta.title}}</mj-text>
48
+ <mj-text>{{document.meta.body}}</mj-text>
49
+ </mj-column>
50
+ </mj-section>
51
+ </mj-body>
52
+ </mjml>
53
+ ```
54
+
55
+ MJML validation errors (if any) are surfaced via the Mikser logger as warnings.
56
+
57
+ ## License
58
+
59
+ MIT
package/index.js ADDED
@@ -0,0 +1,33 @@
1
+ import mjml2html from 'mjml'
2
+ import { readFile } from 'node:fs/promises'
3
+ import path from 'node:path'
4
+
5
+ export async function postprocess({ entity, options, config, logger }) {
6
+ const sourcePath = path.join(options.outputFolder, entity.origin)
7
+ const source = await readFile(sourcePath, 'utf8')
8
+
9
+ const { html, errors } = await mjml2html(source, {
10
+ validationLevel: 'soft',
11
+ ...config?.options,
12
+ })
13
+
14
+ if (errors?.length) {
15
+ for (const err of errors) {
16
+ logger.warn('MJML %s:%d %s', entity.name || entity.id, err.line || 0, err.message || err.formattedMessage)
17
+ }
18
+ }
19
+
20
+ // The default postprocessor convention names the output extension after the
21
+ // postprocessor key (`.mjml` here). MJML actually produces HTML — rewrite
22
+ // the destination so the writer emits `*.html`.
23
+ if (entity.destination?.endsWith('.mjml')) {
24
+ const desired = entity.destination.slice(0, -'.mjml'.length) + '.html'
25
+ // Avoid the origin/destination collision (e.g. layout `name.html-mjml.hbs`
26
+ // gives origin=`name.html`, which is also the desired output path).
27
+ // Clearing origin prevents onComplete from unlinking our final file.
28
+ if (desired === entity.origin) entity.origin = undefined
29
+ entity.destination = desired
30
+ }
31
+
32
+ return html
33
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "mikser-io-post-mjml",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {},
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/almero-digital-marketing/mikser-io-post-mjml.git"
11
+ },
12
+ "author": "",
13
+ "license": "MIT",
14
+ "bugs": {
15
+ "url": "https://github.com/almero-digital-marketing/mikser-io-post-mjml/issues"
16
+ },
17
+ "homepage": "https://github.com/almero-digital-marketing/mikser-io-post-mjml#readme",
18
+ "peerDependencies": {
19
+ "mikser-io": "^6.0.0"
20
+ },
21
+ "dependencies": {
22
+ "mjml": "^5.2.1"
23
+ }
24
+ }