@maizzle/framework 3.6.2 → 3.7.3

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.
@@ -1,84 +1,84 @@
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 = {}) => {
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
- purge: {
37
- enabled: maizzleConfig.env !== 'local',
38
- content: [
39
- 'src/**/*.*',
40
- {raw: html}
41
- ],
42
- options: get(maizzleConfig, 'purgeCSS', {})
43
- },
44
- corePlugins: {
45
- animation: false,
46
- backgroundOpacity: false,
47
- borderOpacity: false,
48
- boxShadow: false,
49
- divideOpacity: false,
50
- placeholderOpacity: false,
51
- ringColor: false,
52
- ringWidth: false,
53
- ringOpacity: false,
54
- ringOffsetColor: false,
55
- textOpacity: false
56
- },
57
- plugins: []
58
- }, userConfig())
59
-
60
- // Merge user's Tailwind plugins with our default ones
61
- config.plugins.push(require('tailwindcss-box-shadow'))
62
-
63
- const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
64
-
65
- css = await fs.pathExists(userFilePath).then(async exists => {
66
- if (exists) {
67
- const userFileCSS = await fs.readFile(path.resolve(userFilePath), 'utf8')
68
- return userFileCSS
69
- }
70
-
71
- return css
72
- })
73
-
74
- return postcss([
75
- postcssImport({path: userFilePath ? path.dirname(userFilePath) : []}),
76
- postcssNested(),
77
- tailwindcss(config),
78
- maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
79
- ...get(maizzleConfig, 'build.postcss.plugins', [])
80
- ])
81
- .process(css, {from: undefined})
82
- .then(result => result.css)
83
- }
84
- }
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 = {}) => {
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
+ purge: {
37
+ enabled: maizzleConfig.env !== 'local',
38
+ content: [
39
+ 'src/**/*.*',
40
+ {raw: html}
41
+ ],
42
+ options: get(maizzleConfig, 'purgeCSS', {})
43
+ },
44
+ corePlugins: {
45
+ animation: false,
46
+ backgroundOpacity: false,
47
+ borderOpacity: false,
48
+ boxShadow: false,
49
+ divideOpacity: false,
50
+ placeholderOpacity: false,
51
+ ringColor: false,
52
+ ringWidth: false,
53
+ ringOpacity: false,
54
+ ringOffsetColor: false,
55
+ textOpacity: false
56
+ },
57
+ plugins: []
58
+ }, userConfig())
59
+
60
+ // Merge user's Tailwind plugins with our default ones
61
+ config.plugins.push(require('tailwindcss-box-shadow'))
62
+
63
+ const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
64
+
65
+ css = await fs.pathExists(userFilePath).then(async exists => {
66
+ if (exists) {
67
+ const userFileCSS = await fs.readFile(path.resolve(userFilePath), 'utf8')
68
+ return userFileCSS + css
69
+ }
70
+
71
+ return css
72
+ })
73
+
74
+ return postcss([
75
+ postcssImport({path: userFilePath ? path.dirname(userFilePath) : []}),
76
+ postcssNested(),
77
+ tailwindcss(config),
78
+ maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
79
+ ...get(maizzleConfig, 'build.postcss.plugins', [])
80
+ ])
81
+ .process(css, {from: undefined})
82
+ .then(result => result.css)
83
+ }
84
+ }
@@ -2,8 +2,7 @@ module.exports = async (html, config = {}, direct = false) => {
2
2
  const url = direct ? config : config.baseImageURL
3
3
 
4
4
  if (url) {
5
- return html.replace(/(background="|src=")(?!\s+|url\('?'?\)|"|https?:\/\/)\/?/gi, '$1' + url)
6
- .replace(/(background(-image)?:\s?url\('?)(?![')]|https?:\/\/)\/?/gi, '$1' + url)
5
+ return html.replace(/([^"'=\s(]+\.(?:jpe?g|a?png|avif|gif|svg|webp|jfif|pjpeg|pjp))/gi, url + '$1')
7
6
  }
8
7
 
9
8
  return html
@@ -1,10 +1,10 @@
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
+ 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
+ }
@@ -0,0 +1,7 @@
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>
@@ -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>
@@ -0,0 +1,7 @@
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>
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,73 @@
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 transform: scale(0.5)\n}\n\n/* purgecss end ignore */')
73
- })
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
+ })
@@ -414,5 +414,5 @@ test('local server does not compile unwanted file types', async t => {
414
414
  test('throws if it cannot spin up local development server', async t => {
415
415
  await t.throwsAsync(async () => {
416
416
  await Maizzle.serve('local', {})
417
- }, {instanceOf: TypeError, message: `Cannot read property 'source' of undefined`})
417
+ }, {instanceOf: TypeError})
418
418
  })
@@ -10,10 +10,11 @@ const expected = file => readFileSync(path.join(__dirname, 'expected', `${file}.
10
10
  const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)
11
11
 
12
12
  test('compiles HTML string if no options are passed', async t => {
13
- let html = await renderString('<div>test</div>')
14
- html = html.replace(/[^\S\r\n]+$/gm, '').trim()
13
+ const source = fixture('basic')
14
+
15
+ const html = await renderString(source)
15
16
 
16
- t.is(html, '<div>test</div>')
17
+ t.is(html, source)
17
18
  })
18
19
 
19
20
  test('inheritance', async t => {