@maizzle/framework 3.7.2 → 4.0.0-alpha.10

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.
Files changed (84) hide show
  1. package/.github/workflows/nodejs.yml +28 -29
  2. package/bin/maizzle +3 -0
  3. package/package.json +91 -84
  4. package/src/commands/build.js +32 -0
  5. package/src/commands/serve.js +156 -0
  6. package/src/functions/plaintext.js +5 -0
  7. package/src/functions/render.js +5 -0
  8. package/src/generators/output/to-disk.js +120 -79
  9. package/src/generators/output/to-string.js +7 -8
  10. package/src/generators/plaintext.js +49 -52
  11. package/src/generators/postcss.js +29 -0
  12. package/src/generators/posthtml.js +66 -60
  13. package/src/generators/tailwindcss.js +116 -84
  14. package/src/index.js +14 -160
  15. package/src/transformers/{attribute-to-style.js → attributeToStyle.js} +0 -0
  16. package/src/transformers/baseUrl.js +69 -0
  17. package/src/transformers/{extra-attributes.js → extraAttributes.js} +0 -0
  18. package/src/transformers/filters/defaultFilters.js +126 -0
  19. package/src/transformers/filters/index.js +55 -0
  20. package/src/transformers/index.js +63 -57
  21. package/src/transformers/{inline.js → inlineCss.js} +1 -14
  22. package/src/transformers/minify.js +1 -1
  23. package/src/transformers/{posthtml-mso.js → posthtmlMso.js} +0 -0
  24. package/src/transformers/prettify.js +16 -9
  25. package/src/transformers/{prevent-widows.js → preventWidows.js} +0 -0
  26. package/src/transformers/{remove-attributes.js → removeAttributes.js} +1 -1
  27. package/src/transformers/{remove-inline-bgcolor.js → removeInlineBackgroundColor.js} +1 -1
  28. package/src/transformers/{remove-inline-sizes.js → removeInlineSizes.js} +0 -0
  29. package/src/transformers/removeInlinedSelectors.js +70 -0
  30. package/src/transformers/removeUnusedCss.js +40 -0
  31. package/src/transformers/{replace-strings.js → replaceStrings.js} +0 -0
  32. package/src/transformers/{safe-class-names.js → safeClassNames.js} +8 -2
  33. package/src/transformers/shorthandInlineCSS.js +19 -0
  34. package/src/transformers/sixHex.js +33 -0
  35. package/src/transformers/{url-params.js → urlParameters.js} +0 -0
  36. package/src/utils/helpers.js +2 -8
  37. package/test/expected/posthtml/component.html +13 -0
  38. package/test/expected/{inheritance.html → posthtml/extend-template.html} +2 -2
  39. package/test/expected/posthtml/fetch.html +5 -0
  40. package/test/expected/posthtml/layout.html +3 -0
  41. package/test/expected/transformers/atimport-in-style.html +15 -0
  42. package/test/expected/transformers/base-url.html +99 -0
  43. package/test/expected/transformers/filters.html +81 -0
  44. package/test/expected/transformers/preserve-transform-css.html +36 -0
  45. package/test/expected/useConfig.html +9 -0
  46. package/test/fixtures/basic.html +9 -9
  47. package/test/fixtures/posthtml/component.html +19 -0
  48. package/test/fixtures/{inheritance.html → posthtml/extend-template.html} +7 -7
  49. package/test/fixtures/posthtml/fetch.html +9 -0
  50. package/test/fixtures/posthtml/layout.html +11 -0
  51. package/test/fixtures/transformers/atimport-in-style.html +11 -0
  52. package/test/fixtures/transformers/base-url.html +101 -0
  53. package/test/fixtures/transformers/filters.html +87 -0
  54. package/test/fixtures/transformers/preserve-transform-css.html +25 -0
  55. package/test/fixtures/useConfig.html +9 -0
  56. package/test/stubs/components/component.html +5 -0
  57. package/test/stubs/data.json +14 -0
  58. package/test/stubs/layouts/basic.html +1 -0
  59. package/test/stubs/{layout.html → layouts/full.html} +0 -0
  60. package/test/stubs/{layout-basic.html → layouts/template.html} +5 -5
  61. package/test/stubs/post.css +6 -0
  62. package/test/stubs/tailwind/content-source.html +1 -0
  63. package/test/stubs/tailwind/tailwind.css +3 -0
  64. package/test/stubs/template.html +10 -10
  65. package/test/stubs/templates/1.html +1 -1
  66. package/test/stubs/templates/2.test +1 -0
  67. package/test/test-config.js +19 -19
  68. package/test/test-misc.js +8 -8
  69. package/test/test-postcss.js +8 -0
  70. package/test/test-posthtml.js +72 -0
  71. package/test/test-tailwindcss.js +117 -0
  72. package/test/test-todisk.js +142 -49
  73. package/test/test-tostring.js +148 -124
  74. package/test/test-transformers.js +510 -320
  75. package/xo.config.js +22 -19
  76. package/src/transformers/base-image-url.js +0 -9
  77. package/src/transformers/remove-unused-css.js +0 -20
  78. package/src/transformers/six-hex.js +0 -10
  79. package/src/transformers/transform.js +0 -24
  80. package/test/expected/transformers/base-image-url.html +0 -7
  81. package/test/fixtures/transformers/base-image-url.html +0 -7
  82. package/test/stubs/templates/2.html +0 -1
  83. package/test/stubs/templates/3.mzl +0 -1
  84. package/test/test-tailwind.js +0 -73
