@maizzle/framework 3.7.1 → 4.0.0-alpha.2

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 (39) hide show
  1. package/.github/dependabot.yml +11 -11
  2. package/.github/workflows/nodejs.yml +28 -29
  3. package/package.json +86 -84
  4. package/src/generators/output/to-disk.js +144 -111
  5. package/src/generators/output/to-string.js +71 -64
  6. package/src/generators/posthtml.js +61 -60
  7. package/src/generators/tailwindcss.js +57 -34
  8. package/src/index.js +24 -36
  9. package/src/transformers/{attribute-to-style.js → attributeToStyle.js} +0 -0
  10. package/src/transformers/baseUrl.js +45 -0
  11. package/src/transformers/{extra-attributes.js → extraAttributes.js} +0 -0
  12. package/src/transformers/index.js +13 -13
  13. package/src/transformers/{inline.js → inlineCss.js} +0 -0
  14. package/src/transformers/{posthtml-mso.js → posthtmlMso.js} +0 -0
  15. package/src/transformers/{prevent-widows.js → preventWidows.js} +0 -0
  16. package/src/transformers/{remove-attributes.js → removeAttributes.js} +1 -1
  17. package/src/transformers/{remove-inline-bgcolor.js → removeInlineBackgroundColor.js} +0 -0
  18. package/src/transformers/{remove-inline-sizes.js → removeInlineSizes.js} +0 -0
  19. package/src/transformers/{remove-unused-css.js → removeUnusedCss.js} +0 -0
  20. package/src/transformers/{replace-strings.js → replaceStrings.js} +0 -0
  21. package/src/transformers/{safe-class-names.js → safeClassNames.js} +8 -2
  22. package/src/transformers/{six-hex.js → sixHex.js} +10 -10
  23. package/src/transformers/transform.js +4 -6
  24. package/src/transformers/{url-params.js → urlParameters.js} +0 -0
  25. package/src/utils/helpers.js +2 -8
  26. package/test/expected/transformers/base-image-url.html +83 -7
  27. package/test/expected/transformers/transform-postcss.html +19 -0
  28. package/test/expected/useConfig.html +9 -0
  29. package/test/fixtures/basic.html +9 -0
  30. package/test/fixtures/transformers/base-image-url.html +85 -7
  31. package/test/fixtures/useConfig.html +9 -0
  32. package/test/stubs/tailwind/preserve.html +1 -0
  33. package/test/test-misc.js +8 -8
  34. package/test/test-tailwind.js +100 -73
  35. package/test/test-todisk.js +106 -29
  36. package/test/test-tostring.js +12 -3
  37. package/test/test-transformers.js +343 -320
  38. package/xo.config.js +22 -19
  39. package/src/transformers/base-image-url.js +0 -9
@@ -13,12 +13,10 @@ module.exports = async (html, config = {}, direct = false) => {
13
13
  const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
14
14
  const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
15
15
 
16
- replacements.postcss = css => Tailwind.compile(
17
- `@tailwind components; @tailwind utilities; ${css}`,
18
- html,
19
- tailwindConfig,
20
- maizzleConfig
21
- )
16
+ const compileCss = css => Tailwind.compile(css, html, tailwindConfig, maizzleConfig)
17
+
18
+ replacements.tailwindcss = css => compileCss(`@tailwind components; @tailwind utilities; ${css}`)
19
+ replacements.postcss = css => compileCss(`@tailwind components; @tailwind utilities; ${css}`)
22
20
 
23
21
  return posthtml([posthtmlContent(replacements)]).process(html, posthtmlOptions).then(result => result.html)
24
22
  }
