@maizzle/framework 4.0.0-alpha.1 → 4.0.0-alpha.2

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": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "main": "src/index.js",
@@ -56,9 +56,9 @@
56
56
  "posthtml-extend": "^0.6.0",
57
57
  "posthtml-extra-attributes": "^1.0.0",
58
58
  "posthtml-fetch": "^2.0.0",
59
- "posthtml-markdownit": "^1.2.2",
59
+ "posthtml-markdownit": "^1.3.0",
60
60
  "posthtml-modules": "^0.8.0",
61
- "posthtml-mso": "^1.0.2",
61
+ "posthtml-mso": "^1.0.4",
62
62
  "posthtml-postcss-merge-longhand": "^1.0.2",
63
63
  "posthtml-remove-attributes": "^1.0.0",
64
64
  "posthtml-safe-class-names": "^1.0.4",
@@ -67,8 +67,7 @@
67
67
  "prevent-widows": "^1.0.2",
68
68
  "query-string": "^7.1.0",
69
69
  "string-strip-html": "^8.2.0",
70
- "tailwindcss": "^3.0.0",
71
- "tailwindcss-box-shadow": "^1.0.0"
70
+ "tailwindcss": "^3.0.0"
72
71
  },
73
72
  "devDependencies": {
74
73
  "ava": "^4.0.1",
@@ -46,19 +46,24 @@ module.exports = async (env, spinner, config) => {
46
46
  *
47
47
  * */
48
48
  const templateSource = []
49
+ const templateTypeErrorMessage = 'Invalid template source: expected string or array of strings, got '
49
50
 
50
51
  if (typeof templateConfig.source === 'function') {
51
- const sources = templateConfig.source()
52
+ const sources = templateConfig.source(config)
52
53
  if (Array.isArray(sources)) {
53
54
  templateSource.push(...sources)
54
- } else {
55
+ } else if (typeof sources === 'string') {
55
56
  templateSource.push(sources)
57
+ } else {
58
+ throw new TypeError(templateTypeErrorMessage + typeof sources)
56
59
  }
57
60
  } else {
58
61
  if (Array.isArray(templateConfig.source)) {
59
62
  templateSource.push(...templateConfig.source)
60
- } else {
63
+ } else if (typeof templateConfig.source === 'string') {
61
64
  templateSource.push(templateConfig.source)
65
+ } else {
66
+ throw new TypeError(templateTypeErrorMessage + typeof templateConfig.source)
62
67
  }
63
68
  }
64
69
 
@@ -38,22 +38,7 @@ module.exports = {
38
38
  './src/**/*.*',
39
39
  {raw: html, extension: 'html'}
40
40
  ]
41
- },
42
- corePlugins: {
43
- preflight: false,
44
- animation: false,
45
- backgroundOpacity: false,
46
- borderOpacity: false,
47
- boxShadow: false,
48
- divideOpacity: false,
49
- placeholderOpacity: false,
50
- ringColor: false,
51
- ringWidth: false,
52
- ringOpacity: false,
53
- ringOffsetColor: false,
54
- textOpacity: false
55
- },
56
- plugins: []
41
+ }
57
42
  }, userConfig())
58
43
 
59
44
  // Add back the `{raw: html}` option if user provided own config
@@ -75,23 +60,30 @@ module.exports = {
75
60
  const templateSources = templateObjects.map(template => {
76
61
  const source = get(template, 'source')
77
62
 
63
+ if (typeof source === 'function') {
64
+ const sources = source(maizzleConfig)
65
+
66
+ if (Array.isArray(sources)) {
67
+ sources.map(s => config.content.files.push(s))
68
+ } else if (typeof sources === 'string') {
69
+ config.content.files.push(sources)
70
+ }
71
+
72
+ // Must return a valid `content` entry
73
+ return {raw: '', extension: 'html'}
74
+ }
75
+
78
76
  return `${source}/**/*.*`
79
77
  })
80
78
 
81
79
  config.content.files.push(...templateSources)
82
80
  }
83
81
 
84
- // Merge user's Tailwind plugins with our default ones
85
- config.plugins = [
86
- ...config.plugins,
87
- require('tailwindcss-box-shadow')
88
- ]
89
-
90
82
  const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
91
83
  const userFileExists = await fs.pathExists(userFilePath)
92
84
 
