@maizzle/framework 5.0.0-beta.10 → 5.0.0-beta.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "5.0.0-beta.10",
3
+ "version": "5.0.0-beta.12",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -4,6 +4,7 @@ import { cwd } from 'node:process'
4
4
  import { defu as merge } from 'defu'
5
5
  import expressions from 'posthtml-expressions'
6
6
  import { parseFrontMatter } from '../utils/node.js'
7
+ import defaultConfig from '../posthtml/defaultConfig.js'
7
8
  import { process as compilePostHTML } from '../posthtml/index.js'
8
9
  import { run as useTransformers, transformers } from '../transformers/index.js'
9
10
 
@@ -40,7 +41,7 @@ export async function render(html = '', config = {}) {
40
41
  })
41
42
  ]
42
43
  )
43
- .process(matter)
44
+ .process(matter, defaultConfig)
44
45
  .then(({ html }) => parseFrontMatter(`---${html}\n---`))
45
46
 
46
47
  const templateConfig = merge(matterData, config)
@@ -57,13 +58,16 @@ export async function render(html = '', config = {}) {
57
58
  *
58
59
  * @param {Object} options
59
60
  * @param {string} options.html - The HTML to be transformed
61
+ * @param {Object} options.matter - The front matter data
60
62
  * @param {Object} options.config - The current template config
61
- * @param {function} options.render - The render function
63
+ * @param {function} options.posthtml - The PostHTML compiler
64
+ * @param {Object} options.transform - The transformers object
62
65
  * @returns {string} - The transformed HTML, or the original one if nothing was returned
63
66
  */
64
67
  if (typeof templateConfig.beforeRender === 'function') {
65
68
  content = await templateConfig.beforeRender(({
66
69
  html: content,
70
+ matter: matterData,
67
71
  config: templateConfig,
68
72
  posthtml: compilePostHTML,
69
73
  transform: transformers,
@@ -78,13 +82,16 @@ export async function render(html = '', config = {}) {
78
82
  *
79
83
  * @param {Object} options
80
84
  * @param {string} options.html - The HTML to be transformed
85
+ * @param {Object} options.matter - The front matter data
81
86
  * @param {Object} options.config - The current template config
82
- * @param {function} options.render - The render function
87
+ * @param {function} options.posthtml - The PostHTML compiler
88
+ * @param {Object} options.transform - The transformers object
83
89
  * @returns {string} - The transformed HTML, or the original one if nothing was returned
84
90
  */
85
91
  if (typeof templateConfig.afterRender === 'function') {
86
92
  compiled.html = await templateConfig.afterRender(({
87
93
  html: compiled.html,
94
+ matter: matterData,
88
95
  config: templateConfig,
89
96
  posthtml: compilePostHTML,
90
97
  transform: transformers,
@@ -111,13 +118,16 @@ export async function render(html = '', config = {}) {
111
118
  *
112
119
  * @param {Object} options
113
120
  * @param {string} options.html - The HTML to be transformed
121
+ * @param {Object} options.matter - The front matter data
114
122
  * @param {Object} options.config - The current template config
115
- * @param {function} options.render - The render function
123
+ * @param {function} options.posthtml - The PostHTML compiler
124
+ * @param {Object} options.transform - The transformers object
116
125
  * @returns {string} - The transformed HTML, or the original one if nothing was returned
117
126
  */
118
127
  if (typeof templateConfig.afterTransformers === 'function') {
119
128
  compiled.html = await templateConfig.afterTransformers(({
120
129
  html: compiled.html,
130
+ matter: matterData,
121
131
  config: templateConfig,
122
132
  posthtml: compilePostHTML,
123
133
  transform: transformers,
@@ -57,11 +57,15 @@ export async function process(html = '', config = {}) {
57
57
  expandLinkTag,
58
58
  postcssPlugin,
59
59
  components(
60
- merge({
61
- expressions: {
62
- locals,
63
- }
64
- }, defaultComponentsConfig)
60
+ merge(
61
+ {
62
+ expressions: {
63
+ locals,
64
+ }
65
+ },
66
+ componentsUserOptions,
67
+ defaultComponentsConfig
68
+ )
65
69
  ),
66
70
  expandLinkTag,
67
71
  postcssPlugin,
@@ -50,6 +50,7 @@ export default async (config = {}) => {
50
50
  */
51
51
  const shouldScroll = get(config, 'server.scrollSync', false)
52
52
  const useHmr = get(config, 'server.hmr', true)
53
+ spinner.spinner = get(config, 'server.spinner', 'circleHalves')
53
54
 
54
55
  // Add static assets root prefix so user doesn't have to
55
56
  if (!config.baseURL) {
package/src/utils/node.js CHANGED
@@ -1,13 +1,7 @@
1
- import path from 'pathe'
2
1
  import os from 'node:os'
3
2
  import gm from 'gray-matter'
4
3
  import pico from 'picocolors'
5
4
  import { humanFileSize } from './string.js'
6
- import {
7
- copyFile,
8
- mkdir,
9
- readdir
10
- } from 'node:fs/promises'
11
5
 
12
6
  // Return a local IP address
13
7
  export function getLocalIP() {
package/types/config.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type Events from './events';
1
2
  import type BuildConfig from './build';
2
3
  import type MinifyConfig from './minify';
3
4
  import type PostHTMLConfig from './posthtml';
@@ -5,25 +6,17 @@ import type MarkdownConfig from './markdown';
5
6
  import type { ProcessOptions } from 'postcss';
6
7
  import type PurgeCSSConfig from './css/purge';
7
8
  import type CSSInlineConfig from './css/inline';
9
+ import type { SpinnerName } from 'cli-spinners';
8
10
  import type ComponentsConfig from './components';
9
11
  import type WidowWordsConfig from './widowWords';
10
12
  import type { CoreBeautifyOptions } from 'js-beautify';
11
13
  import type { BaseURLConfig } from 'posthtml-base-url';
12
14
  import type URLParametersConfig from './urlParameters';
13
- import type {
14
- beforeCreateType,
15
- beforeRenderType,
16
- afterRenderType,
17
- afterTransformersType,
18
- afterBuildType
19
- } from './events';
20
15
  import type PlaintextConfig from './plaintext';
21
16
 
22
17
  import type { Config as TailwindConfig } from 'tailwindcss';
23
18
 
24
19
  export default interface Config {
25
- [key: string]: any; // eslint-disable-line
26
-
27
20
  /**
28
21
  * Add or remove attributes from elements.
29
22
  */
@@ -404,6 +397,22 @@ export default interface Config {
404
397
  * @default false
405
398
  */
406
399
  reportFileSize?: boolean;
400
+
401
+ /**
402
+ * Type of spinner to show in the console.
403
+ *
404
+ * @default 'circleHalves'
405
+ *
406
+ * @example
407
+ * ```
408
+ * export default {
409
+ * server: {
410
+ * spinner: 'bounce'
411
+ * }
412
+ * }
413
+ * ```
414
+ */
415
+ spinner?: SpinnerName;
407
416
  }
408
417
 
409
418
  /**
@@ -471,83 +480,87 @@ export default interface Config {
471
480
  * @example
472
481
  * ```
473
482
  * export default {
474
- * beforeCreate: async (config) => {
483
+ * beforeCreate: async ({config}) => {
475
484
  * // do something with `config`
476
485
  * }
477
486
  * }
478
487
  * ```
479
488
  */
480
- beforeCreate: beforeCreateType;
489
+ beforeCreate: Events['beforeCreate'];
481
490
 
482
491
  /**
483
492
  * Runs after the Template's config has been computed, but just before it is compiled.
484
- * It exposes the Template's HTML, its config, and the Maizzle `render` function.
485
- * Must return the `html` string.
493
+ *
494
+ * Must return the `html` string, otherwise the original will be used.
486
495
  *
487
496
  * @default undefined
488
497
  *
489
498
  * @example
490
499
  * ```
491
500
  * export default {
492
- * beforeRender: async ({html, config, render}) => {
501
+ * beforeRender: async ({html, matter, config, posthtml, transform}) => {
493
502
  * // do something...
494
503
  * return html;
495
504
  * }
496
505
  * }
497
506
  * ```
498
507
  */
499
- beforeRender: beforeRenderType;
508
+ beforeRender: Events['beforeRender'];
500
509
 
501
510
  /**
502
511
  * Runs after the Template has been compiled, but before any Transformers have been applied.
503
- * Exposes the rendered `html` string and the `config`. Must return the `html` string.
512
+ *
513
+ * Must return the `html` string, otherwise the original will be used.
504
514
  *
505
515
  * @default undefined
506
516
  *
507
517
  * @example
508
518
  * ```
509
519
  * export default {
510
- * afterRender: async ({html, config}) => {
520
+ * afterRender: async ({html, matter, config, posthtml, transform}) => {
511
521
  * // do something...
512
522
  * return html;
513
523
  * }
514
524
  * }
515
525
  * ```
516
526
  */
517
- afterRender: afterRenderType;
527
+ afterRender: Events['afterRender'];
518
528
 
519
529
  /**
520
530
  * Runs after all Transformers have been applied, just before the final HTML is returned.
521
- * Exposes the rendered `html` string and the `config`. Must return the `html` string.
531
+ *
532
+ * Must return the `html` string, otherwise the original will be used.
522
533
  *
523
534
  * @default undefined
524
535
  *
525
536
  * @example
526
537
  * ```
527
538
  * export default {
528
- * afterTransformers: async ({html, config, render}) => {
539
+ * afterTransformers: async ({html, matter, config, posthtml, transform}) => {
529
540
  * // do something...
530
541
  * return html;
531
542
  * }
532
543
  * }
533
544
  * ```
534
545
  */
535
- afterTransformers: afterTransformersType;
546
+ afterTransformers: Events['afterTransformers'];
536
547
 
537
548
  /**
538
549
  * Runs after all Templates have been compiled and output to disk.
539
- * The files parameter will contain the paths to all the files inside the `build.templates.destination.path` directory.
550
+ * `files` will contain the paths to all the files inside the `build.output.path` directory.
540
551
  *
541
552
  * @default undefined
542
553
  *
543
554
  * @example
544
555
  * ```
545
556
  * export default {
546
- * afterBuild: async ({files, config, render}) => {
557
+ * afterBuild: async ({files, config, transform}) => {
547
558
  * // do something...
548
559
  * }
549
560
  * }
550
561
  * ```
551
562
  */
552
- afterBuild: afterBuildType;
563
+ afterBuild: Events['afterBuild'];
564
+
565
+ [key: string]: any;
553
566
  }
package/types/events.d.ts CHANGED
@@ -1,5 +1,346 @@
1
- export type beforeCreateType = (config: object) => Promise<void>;
2
- export type beforeRenderType = (html: string, config: object, render: (html: string, config: object) => Promise<string>) => Promise<string>;
3
- export type afterRenderType = ({ html, config }: { html: string, config: object }) => Promise<string>;
4
- export type afterTransformersType = ({ html, config, render }: { html: string, config: object, render: (html: string, config: object) => Promise<string> }) => Promise<string>;
5
- export type afterBuildType = ({ files, config, render }: { files: string[], config: object, render: (html: string, config: object) => Promise<string> }) => Promise<void>;
1
+ import type Config from "./config";
2
+ import type {
3
+ safeClassNames,
4
+ markdown,
5
+ preventWidows,
6
+ attributeToStyle,
7
+ inlineCSS,
8
+ shorthandCSS,
9
+ removeUnusedCSS,
10
+ purgeCSS,
11
+ removeAttributes,
12
+ addAttributes,
13
+ prettify,
14
+ applyBaseURL,
15
+ addUrlParams,
16
+ sixHEX,
17
+ minify,
18
+ replaceStrings,
19
+ plaintext,
20
+ } from "./index";
21
+
22
+ type PostHTMLType = (html: string, config: Config) => { html: string; config: Config };
23
+
24
+ type TransformType = {
25
+ /**
26
+ * Normalize escaped character class names like `\:` or `\/` by replacing them with email-safe alternatives.
27
+ *
28
+ * @param {string} html The HTML string to normalize.
29
+ * @param {Record<string, string>} replacements A dictionary of replacements to apply.
30
+ * @returns {string} The normalized HTML string.
31
+ * @see https://maizzle.com/docs/transformers/safe-class-names
32
+ */
33
+ safeClassNames: typeof safeClassNames;
34
+ /**
35
+ * Compile Markdown to HTML.
36
+ *
37
+ * @param {string} input The Markdown string to compile.
38
+ * @param {MarkdownConfig} [options] A configuration object for the Markdown compiler.
39
+ * @returns {string} The compiled HTML string.
40
+ * @see https://maizzle.com/docs/transformers/markdown
41
+ */
42
+ markdown: typeof markdown;
43
+ /**
44
+ * Prevent widow words inside a tag by adding a `&nbsp;` between its last two words.
45
+ *
46
+ * @param {string} html The HTML string to process.
47
+ * @param {WidowWordsConfig} [options] A configuration object for the widow words transformer.
48
+ * @returns {string} The processed HTML string.
49
+ * @see https://maizzle.com/docs/transformers/widows
50
+ */
51
+ preventWidows: typeof preventWidows;
52
+ /**
53
+ * Duplicate HTML attributes to inline CSS.
54
+ *
55
+ * @param {string} html The HTML string to process.
56
+ * @param {AttributeToStyleSupportedAttributes[]} attributes An array of attributes to inline.
57
+ * @param {PostHTMLConfig} [posthtmlConfig] A configuration object for PostHTML.
58
+ * @returns {string} The processed HTML string.
59
+ * @see https://maizzle.com/docs/transformers/attribute-to-style
60
+ */
61
+ attributeToStyle: typeof attributeToStyle;
62
+ /**
63
+ * Inline CSS styles in an HTML string.
64
+ *
65
+ * @param {string} html The HTML string to process.
66
+ * @param {CSSInlineConfig} [options] A configuration object for the CSS inliner.
67
+ * @returns {string} The processed HTML string.
68
+ * @see https://maizzle.com/docs/transformers/inline-css
69
+ */
70
+ inlineCSS: typeof inlineCSS;
71
+ /**
72
+ * Rewrite longhand CSS inside style attributes with shorthand syntax.
73
+ * Only works with margin, padding and border, and only when all sides are specified.
74
+ *
75
+ * @param {string} html The HTML string to process.
76
+ * @returns {string} The processed HTML string.
77
+ * @see https://maizzle.com/docs/transformers/shorthand-css
78
+ */
79
+ shorthandCSS: typeof shorthandCSS;
80
+ /**
81
+ * Remove unused CSS from `<style>` tags and HTML elements.
82
+ *
83
+ * @param {string} html The HTML string to process.
84
+ * @param {PurgeCSSConfig} [options] A configuration object for `email-comb`.
85
+ * @returns {string} The processed HTML string.
86
+ * @see https://maizzle.com/docs/transformers/remove-unused-css
87
+ */
88
+ removeUnusedCSS: typeof removeUnusedCSS;
89
+ /**
90
+ * Remove HTML attributes from an HTML string.
91
+ *
92
+ * @param {string} html The HTML string to process.
93
+ * @param {string[] | Array<{ name: string; value: string | RegExp }>} [options] An array of attribute names to remove, or an array of objects with `name` and `value` properties.
94
+ * @returns {string} The processed HTML string.
95
+ * @see https://maizzle.com/docs/transformers/remove-attributes
96
+ */
97
+ removeAttributes: typeof removeAttributes;
98
+ /**
99
+ * Add attributes to elements in an HTML string.
100
+ *
101
+ * @param {string} html The HTML string to process.
102
+ * @param {Record<string, unknown>} [options] A dictionary of attributes to add.
103
+ * @returns {string} The processed HTML string.
104
+ * @see https://maizzle.com/docs/transformers/add-attributes
105
+ */
106
+ addAttributes: typeof addAttributes;
107
+ /**
108
+ * Pretty-print an HTML string.
109
+ *
110
+ * @param {string} html The HTML string to prettify.
111
+ * @param {HTMLBeautifyOptions} [options] A configuration object for `js-beautify`.
112
+ * @returns {string} The prettified HTML string.
113
+ * @see https://maizzle.com/docs/transformers/prettify
114
+ */
115
+ prettify: typeof prettify;
116
+ /**
117
+ * Prepend a string to sources and hrefs in an HTML string.
118
+ *
119
+ * @param {string} html The HTML string to process.
120
+ * @param {string | BaseURLConfig} [options] A string to prepend to sources and hrefs, or a configuration object for `posthtml-base-url`.
121
+ * @returns {string} The processed HTML string.
122
+ * @see https://maizzle.com/docs/transformers/base-url
123
+ */
124
+ applyBaseURL: typeof applyBaseURL;
125
+ /**
126
+ * Append parameters to URLs in an HTML string.
127
+ *
128
+ * @param {string} html The HTML string to process.
129
+ * @param {URLParametersConfig} [options] A configuration object for `posthtml-url-parameters`.
130
+ * @returns {string} The processed HTML string.
131
+ * @see https://maizzle.com/docs/transformers/url-parameters
132
+ */
133
+ addUrlParams: typeof addUrlParams;
134
+ /**
135
+ * Ensure that all HEX colors inside `bgcolor` and `color` attributes are defined with six digits.
136
+ *
137
+ * @param {string} html The HTML string to process.
138
+ * @returns {string} The processed HTML string.
139
+ * @see https://maizzle.com/docs/transformers/six-hex
140
+ */
141
+ sixHEX: typeof sixHEX;
142
+ /**
143
+ * Minify an HTML string, with email client considerations.
144
+ *
145
+ * @param {string} html The HTML string to minify.
146
+ * @param {MinifyConfig} [options] A configuration object for `html-minifier`.
147
+ * @returns {string} The minified HTML string.
148
+ * @see https://maizzle.com/docs/transformers/minify
149
+ */
150
+ minify: typeof minify;
151
+ /**
152
+ * Batch-replace strings in an HTML string.
153
+ *
154
+ * @param {string} html The HTML string to process.
155
+ * @param {Record<string, string>} [replacements] A dictionary of strings to replace.
156
+ * @returns {string} The processed HTML string.
157
+ * @see https://maizzle.com/docs/transformers/replace-strings
158
+ */
159
+ replaceStrings: typeof replaceStrings;
160
+ /**
161
+ * Generate a plaintext version of an HTML string.
162
+ * @param {string} html - The HTML string to convert to plaintext.
163
+ * @param {PlaintextConfig} [options] - A configuration object for the plaintext generator.
164
+ * @returns {Promise<string>} The plaintext version of the HTML string.
165
+ * @see https://maizzle.com/docs/plaintext
166
+ */
167
+ plaintext: typeof plaintext;
168
+ };
169
+
170
+ export default interface Events {
171
+ /**
172
+ * Runs after the Environment config has been computed, but before Templates are processed.
173
+ * Exposes the `config` object so you can further customize it.
174
+ *
175
+ * @default undefined
176
+ *
177
+ * @example
178
+ * ```
179
+ * export default {
180
+ * beforeCreate: async ({config}) => {
181
+ * // do something with `config`
182
+ * }
183
+ * }
184
+ * ```
185
+ */
186
+ beforeCreate?: (params: { config: Config }) => void | Promise<void>;
187
+
188
+ /**
189
+ * Runs after the Template's config has been computed, but just before it is compiled.
190
+ *
191
+ * Must return the `html` string, otherwise the original will be used.
192
+ *
193
+ * @default undefined
194
+ *
195
+ * @example
196
+ * ```
197
+ * export default {
198
+ * beforeRender: async ({html, matter, config, posthtml, transform}) => {
199
+ * // do something...
200
+ * return html;
201
+ * }
202
+ * }
203
+ * ```
204
+ */
205
+ beforeRender?: (params: {
206
+ /**
207
+ * The Template's HTML string.
208
+ */
209
+ html: string;
210
+ /**
211
+ * The Template's Front Matter.
212
+ */
213
+ matter: { [key: string]: string };
214
+ /**
215
+ * The Template's computed config.
216
+ */
217
+ config: Config;
218
+ /**
219
+ * A function to process an HTML string with PostHTML.
220
+ *
221
+ * @param {string} html The HTML string to process.
222
+ * @param {Config} config The Maizzle config object.
223
+ */
224
+ posthtml: PostHTMLType;
225
+ /**
226
+ * A collection of Maizzle Transformers.
227
+ */
228
+ transform: TransformType;
229
+ }) => string | Promise<string>;
230
+
231
+ /**
232
+ * Runs after the Template has been compiled, but before any Transformers have been applied.
233
+ *
234
+ * Must return the `html` string, otherwise the original will be used.
235
+ *
236
+ * @default undefined
237
+ *
238
+ * @example
239
+ * ```
240
+ * export default {
241
+ * afterRender: async async ({html, matter, config, posthtml, transform}) => {
242
+ * // do something...
243
+ * return html;
244
+ * }
245
+ * }
246
+ * ```
247
+ */
248
+ afterRender?: (params: {
249
+ /**
250
+ * The Template's HTML string.
251
+ */
252
+ html: string;
253
+ /**
254
+ * The Template's Front Matter.
255
+ */
256
+ matter: { [key: string]: string };
257
+ /**
258
+ * The Template's computed config.
259
+ */
260
+ config: Config;
261
+ /**
262
+ * A function to process an HTML string with PostHTML.
263
+ *
264
+ * @param {string} html The HTML string to process.
265
+ * @param {Config} config The Maizzle config object.
266
+ */
267
+ posthtml: PostHTMLType;
268
+ /**
269
+ * A collection of Maizzle Transformers.
270
+ */
271
+ transform: TransformType;
272
+ }) => string | Promise<string>;
273
+
274
+ /**
275
+ * Runs after all Transformers have been applied, just before the final HTML is returned.
276
+ *
277
+ * Must return the `html` string, otherwise the original will be used.
278
+ *
279
+ * @default undefined
280
+ *
281
+ * @example
282
+ * ```
283
+ * export default {
284
+ * afterTransformers: async ({html, matter, config, posthtml, transform}) => {
285
+ * // do something...
286
+ * return html;
287
+ * }
288
+ * }
289
+ * ```
290
+ */
291
+ afterTransformers?: (params: {
292
+ /**
293
+ * The Template's HTML string.
294
+ */
295
+ html: string;
296
+ /**
297
+ * The Template's Front Matter.
298
+ */
299
+ matter: { [key: string]: string };
300
+ /**
301
+ * The Template's computed config.
302
+ */
303
+ config: Config;
304
+ /**
305
+ * A function to process an HTML string with PostHTML.
306
+ *
307
+ * @param {string} html The HTML string to process.
308
+ * @param {Config} config The Maizzle config object.
309
+ */
310
+ posthtml: PostHTMLType;
311
+ /**
312
+ * A collection of Maizzle Transformers.
313
+ */
314
+ transform: TransformType;
315
+ }) => string | Promise<string>;
316
+
317
+ /**
318
+ * Runs after all Templates have been compiled and output to disk.
319
+ * `files` will contain the paths to all the files inside the `build.output.path` directory.
320
+ *
321
+ * @default undefined
322
+ *
323
+ * @example
324
+ * ```
325
+ * export default {
326
+ * afterBuild: async ({files, config, transform}) => {
327
+ * // do something...
328
+ * }
329
+ * }
330
+ * ```
331
+ */
332
+ afterBuild?: (params: {
333
+ /**
334
+ * An array of paths to all the files inside the `build.output.path` directory.
335
+ */
336
+ files: string[];
337
+ /**
338
+ * The Maizzle config object.
339
+ */
340
+ config: Config;
341
+ /**
342
+ * A collection of Maizzle Transformers.
343
+ */
344
+ transform: TransformType;
345
+ }) => string | Promise<string>;
346
+ }