@@ -1,5 +1,3 @@
1
- const readline = require('readline')
2
-
3
1
  module.exports = {
4
2
  asyncForEach: async (array, callback) => {
5
3
  for (let index = 0; index < array.length; index++) {
@@ -14,10 +12,6 @@ module.exports = {
14
12
  throw new Error(`could not load ${module}`)
15
13
  }
16
14
  },
17
- clearConsole: () => {
18
- const blank = '\n'.repeat(process.stdout.rows)
19
- console.log(blank)
20
- readline.cursorTo(process.stdout, 0, 0)
21
- readline.clearScreenDown(process.stdout)
22
- }
15
+ // https://github.com/lukeed/console-clear
16
+ clearConsole: () => process.stdout.write('\x1B[H\x1B[2J')
23
17
  }
@@ -1,7 +1,83 @@
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
+ <html>
2
+ <head>
3
+ <style>.test {
4
+ background-image: url('https://example.com/image.jpg');
5
+ background: url('https://example.com/image.jpg');
6
+ background-image: url('https://preserve.me/image.jpg');
7
+ background: url('https://preserve.me/image.jpg');
8
+ }
9
+
10
+ .test-2 {
11
+ background-image: url("https://example.com/image.jpg");
12
+ background: url("https://example.com/image.jpg");
13
+ background-image: url("https://preserve.me/image.jpg");
14
+ background: url("https://preserve.me/image.jpg");
15
+ }
16
+
17
+ .test-3 {
18
+ background-image: url(https://example.com/image.jpg);
19
+ background: url(https://example.com/image.jpg);
20
+ background-image: url(https://preserve.me/image.jpg);
21
+ background: url(https://preserve.me/image.jpg);
22
+ }</style>
23
+ </head>
24
+
25
+ <body>
26
+ <img src="https://example.com/test.jpg">
27
+ <img src="https://example.com/test.jpg">
28
+
29
+ <img src="https://example.com/image1.jpg" srcset="https://example.com/image1-HD.jpg 2x, https://example.com/image1-phone.jpg 100w">
30
+
31
+ <img src="https://example.com/image2.jpg" srcset="https://example.com/image2-HD.jpg 2x, https://example.com/image2-phone.jpg 100w">
32
+
33
+ <picture>
34
+ <source media="(max-width: 799px)" srcset="https://example.com/elva-480w-close-portrait.jpg">
35
+ <source media="(min-width: 800px)" srcset="https://example.com/elva-800w.jpg">
36
+ <img src="https://example.com/elva-800w.jpg" alt="...">
37
+ </picture>
38
+
39
+ <video width="250" poster="https://example.com/flower.jpg">
40
+ <source src="https://example.com/media/flower.webm" type="video/webm">
41
+ <source src="https://example.tv/media/flower.mp4" type="video/mp4">
42
+ <track default="" kind="captions" srclang="en" src="https://example.com/media/tracks/friday.vtt">
43
+ </video>
44
+
45
+ <audio src="https://example.com/media/sample.mp3">
46
+ Fallback content
47
+ </audio>
48
+
49
+ <embed type="video/webm" src="https://example.com/media/flower.mp4" width="250" height="200">
50
+
51
+ <iframe width="300" height="200" src="https://example.com/embed.html"></iframe>
52
+
53
+ <input type="image" src="https://example.com/image.jpg" alt="">
54
+
55
+ <script src="https://example.com/javascript.js"></script>
56
+
57
+ <div>
58
+ <!--[if mso]>
59
+ <v:image xmlns:v="urn:schemas-microsoft-com:vml" src="https://example.com/image.jpg" style="600px;height:400px;" />
60
+ <v:rect fill="false" stroke="false" style="position:absolute;600px;height:400px;">
61
+ <v:textbox inset="0,0,0,0"><div><![endif]-->
62
+ <div>test</div>
63
+ <!--[if mso]></div></v:textbox></v:rect><![endif]-->
64
+ </div>
65
+
66
+ <table>
67
+ <tr>
68
+ <td background="https://example.com/image.png" bgcolor="#7bceeb" width="120" height="92" valign="top">
69
+ <!--[if gte mso 9]>
70
+ <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:120px;height:92px;">
71
+ <v:fill type="tile" src="https://example.com/image.png" color="#7bceeb" />
72
+ <v:textbox inset="0,0,0,0">
73
+ <![endif]-->
74
+ <div>test</div>
75
+ <!--[if gte mso 9]>
76
+ </v:textbox>
77
+ </v:rect>
78
+ <![endif]-->
79
+ </td>
80
+ </tr>
81
+ </table>
82
+ </body>
83
+ </html>
@@ -0,0 +1,19 @@
1
+ <style>.inline { display: inline !important
2
+ } .table { display: table !important
3
+ } .contents { display: contents !important
4
+ } .hidden { display: none !important
5
+ } .transform { transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)) !important
6
+ } div { width: 100%
7
+ } @media (min-width: 640px) { div { max-width: 640px
8
+ }
9
+ } @media (min-width: 768px) { div { max-width: 768px
10
+ }
11
+ } @media (min-width: 1024px) { div { max-width: 1024px
12
+ }
13
+ } @media (min-width: 1280px) { div { max-width: 1280px
14
+ }
15
+ } @media (min-width: 1536px) { div { max-width: 1536px
16
+ }
17
+ } div { display: none
18
+ }
19
+ </style>
@@ -0,0 +1,9 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>test></title>
5
+ </head>
6
+ <body>
7
+ <div>build_production</div>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>test></title>
5
+ </head>
6
+ <body>
7
+ <div>test</div>
8
+ </body>
9
+ </html>
@@ -1,7 +1,85 @@
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
+ <html>
2
+ <head>
3
+ <style>
4
+ .test {
5
+ background-image: url('image.jpg');
6
+ background: url('image.jpg');
7
+ background-image: url('https://preserve.me/image.jpg');
8
+ background: url('https://preserve.me/image.jpg');
9
+ }
10
+
11
+ .test-2 {
12
+ background-image: url("image.jpg");
13
+ background: url("image.jpg");
14
+ background-image: url("https://preserve.me/image.jpg");
15
+ background: url("https://preserve.me/image.jpg");
16
+ }
17
+
18
+ .test-3 {
19
+ background-image: url(image.jpg);
20
+ background: url(image.jpg);
21
+ background-image: url(https://preserve.me/image.jpg);
22
+ background: url(https://preserve.me/image.jpg);
23
+ }
24
+ </style>
25
+ </head>
26
+
27
+ <body>
28
+ <img src="test.jpg">
29
+ <img src="https://example.com/test.jpg">
30
+
31
+ <img src="image1.jpg" srcset="image1-HD.jpg 2x,image1-phone.jpg 100w">
32
+
33
+ <img src="https://example.com/image2.jpg" srcset="https://example.com/image2-HD.jpg 2x, https://example.com/image2-phone.jpg 100w">
34
+
35
+ <picture>
36
+ <source media="(max-width: 799px)" srcset="elva-480w-close-portrait.jpg">
37
+ <source media="(min-width: 800px)" srcset="elva-800w.jpg">
38
+ <img src="elva-800w.jpg" alt="...">
39
+ </picture>
40
+
41
+ <video width="250" poster="flower.jpg">
42
+ <source src="media/flower.webm" type="video/webm">
43
+ <source src="https://example.tv/media/flower.mp4" type="video/mp4">
44
+ <track default kind="captions" srclang="en" src="media/tracks/friday.vtt">
45
+ </video>
46
+
47
+ <audio src="media/sample.mp3">
48
+ Fallback content
49
+ </audio>
50
+
51
+ <embed type="video/webm" src="media/flower.mp4" width="250" height="200">
52
+
53
+ <iframe width="300" height="200" src="embed.html"></iframe>
54
+
55
+ <input type="image" src="image.jpg" alt="">
56
+
57
+ <script src="javascript.js"></script>
58
+
59
+ <div>
60
+ <!--[if mso]>
61
+ <v:image xmlns:v="urn:schemas-microsoft-com:vml" src="image.jpg" style="600px;height:400px;" />
62
+ <v:rect fill="false" stroke="false" style="position:absolute;600px;height:400px;">
63
+ <v:textbox inset="0,0,0,0"><div><![endif]-->
64
+ <div>test</div>
65
+ <!--[if mso]></div></v:textbox></v:rect><![endif]-->
66
+ </div>
67
+
68
+ <table>
69
+ <tr>
70
+ <td background="image.png" bgcolor="#7bceeb" width="120" height="92" valign="top">
71
+ <!--[if gte mso 9]>
72
+ <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:120px;height:92px;">
73
+ <v:fill type="tile" src="image.png" color="#7bceeb" />
74
+ <v:textbox inset="0,0,0,0">
75
+ <![endif]-->
76
+ <div>test</div>
77
+ <!--[if gte mso 9]>
78
+ </v:textbox>
79
+ </v:rect>
80
+ <![endif]-->
81
+ </td>
82
+ </tr>
83
+ </table>
84
+ </body>
85
+ </html>
@@ -0,0 +1,9 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>test></title>
5
+ </head>
6
+ <body>
7
+ <div>{{ page.build.templates.destination.path }}</div>
8
+ </body>
9
+ </html>
@@ -0,0 +1 @@
1
+ <div class="hidden"></div>
package/test/test-misc.js CHANGED
@@ -1,8 +1,8 @@
1
- const test = require('ava')
2
- const path = require('path')
3
- const {requireUncached} = require('../src/utils/helpers')
4
-
5
- test('requires an uncached module', t => {
6
- const helpers = requireUncached(path.resolve(process.cwd(), 'src/utils/helpers'))
7
- t.is(typeof helpers.requireUncached, 'function')
8
- })
1
+ const test = require('ava')
2
+ const path = require('path')
3
+ const {requireUncached} = require('../src/utils/helpers')
4
+
5
+ test('requires an uncached module', t => {
6
+ const helpers = requireUncached(path.resolve(process.cwd(), 'src/utils/helpers'))
7
+ t.is(typeof helpers.requireUncached, 'function')
8
+ })
@@ -1,73 +1,100 @@
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
- })
1
+ const test = require('ava')
2
+ const ora = require('ora')
3
+ const Tailwind = require('../src/generators/tailwindcss')
4
+
5
+ test('throws on compile error', async t => {
6
+ await t.throwsAsync(async () => {
7
+ const spinner = ora('Compiling Tailwind CSS...').start()
8
+ await Tailwind.compile('.test {@apply inexistent;}', '<div class="test">Test</a>', {}, {}, spinner)
9
+ }, {instanceOf: Error, message: 'Tailwind CSS compilation failed'})
10
+ })
11
+
12
+ test('uses Tailwind defaults if no config specified', async t => {
13
+ const css = await Tailwind.compile(
14
+ '@tailwind utilities;',
15
+ '<p class="xl:z-0"></p>',
16
+ {},
17
+ {env: 'production'}
18
+ )
19
+
20
+ t.not(css, undefined)
21
+ t.true(css.includes('.xl\\:z-0'))
22
+ })
23
+
24
+ test('uses CSS file provided in environment config', async t => {
25
+ const config = {
26
+ env: 'production',
27
+ build: {
28
+ tailwind: {
29
+ css: './test/stubs/main.css'
30
+ }
31
+ }
32
+ }
33
+
34
+ const css = await Tailwind.compile('', '<div class="text-center foo">test</div>', {}, config)
35
+
36
+ t.not(css, undefined)
37
+ t.true(css.includes('.text-center'))
38
+ t.true(css.includes('.foo'))
39
+ })
40
+
41
+ test('works with custom `content` sources', async t => {
42
+ const css = await Tailwind.compile(
43
+ '@tailwind utilities;',
44
+ '<div class="hidden"></div>',
45
+ {
46
+ content: ['./test/stubs/tailwind/*.*']
47
+ }
48
+ )
49
+
50
+ t.true(css.includes('.hidden'))
51
+ })
52
+
53
+ test('works with custom `files` sources', async t => {
54
+ const css = await Tailwind.compile(
55
+ '@tailwind utilities;',
56
+ '<div></div>',
57
+ {
58
+ content: {
59
+ files: ['./test/stubs/tailwind/*.*']
60
+ }
61
+ }
62
+ )
63
+
64
+ t.true(css.includes('.hidden'))
65
+ })
66
+
67
+ test('uses maizzle template paths when purging', async t => {
68
+ const css = await Tailwind.compile(
69
+ '@tailwind utilities;',
70
+ '<div></div>',
71
+ {},
72
+ {
73
+ build: {
74
+ templates: {
75
+ source: './test/stubs/tailwind'
76
+ }
77
+ }
78
+ }
79
+ )
80
+
81
+ t.true(css.includes('.hidden'))
82
+ })
83
+
84
+ test('uses custom postcss plugins from the maizzle config', async t => {
85
+ const maizzleConfig = {
86
+ env: 'production',
87
+ build: {
88
+ postcss: {
89
+ plugins: [
90
+ require('autoprefixer')({overrideBrowserslist: ['> 0.1%']})
91
+ ]
92
+ }
93
+ }
94
+ }
95
+
96
+ const css = await Tailwind.compile('.test {transform: scale(0.5)}', '<div class="test">Test</a>', {}, maizzleConfig)
97
+
98
+ t.not(css, undefined)
99
+ t.is(css.trim(), '.test {-webkit-transform: scale(0.5);transform: scale(0.5)}')
100
+ })