@maizzle/framework 4.4.0-beta.7 → 4.4.0-beta.9
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.
|
|
3
|
+
"version": "4.4.0-beta.9",
|
|
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",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
"query-string": "^7.1.3",
|
|
75
75
|
"string-remove-widows": "^2.1.0",
|
|
76
76
|
"string-strip-html": "^8.2.0",
|
|
77
|
-
"tailwindcss": "^3.2.
|
|
77
|
+
"tailwindcss": "^3.2.6"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"ava": "^5.
|
|
80
|
+
"ava": "^5.2.0",
|
|
81
81
|
"c8": "^7.11.0",
|
|
82
82
|
"np": "*",
|
|
83
83
|
"xo": "0.39.1"
|
package/src/commands/serve.js
CHANGED
|
@@ -81,16 +81,21 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
81
81
|
|
|
82
82
|
spinner.start('Building email...')
|
|
83
83
|
|
|
84
|
-
file = file.replace(/\\/g, '/')
|
|
85
|
-
|
|
86
|
-
const renderOptions = {
|
|
87
|
-
maizzle: config,
|
|
88
|
-
...config.events
|
|
89
|
-
}
|
|
90
|
-
|
|
91
84
|
renderToString(
|
|
92
|
-
await fs.readFile(file, 'utf8'),
|
|
93
|
-
|
|
85
|
+
await fs.readFile(file.replace(/\\/g, '/'), 'utf8'),
|
|
86
|
+
{
|
|
87
|
+
maizzle: merge(
|
|
88
|
+
config,
|
|
89
|
+
{
|
|
90
|
+
build: {
|
|
91
|
+
current: {
|
|
92
|
+
path: path.parse(file)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
...config.events
|
|
98
|
+
}
|
|
94
99
|
)
|
|
95
100
|
.then(async ({html, config}) => {
|
|
96
101
|
let source = ''
|
|
@@ -2,7 +2,6 @@ const path = require('path')
|
|
|
2
2
|
const fs = require('fs-extra')
|
|
3
3
|
const glob = require('glob-promise')
|
|
4
4
|
const {get, isEmpty, merge} = require('lodash')
|
|
5
|
-
const {asyncForEach} = require('../../utils/helpers')
|
|
6
5
|
|
|
7
6
|
const Config = require('../config')
|
|
8
7
|
const Tailwind = require('../tailwindcss')
|
|
@@ -28,10 +27,10 @@ module.exports = async (env, spinner, config) => {
|
|
|
28
27
|
|
|
29
28
|
const css = (typeof get(config, 'build.tailwind.compiled') === 'string')
|
|
30
29
|
? config.build.tailwind.compiled
|
|
31
|
-
: await Tailwind.compile(
|
|
30
|
+
: await Tailwind.compile({config})
|
|
32
31
|
|
|
33
32
|
// Parse each template config object
|
|
34
|
-
await
|
|
33
|
+
for await (const templateConfig of templatesConfig) {
|
|
35
34
|
if (!templateConfig) {
|
|
36
35
|
const configFileName = env === 'local' ? 'config.js' : `config.${env}.js`
|
|
37
36
|
throw new Error(`No template sources defined in \`build.templates\`, check your ${configFileName} file`)
|
|
@@ -79,18 +78,20 @@ module.exports = async (env, spinner, config) => {
|
|
|
79
78
|
: templateConfig.filetypes || get(templateConfig, 'filetypes', 'html')
|
|
80
79
|
|
|
81
80
|
// List of files that won't be copied to the output directory
|
|
82
|
-
const omitted = Array.isArray(templateConfig.omit)
|
|
83
|
-
templateConfig.omit
|
|
84
|
-
[get(templateConfig, 'omit', '')]
|
|
81
|
+
const omitted = Array.isArray(templateConfig.omit)
|
|
82
|
+
? templateConfig.omit
|
|
83
|
+
: [get(templateConfig, 'omit', '')]
|
|
85
84
|
|
|
86
85
|
// Parse each template source
|
|
87
|
-
await
|
|
86
|
+
for await (const source of templateSource) {
|
|
88
87
|
/**
|
|
89
88
|
* Copy single-file sources correctly
|
|
90
89
|
* If `src` is a file, `dest` cannot be a directory
|
|
91
90
|
* https://github.com/jprichardson/node-fs-extra/issues/323
|
|
92
91
|
*/
|
|
93
|
-
const out = fs.lstatSync(source).isFile()
|
|
92
|
+
const out = fs.lstatSync(source).isFile()
|
|
93
|
+
? `${outputDir}/${path.basename(source)}`
|
|
94
|
+
: outputDir
|
|
94
95
|
|
|
95
96
|
await fs
|
|
96
97
|
.copy(source, out, {filter: file => {
|
|
@@ -119,7 +120,7 @@ module.exports = async (env, spinner, config) => {
|
|
|
119
120
|
await config.events.beforeCreate(config)
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
await
|
|
123
|
+
for await (const file of templates) {
|
|
123
124
|
config.build.current = {
|
|
124
125
|
path: path.parse(file)
|
|
125
126
|
}
|
|
@@ -202,19 +203,23 @@ module.exports = async (env, spinner, config) => {
|
|
|
202
203
|
throw error
|
|
203
204
|
}
|
|
204
205
|
}
|
|
205
|
-
}
|
|
206
|
+
}
|
|
206
207
|
|
|
207
208
|
const assets = {source: '', destination: 'assets', ...get(templateConfig, 'assets')}
|
|
208
209
|
|
|
209
210
|
if (Array.isArray(assets.source)) {
|
|
210
|
-
await
|
|
211
|
+
for await (const source of assets.source) {
|
|
211
212
|
if (fs.existsSync(source)) {
|
|
212
|
-
await fs
|
|
213
|
+
await fs
|
|
214
|
+
.copy(source, path.join(templateConfig.destination.path, assets.destination))
|
|
215
|
+
.catch(error => spinner.warn(error.message))
|
|
213
216
|
}
|
|
214
|
-
}
|
|
217
|
+
}
|
|
215
218
|
} else {
|
|
216
219
|
if (fs.existsSync(assets.source)) {
|
|
217
|
-
await fs
|
|
220
|
+
await fs
|
|
221
|
+
.copy(assets.source, path.join(templateConfig.destination.path, assets.destination))
|
|
222
|
+
.catch(error => spinner.warn(error.message))
|
|
218
223
|
}
|
|
219
224
|
}
|
|
220
225
|
|
|
@@ -224,8 +229,8 @@ module.exports = async (env, spinner, config) => {
|
|
|
224
229
|
})
|
|
225
230
|
})
|
|
226
231
|
.catch(error => spinner.warn(error.message))
|
|
227
|
-
}
|
|
228
|
-
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
229
234
|
|
|
230
235
|
if (config.events && typeof config.events.afterBuild === 'function') {
|
|
231
236
|
await config.events.afterBuild(files)
|
|
@@ -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(
|
|
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 = '',
|
|
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(
|
|
19
|
-
return
|
|
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(),
|
|
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(
|
|
35
|
-
const componentsRoot = get(
|
|
34
|
+
const layoutsRoot = get(config, 'build.layouts.root')
|
|
35
|
+
const componentsRoot = get(config, 'build.components.root')
|
|
36
36
|
|
|
37
|
-
const
|
|
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(
|
|
54
|
-
|
|
53
|
+
if (Array.isArray(tailwindConfig.content)) {
|
|
54
|
+
tailwindConfig.content = {
|
|
55
55
|
files: [
|
|
56
|
-
...
|
|
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(
|
|
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(
|
|
71
|
+
const sources = source(config)
|
|
72
72
|
|
|
73
73
|
if (Array.isArray(sources)) {
|
|
74
|
-
sources.map(s =>
|
|
74
|
+
sources.map(s => tailwindConfig.content.files.push(s))
|
|
75
75
|
} else if (typeof sources === 'string') {
|
|
76
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
+
tailwindConfig.content.files.push(...templateSources)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const userFilePath = get(
|
|
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(
|
|
102
|
-
get(
|
|
101
|
+
tailwindcss(tailwindConfig),
|
|
102
|
+
get(config, 'shorthandCSS', get(config, 'shorthandInlineCSS')) === true ?
|
|
103
103
|
mergeLonghand() :
|
|
104
104
|
() => {},
|
|
105
|
-
...get(
|
|
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(
|
|
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(),
|
package/src/utils/helpers.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
asyncForEach: async (array, callback) => {
|
|
3
|
-
for (let index = 0; index < array.length; index++) {
|
|
4
|
-
await callback(array[index], index, array) // eslint-disable-line
|
|
5
|
-
}
|
|
6
|
-
},
|
|
7
2
|
requireUncached: module => {
|
|
8
3
|
try {
|
|
9
4
|
delete require.cache[require.resolve(module)]
|