93
85
  if (userFileExists) {
94
- css = await fs.readFile(path.resolve(userFilePath), 'utf8')
86
+ css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
95
87
  }
96
88
 
97
89
  return postcss([
@@ -8,11 +8,11 @@ const rewriteVMLs = (html, url) => {
8
8
  const vImageMatch = html.match(/(<v:image.+)(src=['"]([^'"]+)['"])/)
9
9
  const vFillMatch = html.match(/(<v:fill.+)(src=['"]([^'"]+)['"])/)
10
10
 
11
- if (!isUrl(vImageMatch[3])) {
11
+ if (vImageMatch && !isUrl(vImageMatch[3])) {
12
12
  html = html.replace(vImageMatch[0], `${vImageMatch[1]}src="${url}${vImageMatch[3]}"`)
13
13
  }
14
14
 
15
- if (!isUrl(vFillMatch[3])) {
15
+ if (vFillMatch && !isUrl(vFillMatch[3])) {
16
16
  html = html.replace(vFillMatch[0], `${vFillMatch[1]}src="${url}${vFillMatch[3]}"`)
17
17
  }
18
18
 
@@ -1,57 +1,57 @@
1
- const inline = require('./inlineCss')
2
- const minify = require('./minify')
3
- const markdown = require('./markdown')
4
- const prettify = require('./prettify')
5
- const ensureSixHEX = require('./sixHex')
6
- const applyBaseImageUrl = require('./baseUrl')
7
- const addURLParams = require('./urlParameters')
8
- const transformContents = require('./transform')
9
- const preventWidows = require('./preventWidows')
10
- const replaceStrings = require('./replaceStrings')
11
- const safeClassNames = require('./safeClassNames')
12
- const removeUnusedCSS = require('./removeUnusedCss')
13
- const removeAttributes = require('./removeAttributes')
14
- const attributeToStyle = require('./attributeToStyle')
15
- const removeInlineSizes = require('./removeInlineSizes')
16
- const applyExtraAttributes = require('./extraAttributes')
17
- const removeInlineBgColor = require('./removeInlineBackgroundColor')
18
-
19
- exports.process = async (html, config) => {
20
- html = await safeClassNames(html, config)
21
- html = await transformContents(html, config)
22
- html = await markdown(html, config)
23
- html = await preventWidows(html, config)
24
- html = await attributeToStyle(html, config)
25
- html = await inline(html, config)
26
- html = await removeUnusedCSS(html, config)
27
- html = await removeInlineSizes(html, config)
28
- html = await removeInlineBgColor(html, config)
29
- html = await removeAttributes(html, config)
30
- html = await applyExtraAttributes(html, config)
31
- html = await applyBaseImageUrl(html, config)
32
- html = await addURLParams(html, config)
33
- html = await ensureSixHEX(html, config)
34
- html = await prettify(html, config)
35
- html = await minify(html, config)
36
- html = await replaceStrings(html, config)
37
-
38
- return html
39
- }
40
-
41
- exports.inlineCSS = (html, config) => inline(html, config, true)
42
- exports.minify = (html, config) => minify(html, config, true)
43
- exports.markdown = (html, config) => markdown(html, config, true)
44
- exports.prettify = (html, config) => prettify(html, config, true)
45
- exports.ensureSixHEX = (html, config) => ensureSixHEX(html, config)
46
- exports.addURLParams = (html, config) => addURLParams(html, config, true)
47
- exports.transformContents = (html, config) => transformContents(html, config, true)
48
- exports.preventWidows = (html, config) => preventWidows(html, config, true)
49
- exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
50
- exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
51
- exports.applyBaseImageUrl = (html, config) => applyBaseImageUrl(html, config, true)
52
- exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true)
53
- exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
54
- exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
55
- exports.applyExtraAttributes = (html, config) => applyExtraAttributes(html, config, true)
56
- exports.removeInlineBgColor = (html, config) => removeInlineBgColor(html, config, true)
57
- exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
1
+ const inline = require('./inlineCss')
2
+ const minify = require('./minify')
3
+ const markdown = require('./markdown')
4
+ const prettify = require('./prettify')
5
+ const ensureSixHEX = require('./sixHex')
6
+ const applyBaseImageUrl = require('./baseUrl')
7
+ const addURLParams = require('./urlParameters')
8
+ const transformContents = require('./transform')
9
+ const preventWidows = require('./preventWidows')
10
+ const replaceStrings = require('./replaceStrings')
11
+ const safeClassNames = require('./safeClassNames')
12
+ const removeUnusedCSS = require('./removeUnusedCss')
13
+ const removeAttributes = require('./removeAttributes')
14
+ const attributeToStyle = require('./attributeToStyle')
15
+ const removeInlineSizes = require('./removeInlineSizes')
16
+ const applyExtraAttributes = require('./extraAttributes')
17
+ const removeInlineBgColor = require('./removeInlineBackgroundColor')
18
+
19
+ exports.process = async (html, config) => {
20
+ html = await safeClassNames(html, config)
21
+ html = await transformContents(html, config)
22
+ html = await markdown(html, config)
23
+ html = await preventWidows(html, config)
24
+ html = await attributeToStyle(html, config)
25
+ html = await inline(html, config)
26
+ html = await removeUnusedCSS(html, config)
27
+ html = await removeInlineSizes(html, config)
28
+ html = await removeInlineBgColor(html, config)
29
+ html = await removeAttributes(html, config)
30
+ html = await applyExtraAttributes(html, config)
31
+ html = await applyBaseImageUrl(html, config)
32
+ html = await addURLParams(html, config)
33
+ html = await ensureSixHEX(html, config)
34
+ html = await prettify(html, config)
35
+ html = await minify(html, config)
36
+ html = await replaceStrings(html, config)
37
+
38
+ return html
39
+ }
40
+
41
+ exports.inlineCSS = (html, config) => inline(html, config, true)
42
+ exports.minify = (html, config) => minify(html, config, true)
43
+ exports.markdown = (html, config) => markdown(html, config, true)
44
+ exports.prettify = (html, config) => prettify(html, config, true)
45
+ exports.ensureSixHEX = (html, config) => ensureSixHEX(html, config)
46
+ exports.addURLParams = (html, config) => addURLParams(html, config, true)
47
+ exports.transformContents = (html, config) => transformContents(html, config, true)
48
+ exports.preventWidows = (html, config) => preventWidows(html, config, true)
49
+ exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
50
+ exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
51
+ exports.applyBaseImageUrl = (html, config) => applyBaseImageUrl(html, config, true)
52
+ exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true)
53
+ exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
54
+ exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
55
+ exports.applyExtraAttributes = (html, config) => applyExtraAttributes(html, config, true)
56
+ exports.removeInlineBgColor = (html, config) => removeInlineBgColor(html, config, true)
57
+ exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
@@ -446,8 +446,11 @@ test('works with templates.source defined as function (array paths)', async t =>
446
446
  const {files} = await Maizzle.build('maizzle-ci', {
447
447
  build: {
448
448
  fail: 'silent',
449
+ customSources: ['test/stubs/templates', 'test/stubs/templates'],
449
450
  templates: {
450
- source: () => ['test/stubs/templates', 'test/stubs/templates'],
451
+ source: config => {
452
+ return config.build.customSources
453
+ },
451
454
  destination: {
452
455
  path: t.context.folder
453
456
  }
@@ -458,3 +461,35 @@ test('works with templates.source defined as function (array paths)', async t =>
458
461
  t.true(fs.pathExistsSync(t.context.folder))
459
462
  t.is(files.length, 3)
460
463
  })
464
+
465
+ test('throws if templates path is invalid', async t => {
466
+ await t.throwsAsync(async () => {
467
+ await Maizzle.build('maizzle-ci', {
468
+ build: {
469
+ fail: 'silent',
470
+ templates: {
471
+ source: false,
472
+ destination: {
473
+ path: t.context.folder
474
+ }
475
+ }
476
+ }
477
+ })
478
+ }, {instanceOf: TypeError})
479
+ })
480
+
481
+ test('throws if templates path is invalid (function)', async t => {
482
+ await t.throwsAsync(async () => {
483
+ await Maizzle.build('maizzle-ci', {
484
+ build: {
485
+ fail: 'silent',
486
+ templates: {
487
+ source: () => {},
488
+ destination: {
489
+ path: t.context.folder
490
+ }
491
+ }
492
+ }
493
+ })
494
+ }, {instanceOf: TypeError})
495
+ })