package/xo.config.js CHANGED
@@ -1,19 +1,22 @@
1
- module.exports = {
2
- space: true,
3
- rules: {
4
- semi: 0,
5
- complexity: 0,
6
- 'no-lonely-if': 0,
7
- 'unicorn/no-reduce': 0,
8
- 'import/extensions': 0,
9
- 'operator-linebreak': 0,
10
- 'max-nested-callbacks': 0,
11
- 'unicorn/prefer-ternary': 0,
12
- 'unicorn/string-content': 0,
13
- 'unicorn/no-array-for-each': 0,
14
- 'unicorn/prefer-array-find': 0,
15
- 'promise/prefer-await-to-then': 0,
16
- 'unicorn/no-abusive-eslint-disable': 0,
17
- quotes: ['error', 'single', {allowTemplateLiterals: true}]
18
- }
19
- }
1
+ module.exports = {
2
+ space: true,
3
+ rules: {
4
+ semi: 0,
5
+ complexity: 0,
6
+ 'max-params': 0,
7
+ 'no-lonely-if': 0,
8
+ 'unicorn/no-reduce': 0,
9
+ 'import/extensions': 0,
10
+ 'operator-linebreak': 0,
11
+ 'max-nested-callbacks': 0,
12
+ 'unicorn/filename-case': 0,
13
+ 'unicorn/no-hex-escape': 0,
14
+ 'unicorn/prefer-ternary': 0,
15
+ 'unicorn/string-content': 0,
16
+ 'unicorn/no-array-for-each': 0,
17
+ 'unicorn/prefer-array-find': 0,
18
+ 'promise/prefer-await-to-then': 0,
19
+ 'unicorn/no-abusive-eslint-disable': 0,
20
+ quotes: ['error', 'single', {allowTemplateLiterals: true}]
21
+ }
22
+ }
@@ -1,9 +0,0 @@
1
- module.exports = async (html, config = {}, direct = false) => {
2
- const url = direct ? config : config.baseImageURL
3
-
4
- if (url) {
5
- return html.replace(/([^"'=\s(]+\.(?:jpe?g|a?png|avif|gif|svg|webp|jfif|pjpeg|pjp))/gi, url + '$1')
6
- }
7
-
8
- return html
9
- }
@@ -1,20 +0,0 @@
1
- const {get, isEmpty} = require('lodash')
2
- const {comb} = require('email-comb')
3
-
4
- module.exports = async (html, config = {}, direct = false) => {
5
- if (get(config, 'removeUnusedCSS') === false) {
6
- return html
7
- }
8
-
9
- const options = direct ? config : get(config, 'removeUnusedCSS', {})
10
-
11
- if (typeof options === 'boolean' && options) {
12
- return comb(html).result
13
- }
14
-
15
- if (!isEmpty(options)) {
16
- return comb(html, options).result
17
- }
18
-
19
- return html
20
- }
@@ -1,10 +0,0 @@
1
- const {get} = require('lodash')
2
- const {conv} = require('color-shorthand-hex-to-six-digit')
3
-
4
- module.exports = async (html, config = {}) => {
5
- if (get(config, 'sixHex') === false) {
6
- return html
7
- }
8
-
9
- return conv(html)
10
- }
@@ -1,24 +0,0 @@
1
- const posthtml = require('posthtml')
2
- const posthtmlContent = require('posthtml-content')
3
- const Tailwind = require('../generators/tailwindcss')
4
- const {get, omit} = require('lodash')
5
-
6
- module.exports = async (html, config = {}, direct = false) => {
7
- const replacements = direct ? config : get(config, 'transform', {})
8
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
9
-
10
- /**
11
- * Compile CSS in <style postcss> tags with PostCSS and Tailwind CSS
12
- */
13
- const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
14
- const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
15
-
16
- replacements.postcss = css => Tailwind.compile(
17
- `@tailwind components; @tailwind utilities; ${css}`,
18
- html,
19
- tailwindConfig,
20
- maizzleConfig
21
- )
22
-
23
- return posthtml([posthtmlContent(replacements)]).process(html, posthtmlOptions).then(result => result.html)
24
- }
@@ -1,7 +0,0 @@
1
- <div style="background-image: url('https://example.com/foo/bar.jpg')">
2
- <img src="https://example.com/logo.png" srcset="https://example.com/assets/logo.png 1x, https://example.com/assets/logo@2x.png 2x">
3
- </div>
4
-
5
- <div style="background: url(https://example.com/foo/bar.jpg)">
6
- <img background="https://example.com/example.jpg" srcset="https://example.com/example.jpg 1x, https://example.com/example@2x.jpg 2x">
7
- </div>
@@ -1,7 +0,0 @@
1
- <div style="background-image: url('foo/bar.jpg')">
2
- <img src="logo.png" srcset="assets/logo.png 1x, assets/logo@2x.png 2x">
3
- </div>
4
-
5
- <div style="background: url(foo/bar.jpg)">
6
- <img background="example.jpg" srcset="example.jpg 1x, example@2x.jpg 2x">
7
- </div>
@@ -1 +0,0 @@
1
- <a href="https://example.com">Test</a>
@@ -1 +0,0 @@
1
- <a href="https://example.com">Test</a>
@@ -1,73 +0,0 @@
1
- const test = require('ava')
2
- const Tailwind = require('../src/generators/tailwindcss')
3
-
4
- test('uses Tailwind defaults if no config specified', async t => {
5
- const css = await Tailwind.compile('@tailwind utilities', '<p class="xl:z-0"></p>', {}, {env: 'production'})
6
-
7
- t.not(css, undefined)
8
- t.true(css.includes('.xl\\:z-0'))
9
- })
10
-
11
- test('uses CSS file provided in environment config', async t => {
12
- const config = {
13
- env: 'production',
14
- build: {
15
- tailwind: {
16
- css: './test/stubs/main.css'
17
- }
18
- }
19
- }
20
-
21
- const css = await Tailwind.compile('', '<div class="text-center foo">test</div>', {}, config)
22
-
23
- t.not(css, undefined)
24
- t.true(css.includes('.text-center'))
25
- t.true(css.includes('.foo'))
26
- })
27
-
28
- test('uses purgeCSS options provided in the maizzle config', async t => {
29
- const arrayConfig = {
30
- purgeCSS: {
31
- safelist: ['z-10'],
32
- blocklist: ['text-center']
33
- }
34
- }
35
-
36
- const objectConfig = {
37
- purgeCSS: {
38
- safelist: {
39
- standard: ['z-10']
40
- },
41
- blocklist: ['text-center']
42
- }
43
- }
44
-
45
- const css1 = await Tailwind.compile('@tailwind utilities', '<div class="z-0 text-center"></div>', {}, arrayConfig)
46
- const css2 = await Tailwind.compile('@tailwind utilities', '<div class="z-0 text-center"></div>', {}, objectConfig)
47
-
48
- t.true(css1.includes('.z-0'))
49
- t.true(css1.includes('.z-10'))
50
- t.false(css1.includes('.text-center'))
51
-
52
- t.true(css2.includes('.z-0'))
53
- t.true(css2.includes('.z-10'))
54
- t.false(css2.includes('.text-center'))
55
- })
56
-
57
- test('uses postcss plugins from the maizzle config when compiling from string', async t => {
58
- const maizzleConfig = {
59
- env: 'production',
60
- build: {
61
- postcss: {
62
- plugins: [
63
- require('autoprefixer')({overrideBrowserslist: ['> 0.1%']})
64
- ]
65
- }
66
- }
67
- }
68
-
69
- const css = await Tailwind.compile('.test {transform: scale(0.5)}', '<div class="test">Test</a>', {}, maizzleConfig)
70
-
71
- t.not(css, undefined)
72
- t.is(css.trim(), '/* purgecss start ignore */\n\n.test {\n -webkit-transform: scale(0.5);\n -ms-transform: scale(0.5);\n transform: scale(0.5)\n}\n\n/* purgecss end ignore */')
73
- })