@maizzle/framework 4.4.0-beta.7 → 4.4.0-beta.8

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.4.0-beta.7",
3
+ "version": "4.4.0-beta.8",
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",
@@ -28,7 +28,7 @@ module.exports = async (env, spinner, config) => {
28
28
 
29
29
  const css = (typeof get(config, 'build.tailwind.compiled') === 'string')
30
30
  ? config.build.tailwind.compiled
31
- : await Tailwind.compile('', '', {}, config)
31
+ : await Tailwind.compile({config})
32
32
 
33
33
  // Parse each template config object
34
34
  await asyncForEach(templatesConfig, async templateConfig => {
@@ -209,12 +209,16 @@ module.exports = async (env, spinner, config) => {
209
209
  if (Array.isArray(assets.source)) {
210
210
  await asyncForEach(assets.source, async source => {
211
211
  if (fs.existsSync(source)) {
212
- await fs.copy(source, path.join(templateConfig.destination.path, assets.destination)).catch(error => spinner.warn(error.message))
212
+ await fs
213
+ .copy(source, path.join(templateConfig.destination.path, assets.destination))
214
+ .catch(error => spinner.warn(error.message))
213
215
  }
214
216
  })
215
217
  } else {
216
218
  if (fs.existsSync(assets.source)) {
217
- await fs.copy(assets.source, path.join(templateConfig.destination.path, assets.destination)).catch(error => spinner.warn(error.message))
219
+ await fs
220
+ .copy(assets.source, path.join(templateConfig.destination.path, assets.destination))
221
+ .catch(error => spinner.warn(error.message))
218
222
  }
219
223
  }
220
224
 
@@ -22,9 +22,6 @@ module.exports = async (html, options) => {
22
22
 
23
23
  let config = merge(fileConfig, get(options, 'maizzle', {}))
24
24
 
25
- const tailwindConfig = get(options, 'tailwind.config', {})
26
- const cssString = get(options, 'tailwind.css', '')
27
-
28
25
  const {frontmatter} = fm(html)
29
26
 
30
27
  html = `---\n${frontmatter}\n---\n\n${fm(html).body}`
@@ -34,7 +31,17 @@ module.exports = async (html, options) => {
34
31
  if (typeof get(options, 'tailwind.compiled') === 'string') {
35
32
  config.css = options.tailwind.compiled
36
33
  } else {
37
- config.css = await Tailwind.compile(cssString, html, tailwindConfig, config)
34
+ config.css = await Tailwind.compile({
35
+ css: get(options, 'tailwind.css', ''),
36
+ html,
37
+ config: merge(config, {
38
+ build: {
39
+ tailwind: {
40
+ config: get(options, 'tailwind.config', {})
41
+ }
42
+ }
43
+ })
44
+ })
38
45
  }
39
46
 
40
47
  if (options && typeof options.beforeRender === 'function') {
@@ -9,14 +9,14 @@ const mergeLonghand = require('postcss-merge-longhand')
9
9
  const {get, isObject, isEmpty, merge} = require('lodash')
10
10
 
11
11
  module.exports = {
12
- compile: async (css = '', html = '', tailwindConfig = {}, maizzleConfig = {}) => {
13
- tailwindConfig = (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) ? tailwindConfig : get(maizzleConfig, 'build.tailwind.config', 'tailwind.config.js')
14
-
12
+ compile: async ({css = '', html = '', config = {}}) => {
15
13
  // Compute the Tailwind config to use
16
- const userConfig = () => {
14
+ const userConfig = config => {
15
+ const tailwindUserConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
16
+
17
17
  // If a custom config object was passed, use that
18
- if (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) {
19
- return tailwindConfig
18
+ if (isObject(tailwindUserConfig) && !isEmpty(tailwindUserConfig)) {
19
+ return tailwindUserConfig
20
20
  }
21
21
 
22
22
  /**
@@ -24,17 +24,17 @@ module.exports = {
24
24
  * This will use the default Tailwind config (with rem units etc)
25
25
  */
26
26
  try {
27
- return requireUncached(path.resolve(process.cwd(), tailwindConfig))
27
+ return requireUncached(path.resolve(process.cwd(), tailwindUserConfig))
28
28
  } catch {
29
29
  return {}
30
30
  }
31
31
  }
32
32
 
33
33
  // Merge user's Tailwind config on top of a 'base' config
34
- const layoutsRoot = get(maizzleConfig, 'build.layouts.root')
35
- const componentsRoot = get(maizzleConfig, 'build.components.root')
34
+ const layoutsRoot = get(config, 'build.layouts.root')
35
+ const componentsRoot = get(config, 'build.components.root')
36
36
 
37
- const config = merge({
37
+ const tailwindConfig = merge({
38
38
  important: true,
39
39
  content: {
40
40
  files: [
@@ -47,20 +47,20 @@ module.exports = {
47
47
  {raw: html, extension: 'html'}
48
48
  ]
49
49
  }
50
- }, userConfig())
50
+ }, userConfig(config))
51
51
 
52
52
  // Add back the `{raw: html}` option if user provided own config
53
- if (Array.isArray(config.content)) {
54
- config.content = {
53
+ if (Array.isArray(tailwindConfig.content)) {
54
+ tailwindConfig.content = {
55
55
  files: [
56
- ...config.content,
56
+ ...tailwindConfig.content,
57
57
  {raw: html, extension: 'html'}
58
58
  ]
59
59
  }
60
60
  }
61
61
 
62
62
  // Include all `build.templates.source` paths when scanning for selectors to preserve
63
- const buildTemplates = get(maizzleConfig, 'build.templates')
63
+ const buildTemplates = get(config, 'build.templates')
64
64
 
65
65
  if (buildTemplates) {
66
66
  const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
@@ -68,12 +68,12 @@ module.exports = {
68
68
  const source = get(template, 'source')
69
69
 
70
70
  if (typeof source === 'function') {
71
- const sources = source(maizzleConfig)
71
+ const sources = source(config)
72
72
 
73
73
  if (Array.isArray(sources)) {
74
- sources.map(s => config.content.files.push(s))
74
+ sources.map(s => tailwindConfig.content.files.push(s))
75
75
  } else if (typeof sources === 'string') {
76
- config.content.files.push(sources)
76
+ tailwindConfig.content.files.push(sources)
77
77
  }
78
78
 
79
79
  // Must return a valid `content` entry
@@ -82,7 +82,7 @@ module.exports = {
82
82
 
83
83
  // Support single-file sources i.e. src/templates/index.html
84
84
  if (typeof source === 'string' && Boolean(path.extname(source))) {
85
- config.content.files.push(source)
85
+ tailwindConfig.content.files.push(source)
86
86
 
87
87
  return {raw: '', extension: 'html'}
88
88
  }
@@ -90,23 +90,24 @@ module.exports = {
90
90
  return `${source}/**/*.*`
91
91
  })
92
92
 
93
- config.content.files.push(...templateSources)
93
+ tailwindConfig.content.files.push(...templateSources)
94
94
  }
95
95
 
96
- const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
96
+ const userFilePath = get(config, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
97
97
  const userFileExists = await fs.pathExists(userFilePath)
98
98
 
99
99
  const toProcess = [
100
100
  postcssNested(),
101
- tailwindcss(config),
102
- get(maizzleConfig, 'shorthandCSS', get(maizzleConfig, 'shorthandInlineCSS')) === true ?
101
+ tailwindcss(tailwindConfig),
102
+ get(config, 'shorthandCSS', get(config, 'shorthandInlineCSS')) === true ?
103
103
  mergeLonghand() :
104
104
  () => {},
105
- ...get(maizzleConfig, 'build.postcss.plugins', [])
105
+ ...get(config, 'build.postcss.plugins', [])
106
106
  ]
107
107
 
108
108
  if (userFileExists) {
109
109
  css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
110
+
110
111
  toProcess.unshift(
111
112
  postcssImport({path: path.dirname(userFilePath)})
112
113
  )
@@ -22,10 +22,19 @@ module.exports = async (html, config = {}, direct = false) => {
22
22
  * Compile CSS in <style {post|tailwind}css> tags
23
23
  */
24
24
  const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
25
- const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
26
25
 
27
26
  filters.postcss = css => PostCSS.process(css, maizzleConfig)
28
- filters.tailwindcss = css => Tailwind.compile(css, html, tailwindConfig, maizzleConfig)
27
+ filters.tailwindcss = css => Tailwind.compile({
28
+ css,
29
+ html,
30
+ config: merge({
31
+ build: {
32
+ tailwind: {
33
+ config: get(config, 'build.tailwind.config', {})
34
+ }
35
+ }
36
+ }, maizzleConfig)
37
+ })
29
38
 
30
39
  const posthtmlPlugins = [
31
40
  styleDataEmbed(),