@maizzle/framework 4.5.0 → 4.6.1

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,9 +1,10 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "4.5.0",
3
+ "version": "4.6.1",
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",
7
+ "types": "src/index.d.ts",
7
8
  "bin": {
8
9
  "maizzle": "bin/maizzle"
9
10
  },
@@ -77,6 +78,8 @@
77
78
  "tailwindcss": "^3.2.7"
78
79
  },
79
80
  "devDependencies": {
81
+ "@types/js-beautify": "^1.14.0",
82
+ "@types/markdown-it": "^13.0.0",
80
83
  "ava": "^5.2.0",
81
84
  "c8": "^8.0.0",
82
85
  "np": "*",
@@ -6,8 +6,8 @@ const Config = require('../generators/config')
6
6
  const buildToFile = require('../commands/build')
7
7
  const renderToString = require('../functions/render')
8
8
 
9
- const {get, merge, isObject} = require('lodash')
10
- const {clearConsole} = require('../utils/helpers')
9
+ const {get, isObject} = require('lodash')
10
+ const {clearConsole, merge} = require('../utils/helpers')
11
11
 
12
12
  /**
13
13
  * Initialize Browsersync on-demand
@@ -149,9 +149,12 @@ const serve = async (env = 'local', config = {}) => {
149
149
 
150
150
  // Watch for changes in config files
151
151
  browsersync()
152
- .watch('config*.js')
152
+ .watch('{maizzle.config*,config*}.{js,cjs}')
153
153
  .on('change', async file => {
154
- const parsedEnv = path.parse(file).name.split('.')[1] || 'local'
154
+ const fileName = path.parse(file).base
155
+ const match = fileName.match(/\.?config\.(.+?)\./)
156
+
157
+ const parsedEnv = match ? match[1] : env || 'local'
155
158
 
156
159
  Config
157
160
  .getMerged(parsedEnv)
@@ -180,7 +183,13 @@ const serve = async (env = 'local', config = {}) => {
180
183
  },
181
184
  tunnel: false,
182
185
  ui: {port: 3001},
183
- logFileChanges: false
186
+ logFileChanges: false,
187
+ watchOptions: {
188
+ awaitWriteFinish: {
189
+ stabilityThreshold: 150,
190
+ pollInterval: 25
191
+ }
192
+ }
184
193
  },
185
194
  get(config, 'build.browsersync', {})
186
195
  ), () => {})
@@ -1,6 +1,16 @@
1
1
  const path = require('path')
2
- const {merge} = require('lodash')
3
- const {requireUncached} = require('../utils/helpers')
2
+ const {merge, requireUncached} = require('../utils/helpers')
3
+
4
+ const baseConfigFileNames = [
5
+ './maizzle.config.js',
6
+ './maizzle.config.cjs',
7
+ './maizzle.config.local.js',
8
+ './maizzle.config.local.cjs',
9
+ './config.js',
10
+ './config.cjs',
11
+ './config.local.js',
12
+ './config.local.cjs'
13
+ ]
4
14
 
5
15
  module.exports = {
6
16
  getMerged: async (env = 'local') => {
@@ -11,17 +21,19 @@ module.exports = {
11
21
  let baseConfig = {env}
12
22
  let envConfig = {env}
13
23
 
14
- const cwd = env === 'maizzle-ci' ? './test/stubs/config' : process.cwd()
24
+ const cwd = ['maizzle-ci', 'test'].includes(env) ? './test/stubs/config' : process.cwd()
15
25
 
16
- for (const module of ['./config', './config.cjs', './config.local', './config.local.cjs']) {
26
+ for (const module of baseConfigFileNames) {
17
27
  try {
18
28
  baseConfig = merge(baseConfig, requireUncached(path.resolve(cwd, module)))
19
29
  } catch {}
20
30
  }
21
31
 
22
- if (typeof env === 'string' && env !== 'local') {
32
+ if (env !== 'local') {
23
33
  let loaded = false
24
- for (const module of [`./config.${env}`, `./config.${env}.cjs`]) {
34
+ const modulesToTry = [`./maizzle.config.${env}.js`, `./maizzle.config.${env}.cjs`, `./config.${env}.js`, `./config.${env}.cjs`]
35
+
36
+ for (const module of modulesToTry) {
25
37
  try {
26
38
  envConfig = merge(envConfig, requireUncached(path.resolve(cwd, module)))
27
39
  loaded = true
@@ -30,7 +42,7 @@ module.exports = {
30
42
  }
31
43
 
32
44
  if (!loaded) {
33
- throw new Error(`could not load config.${env}.js`)
45
+ throw new Error(`Failed to load config file for \`${env}\` environment, do you have one of these files in your project root?\n\n${modulesToTry.join('\n')}`)
34
46
  }
35
47
  }
36
48
 
@@ -1,7 +1,8 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs-extra')
3
3
  const glob = require('glob-promise')
4
- const {get, isEmpty, merge} = require('lodash')
4
+ const {get, isEmpty} = require('lodash')
5
+ const {merge} = require('../../utils/helpers')
5
6
 
6
7
  const Config = require('../config')
7
8
  const Tailwind = require('../tailwindcss')
@@ -1,6 +1,7 @@
1
1
  const fm = require('front-matter')
2
- const {get, merge} = require('lodash')
2
+ const {get} = require('lodash')
3
3
  const posthtml = require('../posthtml')
4
+ const {merge} = require('../../utils/helpers')
4
5
  const Transformers = require('../../transformers')
5
6
  const Tailwind = require('../tailwindcss')
6
7
  const Config = require('../config')
@@ -1,6 +1,7 @@
1
1
  const path = require('path')
2
+ const {get} = require('lodash')
2
3
  const posthtml = require('posthtml')
3
- const {get, merge} = require('lodash')
4
+ const {merge} = require('../utils/helpers')
4
5
  const {stripHtml} = require('string-strip-html')
5
6
  const defaultConfig = require('./posthtml/defaultConfig')
6
7
 
@@ -1,26 +1,28 @@
1
1
  const fm = require('front-matter')
2
2
  const posthtml = require('posthtml')
3
- const {get, merge} = require('lodash')
3
+ const {get, omit} = require('lodash')
4
4
  const fetch = require('posthtml-fetch')
5
5
  const layouts = require('posthtml-extend')
6
+ const {merge} = require('../../utils/helpers')
6
7
  const components = require('posthtml-component')
7
- const defaultConfig = require('./defaultConfig')
8
+ const defaultPosthtmlConfig = require('./defaultConfig')
8
9
  const defaultComponentsConfig = require('./defaultComponentsConfig')
9
10
 
10
11
  module.exports = async (html, config) => {
11
- const layoutsOptions = get(config, 'build.layouts', {})
12
- const componentsOptions = get(config, 'build.components', {})
12
+ const posthtmlOptions = merge(defaultPosthtmlConfig, get(config, 'build.posthtml.options', {}))
13
+ const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
14
+
15
+ const componentsUserOptions = get(config, 'build.components', {})
16
+
13
17
  const expressionsOptions = merge(
14
18
  {
15
19
  loopTags: ['each', 'for'],
16
20
  strictMode: false
17
21
  },
18
- get(config, 'build.posthtml.expressions', {})
22
+ get(config, 'build.posthtml.expressions', {}),
23
+ get(componentsUserOptions, 'expressions', {})
19
24
  )
20
25
 
21
- const posthtmlOptions = merge(defaultConfig, get(config, 'build.posthtml.options', {}))
22
- const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
23
-
24
26
  const locals = merge(
25
27
  get(expressionsOptions, 'locals', {}),
26
28
  get(config, 'locals', {}),
@@ -30,24 +32,29 @@ module.exports = async (html, config) => {
30
32
  const fetchPlugin = fetch(
31
33
  merge(
32
34
  {
33
- expressions: merge({...expressionsOptions, locals})
35
+ expressions: merge(expressionsOptions, {locals})
34
36
  },
35
37
  get(config, 'build.posthtml.fetch', {})
36
38
  )
37
39
  )
38
40
 
39
- const defaultComponentsOptions = merge(
41
+ const componentsOptions = merge(
40
42
  {
41
43
  ...defaultComponentsConfig,
42
44
  folders: [
43
- ...defaultComponentsConfig.folders,
44
- ...get(componentsOptions, 'folders', [])
45
+ ...get(componentsUserOptions, 'folders', []),
46
+ ...defaultComponentsConfig.folders
45
47
  ],
46
- expressions: {...expressionsOptions, locals}
48
+ expressions: merge(expressionsOptions, {locals})
47
49
  },
48
50
  {
49
- root: componentsOptions.root || './'
50
- }
51
+ root: componentsUserOptions.root || './'
52
+ },
53
+ /**
54
+ * We omit `folders`, `root` and `expressions` in order to prevent duplicate
55
+ * array values, as they are already added above
56
+ */
57
+ omit(componentsUserOptions, ['folders', 'root', 'expressions'])
51
58
  )
