@maizzle/framework 4.0.0-alpha.7 → 4.0.0-alpha.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/.github/workflows/nodejs.yml +1 -1
- package/package.json +87 -86
- package/src/commands/serve.js +16 -13
- package/src/generators/output/to-string.js +1 -1
- package/src/generators/postcss.js +29 -0
- package/src/generators/posthtml.js +66 -61
- package/src/generators/tailwindcss.js +116 -116
- package/src/index.js +17 -13
- package/src/transformers/index.js +60 -57
- package/src/transformers/inlineCss.js +1 -1
- package/src/transformers/minify.js +1 -1
- package/src/transformers/prettify.js +1 -1
- package/src/transformers/removeInlineBackgroundColor.js +1 -1
- package/src/transformers/removeInlinedSelectors.js +71 -0
- package/src/transformers/removeUnusedCss.js +17 -2
- package/src/transformers/sixHex.js +24 -1
- package/src/transformers/transform.js +35 -6
- package/test/expected/posthtml/component.html +13 -0
- package/test/expected/{inheritance.html → posthtml/extend-template.html} +2 -2
- package/test/expected/posthtml/fetch.html +5 -0
- package/test/expected/posthtml/layout.html +3 -0
- package/test/expected/transformers/atimport-in-style.html +14 -0
- package/test/expected/transformers/base-image-url.html +83 -83
- package/test/expected/transformers/preserve-transform-css.html +27 -0
- package/test/fixtures/posthtml/component.html +19 -0
- package/test/fixtures/{inheritance.html → posthtml/extend-template.html} +7 -7
- package/test/fixtures/posthtml/fetch.html +9 -0
- package/test/fixtures/posthtml/layout.html +11 -0
- package/test/fixtures/transformers/atimport-in-style.html +11 -0
- package/test/fixtures/transformers/base-image-url.html +85 -85
- package/test/fixtures/transformers/preserve-transform-css.html +25 -0
- package/test/stubs/components/component.html +5 -0
- package/test/stubs/data.json +14 -0
- package/test/stubs/layouts/basic.html +1 -0
- package/test/stubs/{layout.html → layouts/full.html} +0 -0
- package/test/stubs/{layout-basic.html → layouts/template.html} +5 -5
- package/test/stubs/post.css +6 -0
- package/test/stubs/tailwind/{preserve.html → content-source.html} +0 -0
- package/test/stubs/tailwind/tailwind.css +3 -0
- package/test/stubs/template.html +10 -10
- package/test/test-postcss.js +8 -0
- package/test/test-posthtml.js +66 -0
- package/test/{test-tailwind.js → test-tailwindcss.js} +3 -3
- package/test/test-tostring.js +142 -132
- package/test/test-transformers.js +479 -343
- package/test/expected/transformers/transform-postcss.html +0 -19
package/package.json
CHANGED
|
@@ -1,86 +1,87 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@maizzle/framework",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
4
|
-
"description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "src/index.js",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/maizzle/framework.git"
|
|
10
|
-
},
|
|
11
|
-
"bugs": "https://github.com/maizzle/framework/issues",
|
|
12
|
-
"homepage": "https://maizzle.com",
|
|
13
|
-
"author": "Cosmin Popovici (https://github.com/cossssmin)",
|
|
14
|
-
"keywords": [
|
|
15
|
-
"maizzle",
|
|
16
|
-
"tailwindcss",
|
|
17
|
-
"responsive-email",
|
|
18
|
-
"email-framework",
|
|
19
|
-
"email-template",
|
|
20
|
-
"email-marketing",
|
|
21
|
-
"email-campaigns",
|
|
22
|
-
"email-newsletter",
|
|
23
|
-
"email-boilerplate",
|
|
24
|
-
"html-emails"
|
|
25
|
-
],
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
28
|
-
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"test": "c8 ava -s",
|
|
31
|
-
"pretest": "xo",
|
|
32
|
-
"style": "xo",
|
|
33
|
-
"release": "np"
|
|
34
|
-
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"autoprefixer": "^10.4.0",
|
|
37
|
-
"browser-sync": "^2.26.13",
|
|
38
|
-
"color-shorthand-hex-to-six-digit": "^3.0.2",
|
|
39
|
-
"email-comb": "^5.
|
|
40
|
-
"front-matter": "^4.0.0",
|
|
41
|
-
"fs-extra": "^10.0.0",
|
|
42
|
-
"glob-promise": "^4.1.0",
|
|
43
|
-
"html-crush": "^4.0.0",
|
|
44
|
-
"is-url-superb": "^5.0.0",
|
|
45
|
-
"juice": "^8.0.0",
|
|
46
|
-
"lodash": "^4.17.20",
|
|
47
|
-
"ora": "^5.1.0",
|
|
48
|
-
"postcss": "^8.4.4",
|
|
49
|
-
"postcss-import": "^14.0.0",
|
|
50
|
-
"postcss-merge-longhand": "^5.0.1",
|
|
51
|
-
"posthtml": "^0.16.6",
|
|
52
|
-
"posthtml-attrs-parser": "^0.1.1",
|
|
53
|
-
"posthtml-base-url": "^1.0.1",
|
|
54
|
-
"posthtml-content": "^0.0.3",
|
|
55
|
-
"posthtml-expressions": "^1.8.1",
|
|
56
|
-
"posthtml-extend": "^0.6.0",
|
|
57
|
-
"posthtml-extra-attributes": "^1.0.0",
|
|
58
|
-
"posthtml-fetch": "^2.
|
|
59
|
-
"posthtml-markdownit": "^1.3.0",
|
|
60
|
-
"posthtml-
|
|
61
|
-
"posthtml-
|
|
62
|
-
"posthtml-
|
|
63
|
-
"posthtml-
|
|
64
|
-
"posthtml-
|
|
65
|
-
"posthtml-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"string
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@maizzle/framework",
|
|
3
|
+
"version": "4.0.0-alpha.8",
|
|
4
|
+
"description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/maizzle/framework.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": "https://github.com/maizzle/framework/issues",
|
|
12
|
+
"homepage": "https://maizzle.com",
|
|
13
|
+
"author": "Cosmin Popovici (https://github.com/cossssmin)",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"maizzle",
|
|
16
|
+
"tailwindcss",
|
|
17
|
+
"responsive-email",
|
|
18
|
+
"email-framework",
|
|
19
|
+
"email-template",
|
|
20
|
+
"email-marketing",
|
|
21
|
+
"email-campaigns",
|
|
22
|
+
"email-newsletter",
|
|
23
|
+
"email-boilerplate",
|
|
24
|
+
"html-emails"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "c8 ava -s",
|
|
31
|
+
"pretest": "xo",
|
|
32
|
+
"style": "xo",
|
|
33
|
+
"release": "np"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"autoprefixer": "^10.4.0",
|
|
37
|
+
"browser-sync": "^2.26.13",
|
|
38
|
+
"color-shorthand-hex-to-six-digit": "^3.0.2",
|
|
39
|
+
"email-comb": "^5.2.0",
|
|
40
|
+
"front-matter": "^4.0.0",
|
|
41
|
+
"fs-extra": "^10.0.0",
|
|
42
|
+
"glob-promise": "^4.1.0",
|
|
43
|
+
"html-crush": "^4.0.0",
|
|
44
|
+
"is-url-superb": "^5.0.0",
|
|
45
|
+
"juice": "^8.0.0",
|
|
46
|
+
"lodash": "^4.17.20",
|
|
47
|
+
"ora": "^5.1.0",
|
|
48
|
+
"postcss": "^8.4.4",
|
|
49
|
+
"postcss-import": "^14.0.0",
|
|
50
|
+
"postcss-merge-longhand": "^5.0.1",
|
|
51
|
+
"posthtml": "^0.16.6",
|
|
52
|
+
"posthtml-attrs-parser": "^0.1.1",
|
|
53
|
+
"posthtml-base-url": "^1.0.1",
|
|
54
|
+
"posthtml-content": "^0.0.3",
|
|
55
|
+
"posthtml-expressions": "^1.8.1",
|
|
56
|
+
"posthtml-extend": "^0.6.0",
|
|
57
|
+
"posthtml-extra-attributes": "^1.0.0",
|
|
58
|
+
"posthtml-fetch": "^2.2.0",
|
|
59
|
+
"posthtml-markdownit": "^1.3.0",
|
|
60
|
+
"posthtml-match-helper": "^1.0.3",
|
|
61
|
+
"posthtml-modules": "^0.9.0",
|
|
62
|
+
"posthtml-mso": "^1.0.4",
|
|
63
|
+
"posthtml-postcss-merge-longhand": "^1.0.2",
|
|
64
|
+
"posthtml-remove-attributes": "^1.0.0",
|
|
65
|
+
"posthtml-safe-class-names": "^1.0.4",
|
|
66
|
+
"posthtml-url-parameters": "^1.0.4",
|
|
67
|
+
"pretty": "^2.0.0",
|
|
68
|
+
"prevent-widows": "^1.0.2",
|
|
69
|
+
"query-string": "^7.1.0",
|
|
70
|
+
"string-strip-html": "^8.2.0",
|
|
71
|
+
"tailwindcss": "^3.0.0"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"ava": "^4.0.1",
|
|
75
|
+
"c8": "^7.11.0",
|
|
76
|
+
"np": "*",
|
|
77
|
+
"xo": "0.39.1"
|
|
78
|
+
},
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=14.19.1"
|
|
81
|
+
},
|
|
82
|
+
"ava": {
|
|
83
|
+
"files": [
|
|
84
|
+
"test/**/test*.js"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/commands/serve.js
CHANGED
|
@@ -121,19 +121,22 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
121
121
|
|
|
122
122
|
// Initialize Browsersync
|
|
123
123
|
browsersync()
|
|
124
|
-
.init(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
.init(
|
|
125
|
+
merge(
|
|
126
|
+
{
|
|
127
|
+
notify: false,
|
|
128
|
+
open: false,
|
|
129
|
+
port: 3000,
|
|
130
|
+
server: {
|
|
131
|
+
baseDir,
|
|
132
|
+
directory: true
|
|
133
|
+
},
|
|
134
|
+
tunnel: false,
|
|
135
|
+
ui: {port: 3001},
|
|
136
|
+
logFileChanges: false
|
|
137
|
+
},
|
|
138
|
+
get(config, 'build.browsersync', {})
|
|
139
|
+
), () => {})
|
|
137
140
|
} catch (error) {
|
|
138
141
|
spinner.fail(error)
|
|
139
142
|
throw error
|
|
@@ -22,7 +22,7 @@ module.exports = async (html, options) => {
|
|
|
22
22
|
let config = merge(fileConfig, get(options, 'maizzle', {}))
|
|
23
23
|
|
|
24
24
|
const tailwindConfig = get(options, 'tailwind.config', {})
|
|
25
|
-
const cssString = get(options, 'tailwind.css', '
|
|
25
|
+
const cssString = get(options, 'tailwind.css', '')
|
|
26
26
|
|
|
27
27
|
let {frontmatter} = fm(html)
|
|
28
28
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const {get} = require('lodash')
|
|
3
|
+
const postcss = require('postcss')
|
|
4
|
+
const postcssImport = require('postcss-import')
|
|
5
|
+
const postcssNested = require('tailwindcss/nesting')
|
|
6
|
+
const mergeLonghand = require('postcss-merge-longhand')
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
process: async (css = '', maizzleConfig = {}, spinner = null) => {
|
|
10
|
+
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
11
|
+
|
|
12
|
+
return postcss([
|
|
13
|
+
postcssImport({path: path.dirname(userFilePath)}),
|
|
14
|
+
postcssNested(),
|
|
15
|
+
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
16
|
+
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
17
|
+
])
|
|
18
|
+
.process(css, {from: undefined})
|
|
19
|
+
.then(result => result.css)
|
|
20
|
+
.catch(error => {
|
|
21
|
+
console.error(error)
|
|
22
|
+
if (spinner) {
|
|
23
|
+
spinner.stop()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw new Error(`PostCSS processing failed`)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,61 +1,66 @@
|
|
|
1
|
-
const fm = require('front-matter')
|
|
2
|
-
const posthtml = require('posthtml')
|
|
3
|
-
const {get, merge} = require('lodash')
|
|
4
|
-
const fetch = require('posthtml-fetch')
|
|
5
|
-
const layouts = require('posthtml-extend')
|
|
6
|
-
const modules = require('posthtml-modules')
|
|
7
|
-
const expressions = require('posthtml-expressions')
|
|
8
|
-
|
|
9
|
-
module.exports = async (html, config) => {
|
|
10
|
-
const layoutsOptions = get(config, 'build.layouts', {})
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
1
|
+
const fm = require('front-matter')
|
|
2
|
+
const posthtml = require('posthtml')
|
|
3
|
+
const {get, merge} = require('lodash')
|
|
4
|
+
const fetch = require('posthtml-fetch')
|
|
5
|
+
const layouts = require('posthtml-extend')
|
|
6
|
+
const modules = require('posthtml-modules')
|
|
7
|
+
const expressions = require('posthtml-expressions')
|
|
8
|
+
|
|
9
|
+
module.exports = async (html, config) => {
|
|
10
|
+
const layoutsOptions = get(config, 'build.layouts', {})
|
|
11
|
+
|
|
12
|
+
const modulesOptions = get(config, 'build.components', {})
|
|
13
|
+
// Fake `from` option so we can reference modules relatively
|
|
14
|
+
const modulesRoot = modulesOptions.root || './'
|
|
15
|
+
const modulesFrom = modulesOptions.from || `${modulesRoot}/fake`
|
|
16
|
+
|
|
17
|
+
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
18
|
+
const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
|
|
19
|
+
|
|
20
|
+
const expressionsOptions = merge({strictMode: false}, get(config, 'build.posthtml.expressions', {}))
|
|
21
|
+
|
|
22
|
+
const locals = merge(
|
|
23
|
+
get(expressionsOptions, 'locals', {}),
|
|
24
|
+
get(config, 'locals', {}),
|
|
25
|
+
{page: config}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const fetchPlugin = fetch(
|
|
29
|
+
merge(
|
|
30
|
+
{
|
|
31
|
+
expressions: merge({...expressionsOptions, locals})
|
|
32
|
+
},
|
|
33
|
+
get(config, 'build.posthtml.fetch', {})
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return posthtml([
|
|
38
|
+
fetchPlugin,
|
|
39
|
+
expressions({...expressionsOptions, locals}),
|
|
40
|
+
layouts(
|
|
41
|
+
merge(
|
|
42
|
+
{
|
|
43
|
+
strict: false,
|
|
44
|
+
expressions: merge({...expressionsOptions, locals})
|
|
45
|
+
},
|
|
46
|
+
layoutsOptions
|
|
47
|
+
)
|
|
48
|
+
),
|
|
49
|
+
modules({
|
|
50
|
+
parser: posthtmlOptions,
|
|
51
|
+
attributeAsLocals: true,
|
|
52
|
+
from: modulesFrom,
|
|
53
|
+
root: modulesRoot,
|
|
54
|
+
tag: 'component',
|
|
55
|
+
attribute: 'src',
|
|
56
|
+
plugins: [
|
|
57
|
+
fetchPlugin
|
|
58
|
+
],
|
|
59
|
+
locals,
|
|
60
|
+
...modulesOptions
|
|
61
|
+
}),
|
|
62
|
+
...posthtmlPlugins
|
|
63
|
+
])
|
|
64
|
+
.process(html, {...posthtmlOptions})
|
|
65
|
+
.then(result => fm(result.html).body)
|
|
66
|
+
}
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const fs = require('fs-extra')
|
|
3
|
-
const postcss = require('postcss')
|
|
4
|
-
const tailwindcss = require('tailwindcss')
|
|
5
|
-
const postcssImport = require('postcss-import')
|
|
6
|
-
const postcssNested = require('tailwindcss/nesting')
|
|
7
|
-
const {requireUncached} = require('../utils/helpers')
|
|
8
|
-
const mergeLonghand = require('postcss-merge-longhand')
|
|
9
|
-
const {get, isObject, isEmpty, merge} = require('lodash')
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
compile: async (css = '', html = '', tailwindConfig = {}, maizzleConfig = {}, spinner = null) => {
|
|
13
|
-
tailwindConfig = (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) ? tailwindConfig : get(maizzleConfig, 'build.tailwind.config', 'tailwind.config.js')
|
|
14
|
-
|
|
15
|
-
// Compute the Tailwind config to use
|
|
16
|
-
const userConfig = () => {
|
|
17
|
-
// If a custom config object was passed, use that
|
|
18
|
-
if (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) {
|
|
19
|
-
return tailwindConfig
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Try loading a fresh tailwind.config.js, with fallback to an empty object.
|
|
24
|
-
* This will use the default Tailwind config (with rem units etc)
|
|
25
|
-
*/
|
|
26
|
-
try {
|
|
27
|
-
return requireUncached(path.resolve(process.cwd(), tailwindConfig))
|
|
28
|
-
} catch {
|
|
29
|
-
return {}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Merge user's Tailwind config on top of a 'base' config
|
|
34
|
-
const config = merge({
|
|
35
|
-
important: true,
|
|
36
|
-
content: {
|
|
37
|
-
files: [
|
|
38
|
-
'./src/**/*.*',
|
|
39
|
-
{raw: html, extension: 'html'}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
}, userConfig())
|
|
43
|
-
|
|
44
|
-
// Add back the `{raw: html}` option if user provided own config
|
|
45
|
-
if (Array.isArray(config.content)) {
|
|
46
|
-
config.content = {
|
|
47
|
-
files: [
|
|
48
|
-
...config.content,
|
|
49
|
-
'./src/**/*.*',
|
|
50
|
-
{raw: html, extension: 'html'}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Include all `build.templates.source` paths when scanning for selectors to preserve
|
|
56
|
-
const buildTemplates = get(maizzleConfig, 'build.templates')
|
|
57
|
-
|
|
58
|
-
if (buildTemplates) {
|
|
59
|
-
const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
60
|
-
const templateSources = templateObjects.map(template => {
|
|
61
|
-
const source = get(template, 'source')
|
|
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
|
-
|
|
76
|
-
// Support single-file sources i.e. src/templates/index.html
|
|
77
|
-
if (typeof source === 'string' && Boolean(path.extname(source))) {
|
|
78
|
-
config.content.files.push(source)
|
|
79
|
-
|
|
80
|
-
return {raw: '', extension: 'html'}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return `${source}/**/*.*`
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
config.content.files.push(...templateSources)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
90
|
-
const userFileExists = await fs.pathExists(userFilePath)
|
|
91
|
-
|
|
92
|
-
if (userFileExists) {
|
|
93
|
-
css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
|
|
94
|
-
} else {
|
|
95
|
-
css =
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return postcss([
|
|
99
|
-
postcssImport({path: path.dirname(userFilePath)}),
|
|
100
|
-
postcssNested(),
|
|
101
|
-
tailwindcss(config),
|
|
102
|
-
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
103
|
-
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
104
|
-
])
|
|
105
|
-
.process(css, {from: undefined})
|
|
106
|
-
.then(result => result.css)
|
|
107
|
-
.catch(error => {
|
|
108
|
-
console.error(error)
|
|
109
|
-
if (spinner) {
|
|
110
|
-
spinner.stop()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
throw new Error(`Tailwind CSS compilation failed`)
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const fs = require('fs-extra')
|
|
3
|
+
const postcss = require('postcss')
|
|
4
|
+
const tailwindcss = require('tailwindcss')
|
|
5
|
+
const postcssImport = require('postcss-import')
|
|
6
|
+
const postcssNested = require('tailwindcss/nesting')
|
|
7
|
+
const {requireUncached} = require('../utils/helpers')
|
|
8
|
+
const mergeLonghand = require('postcss-merge-longhand')
|
|
9
|
+
const {get, isObject, isEmpty, merge} = require('lodash')
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
compile: async (css = '', html = '', tailwindConfig = {}, maizzleConfig = {}, spinner = null) => {
|
|
13
|
+
tailwindConfig = (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) ? tailwindConfig : get(maizzleConfig, 'build.tailwind.config', 'tailwind.config.js')
|
|
14
|
+
|
|
15
|
+
// Compute the Tailwind config to use
|
|
16
|
+
const userConfig = () => {
|
|
17
|
+
// If a custom config object was passed, use that
|
|
18
|
+
if (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) {
|
|
19
|
+
return tailwindConfig
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Try loading a fresh tailwind.config.js, with fallback to an empty object.
|
|
24
|
+
* This will use the default Tailwind config (with rem units etc)
|
|
25
|
+
*/
|
|
26
|
+
try {
|
|
27
|
+
return requireUncached(path.resolve(process.cwd(), tailwindConfig))
|
|
28
|
+
} catch {
|
|
29
|
+
return {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Merge user's Tailwind config on top of a 'base' config
|
|
34
|
+
const config = merge({
|
|
35
|
+
important: true,
|
|
36
|
+
content: {
|
|
37
|
+
files: [
|
|
38
|
+
'./src/**/*.*',
|
|
39
|
+
{raw: html, extension: 'html'}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}, userConfig())
|
|
43
|
+
|
|
44
|
+
// Add back the `{raw: html}` option if user provided own config
|
|
45
|
+
if (Array.isArray(config.content)) {
|
|
46
|
+
config.content = {
|
|
47
|
+
files: [
|
|
48
|
+
...config.content,
|
|
49
|
+
'./src/**/*.*',
|
|
50
|
+
{raw: html, extension: 'html'}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Include all `build.templates.source` paths when scanning for selectors to preserve
|
|
56
|
+
const buildTemplates = get(maizzleConfig, 'build.templates')
|
|
57
|
+
|
|
58
|
+
if (buildTemplates) {
|
|
59
|
+
const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
60
|
+
const templateSources = templateObjects.map(template => {
|
|
61
|
+
const source = get(template, 'source')
|
|
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
|
+
|
|
76
|
+
// Support single-file sources i.e. src/templates/index.html
|
|
77
|
+
if (typeof source === 'string' && Boolean(path.extname(source))) {
|
|
78
|
+
config.content.files.push(source)
|
|
79
|
+
|
|
80
|
+
return {raw: '', extension: 'html'}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return `${source}/**/*.*`
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
config.content.files.push(...templateSources)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
90
|
+
const userFileExists = await fs.pathExists(userFilePath)
|
|
91
|
+
|
|
92
|
+
if (userFileExists) {
|
|
93
|
+
css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
|
|
94
|
+
} else {
|
|
95
|
+
css = `@import "tailwindcss/components"; @import "tailwindcss/utilities"; ${css}`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return postcss([
|
|
99
|
+
postcssImport({path: path.dirname(userFilePath)}),
|
|
100
|
+
postcssNested(),
|
|
101
|
+
tailwindcss(config),
|
|
102
|
+
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
103
|
+
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
104
|
+
])
|
|
105
|
+
.process(css, {from: undefined})
|
|
106
|
+
.then(result => result.css)
|
|
107
|
+
.catch(error => {
|
|
108
|
+
console.error(error)
|
|
109
|
+
if (spinner) {
|
|
110
|
+
spinner.stop()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw new Error(`Tailwind CSS compilation failed`)
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
const serve = require('./commands/serve')
|
|
2
|
-
const toFile = require('./commands/build')
|
|
3
|
-
const transformers = require('./transformers')
|
|
4
|
-
const toString = require('./functions/render')
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
const serve = require('./commands/serve')
|
|
2
|
+
const toFile = require('./commands/build')
|
|
3
|
+
const transformers = require('./transformers')
|
|
4
|
+
const toString = require('./functions/render')
|
|
5
|
+
const PostCSS = require('./generators/postcss')
|
|
6
|
+
const toPlaintext = require('./functions/plaintext')
|
|
7
|
+
const TailwindCSS = require('./generators/tailwindcss')
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
serve,
|
|
11
|
+
build: toFile,
|
|
12
|
+
...transformers,
|
|
13
|
+
render: toString,
|
|
14
|
+
postcss: PostCSS,
|
|
15
|
+
plaintext: toPlaintext,
|
|
16
|
+
tailwindcss: TailwindCSS
|
|
17
|
+
}
|