@maizzle/framework 4.0.0-alpha.9 → 4.0.0
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/media/logo-dark.svg +1 -0
- package/.github/media/logo-light.svg +1 -0
- package/.github/workflows/nodejs.yml +1 -1
- package/README.md +42 -35
- package/package.json +91 -91
- package/src/generators/output/to-string.js +67 -71
- package/src/transformers/index.js +63 -60
- package/src/transformers/inlineCss.js +0 -13
- package/src/transformers/prettify.js +27 -29
- package/src/transformers/shorthandInlineCSS.js +19 -0
- package/test/expected/posthtml/component.html +1 -1
- package/test/expected/transformers/atimport-in-style.html +12 -13
- package/test/expected/transformers/preserve-transform-css.html +33 -45
- package/test/expected/useConfig.html +6 -6
- package/test/fixtures/posthtml/component.html +2 -2
- package/test/test-config.js +19 -19
- package/test/test-postcss.js +8 -8
- package/test/test-posthtml.js +72 -66
- package/test/test-tailwindcss.js +117 -117
- package/test/test-todisk.js +511 -511
- package/test/test-transformers.js +510 -490
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (typeof config === 'boolean' && config) {
|
|
21
|
-
return pretty(html, defaultConfig)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return html
|
|
29
|
-
}
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
const pretty = require('pretty')
|
|
3
|
+
const {get, merge, isEmpty, isObject} = require('lodash')
|
|
4
|
+
|
|
5
|
+
module.exports = async (html, config = {}, direct = false) => {
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
space_around_combinator: true, // Preserve space around CSS selector combinators
|
|
8
|
+
newline_between_rules: false, // Remove empty lines between CSS rules
|
|
9
|
+
indent_inner_html: false, // Helps reduce file size
|
|
10
|
+
extra_liners: [] // Don't add extra new line before any tag
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
config = direct ? config : get(config, 'prettify')
|
|
14
|
+
|
|
15
|
+
// Don't prettify if not explicitly enabled in config
|
|
16
|
+
if (!config || (isObject(config) && isEmpty(config))) {
|
|
17
|
+
return html
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof config === 'boolean' && config) {
|
|
21
|
+
return pretty(html, defaultConfig)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
config = merge(defaultConfig, config)
|
|
25
|
+
|
|
26
|
+
return pretty(html, config)
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const posthtml = require('posthtml')
|
|
2
|
+
const {get, isObject, isEmpty} = require('lodash')
|
|
3
|
+
const mergeLonghand = require('posthtml-postcss-merge-longhand')
|
|
4
|
+
|
|
5
|
+
module.exports = async (html, config, direct = false) => {
|
|
6
|
+
config = direct ? (isObject(config) ? config : true) : get(config, 'shorthandInlineCSS', [])
|
|
7
|
+
|
|
8
|
+
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
9
|
+
|
|
10
|
+
if (typeof config === 'boolean' && config) {
|
|
11
|
+
html = await posthtml([mergeLonghand()]).process(html, posthtmlOptions).then(result => result.html)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (isObject(config) && !isEmpty(config)) {
|
|
15
|
+
html = await posthtml([mergeLonghand(config)]).process(html, posthtmlOptions).then(result => result.html)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return html
|
|
19
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
</
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
</body>
|
|
3
|
+
<head>
|
|
4
|
+
<style>div {
|
|
5
|
+
margin-top: 1px;
|
|
6
|
+
margin-right: 2px;
|
|
7
|
+
margin-bottom: 3px;
|
|
8
|
+
margin-left: 4px;
|
|
9
|
+
}
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div>test</div>
|
|
14
|
+
</body>
|
|
16
15
|
</html>
|
|
@@ -1,48 +1,36 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
div > u + .body .gmail-android-block {
|
|
38
|
-
display: block !important;
|
|
39
|
-
}
|
|
40
|
-
u + #body a {
|
|
41
|
-
color: inherit;
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
44
|
-
</head>
|
|
45
|
-
<body>
|
|
46
|
-
<div>test</div>
|
|
47
|
-
</body>
|
|
3
|
+
<head>
|
|
4
|
+
<style data-embed="">.block {
|
|
5
|
+
display: block !important;
|
|
6
|
+
} .inline {
|
|
7
|
+
display: inline !important;
|
|
8
|
+
} .table {
|
|
9
|
+
display: table !important;
|
|
10
|
+
} .contents {
|
|
11
|
+
display: contents !important;
|
|
12
|
+
} .truncate {
|
|
13
|
+
overflow: hidden !important;
|
|
14
|
+
text-overflow: ellipsis !important;
|
|
15
|
+
white-space: nowrap !important;
|
|
16
|
+
} .uppercase {
|
|
17
|
+
text-transform: uppercase !important;
|
|
18
|
+
} .lowercase {
|
|
19
|
+
text-transform: lowercase !important;
|
|
20
|
+
} .capitalize {
|
|
21
|
+
text-transform: capitalize !important;
|
|
22
|
+
} div {
|
|
23
|
+
text-transform: uppercase;
|
|
24
|
+
} [data-ogsc] .inexistent {
|
|
25
|
+
color: #ef4444;
|
|
26
|
+
} div > u + .body .gmail-android-block {
|
|
27
|
+
display: block !important;
|
|
28
|
+
} u + #body a {
|
|
29
|
+
color: inherit;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div>test</div>
|
|
35
|
+
</body>
|
|
48
36
|
</html>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"foo": "bar"
|
|
6
6
|
}'
|
|
7
7
|
>
|
|
8
|
-
|
|
8
|
+
Variable from page: [[ page.env ]]
|
|
9
9
|
|
|
10
10
|
<component
|
|
11
11
|
src="test/stubs/components/component.html"
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"foo": "bar (nested)"
|
|
15
15
|
}'
|
|
16
16
|
>
|
|
17
|
-
|
|
17
|
+
Variable from page (nested): [[ page.env ]]
|
|
18
18
|
</component>
|
|
19
19
|
</component>
|
package/test/test-config.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const test = require('ava')
|
|
2
|
-
const Config = require('../src/generators/config')
|
|
3
|
-
|
|
4
|
-
test('returns the merged config', async t => {
|
|
5
|
-
const config = await Config.getMerged('maizzle-ci')
|
|
6
|
-
t.is(config.env, 'maizzle-ci')
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
test('throws if env name is not a string', async t => {
|
|
10
|
-
await t.throwsAsync(async () => {
|
|
11
|
-
await Config.getMerged(false)
|
|
12
|
-
}, {instanceOf: TypeError, message: `env name must be a string, received boolean(false)`})
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('throws if a config could not be loaded for the specified environment', async t => {
|
|
16
|
-
await t.throwsAsync(async () => {
|
|
17
|
-
await Config.getMerged('fake')
|
|
18
|
-
}, {instanceOf: Error, message: `could not load config.fake.js`})
|
|
19
|
-
})
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
const Config = require('../src/generators/config')
|
|
3
|
+
|
|
4
|
+
test('returns the merged config', async t => {
|
|
5
|
+
const config = await Config.getMerged('maizzle-ci')
|
|
6
|
+
t.is(config.env, 'maizzle-ci')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('throws if env name is not a string', async t => {
|
|
10
|
+
await t.throwsAsync(async () => {
|
|
11
|
+
await Config.getMerged(false)
|
|
12
|
+
}, {instanceOf: TypeError, message: `env name must be a string, received boolean(false)`})
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('throws if a config could not be loaded for the specified environment', async t => {
|
|
16
|
+
await t.throwsAsync(async () => {
|
|
17
|
+
await Config.getMerged('fake')
|
|
18
|
+
}, {instanceOf: Error, message: `could not load config.fake.js`})
|
|
19
|
+
})
|
package/test/test-postcss.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const test = require('ava')
|
|
2
|
-
const PostCSS = require('../src/generators/postcss')
|
|
3
|
-
|
|
4
|
-
test('throws on processing error', async t => {
|
|
5
|
-
await t.throwsAsync(async () => {
|
|
6
|
-
await PostCSS.process(null, {})
|
|
7
|
-
}, {instanceOf: Error, message: 'PostCSS processing failed'})
|
|
8
|
-
})
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
const PostCSS = require('../src/generators/postcss')
|
|
3
|
+
|
|
4
|
+
test('throws on processing error', async t => {
|
|
5
|
+
await t.throwsAsync(async () => {
|
|
6
|
+
await PostCSS.process(null, {})
|
|
7
|
+
}, {instanceOf: Error, message: 'PostCSS processing failed'})
|
|
8
|
+
})
|
package/test/test-posthtml.js
CHANGED
|
@@ -1,66 +1,72 @@
|
|
|
1
|
-
const test = require('ava')
|
|
2
|
-
const Maizzle = require('../src')
|
|
3
|
-
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
const Maizzle = require('../src')
|
|
3
|
+
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
|
|
7
|
+
const readFile = (dir, filename) => fs.promises
|
|
8
|
+
.readFile(path.join(__dirname, dir, `${filename}.html`), 'utf8')
|
|
9
|
+
.then(html => html.trim())
|
|
10
|
+
|
|
11
|
+
const fixture = file => readFile('fixtures', file)
|
|
12
|
+
const expected = file => readFile('expected', file)
|
|
13
|
+
|
|
14
|
+
const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)
|
|
15
|
+
|
|
16
|
+
test('layouts', async t => {
|
|
17
|
+
const source = await fixture('posthtml/layout')
|
|
18
|
+
|
|
19
|
+
const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
|
|
20
|
+
|
|
21
|
+
t.is(html.trim(), await expected('posthtml/layout'))
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('inheritance when extending a template', async t => {
|
|
25
|
+
const source = await fixture('posthtml/extend-template')
|
|
26
|
+
let html = await renderString(source)
|
|
27
|
+
|
|
28
|
+
html = html.replace(/[^\S\r\n]+$/gm, '').trim()
|
|
29
|
+
|
|
30
|
+
t.is(html, await expected('posthtml/extend-template'))
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('components', async t => {
|
|
34
|
+
const source = await fixture('posthtml/component')
|
|
35
|
+
const options = {
|
|
36
|
+
maizzle: {
|
|
37
|
+
env: 'maizzle-ci',
|
|
38
|
+
build: {
|
|
39
|
+
components: {
|
|
40
|
+
expressions: {
|
|
41
|
+
delimiters: ['[[', ']]']
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const html = await renderString(source, options)
|
|
49
|
+
|
|
50
|
+
t.is(html.trim(), await expected('posthtml/component'))
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('fetch component', async t => {
|
|
54
|
+
const source = await fixture('posthtml/fetch')
|
|
55
|
+
const options = {
|
|
56
|
+
maizzle: {
|
|
57
|
+
env: 'maizzle-ci',
|
|
58
|
+
build: {
|
|
59
|
+
posthtml: {
|
|
60
|
+
expressions: {
|
|
61
|
+
delimiters: ['[[', ']]']
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let html = await renderString(source, options)
|
|
69
|
+
html = html.replace(/[^\S\r\n]+$/gm, '')
|
|
70
|
+
|
|
71
|
+
t.is(html.trim(), await expected('posthtml/fetch'))
|
|
72
|
+
})
|