52
59
 
53
60
  return posthtml([
@@ -56,17 +63,12 @@ module.exports = async (html, config) => {
56
63
  merge(
57
64
  {
58
65
  strict: false,
59
- expressions: merge({...expressionsOptions, locals})
66
+ expressions: merge(expressionsOptions, {locals})
60
67
  },
61
- layoutsOptions
62
- )
63
- ),
64
- components(
65
- merge(
66
- defaultComponentsOptions,
67
- componentsOptions
68
+ get(config, 'build.layouts', {})
68
69
  )
69
70
  ),
71
+ components(componentsOptions),
70
72
  ...posthtmlPlugins
71
73
  ])
72
74
  .process(html, {...posthtmlOptions})
@@ -3,10 +3,10 @@ const fs = require('fs-extra')
3
3
  const postcss = require('postcss')
4
4
  const tailwindcss = require('tailwindcss')
5
5
  const postcssImport = require('postcss-import')
6
+ const {get, isObject, isEmpty} = require('lodash')
6
7
  const postcssNested = require('tailwindcss/nesting')
7
- const {requireUncached} = require('../utils/helpers')
8
+ const {merge, requireUncached} = require('../utils/helpers')
8
9
  const mergeLonghand = require('postcss-merge-longhand')
9
- const {get, isObject, isEmpty, merge} = require('lodash')
10
10
  const defaultComponentsConfig = require('./posthtml/defaultComponentsConfig')
11
11
 
12
12
  const addImportantPlugin = () => {