@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
@@ -16,12 +16,12 @@ test.afterEach.always(async t => {
16
16
 
17
17
  test('throws if config cannot be computed', async t => {
18
18
  await t.throwsAsync(async () => {
19
- await Maizzle.build('production')
20
- }, {instanceOf: Error, message: `could not load config.production.js`})
19
+ await Maizzle.build('missing')
20
+ }, {instanceOf: Error, message: `could not load config.missing.js`})
21
21
  })
22
22
 
23
23
  test('skips if no templates found', async t => {
24
- const {files} = await Maizzle.build('production', {
24
+ const {files} = await Maizzle.build('maizzle-ci', {
25
25
  build: {
26
26
  fail: 'silent',
27
27
  templates: {
@@ -43,7 +43,7 @@ test('skips if no templates found', async t => {
43
43
  })
44
44
 
45
45
  test('outputs files at the correct location', async t => {
46
- const {files} = await Maizzle.build('production', {
46
+ const {files: string} = await Maizzle.build('maizzle-ci', {
47
47
  build: {
48
48
  fail: 'silent',
49
49
  templates: {
@@ -51,17 +51,25 @@ test('outputs files at the correct location', async t => {
51
51
  destination: {
52
52
  path: t.context.folder
53
53
  }
54
- },
55
- tailwind: {
56
- config: {
57
- purge: false
54
+ }
55
+ }
56
+ })
57
+
58
+ const {files: array} = await Maizzle.build('maizzle-ci', {
59
+ build: {
60
+ fail: 'silent',
61
+ templates: {
62
+ source: ['test/stubs/templates'],
63
+ destination: {
64
+ path: t.context.folder
58
65
  }
59
66
  }
60
67
  }
61
68
  })
62
69
 
63
70
  t.true(fs.pathExistsSync(t.context.folder))
64
- t.is(files.length, 3)
71
+ t.is(string.length, 3)
72
+ t.is(array.length, 3)
65
73
  })
66
74
 
67
75
  test('outputs files at the correct location if multiple template sources are used', async t => {
@@ -90,7 +98,7 @@ test('outputs files at the correct location if multiple template sources are use
90
98
  })
91
99
 
92
100
  test('copies all files in the `filetypes` option to destination', async t => {
93
- const {files} = await Maizzle.build('production', {
101
+ const {files} = await Maizzle.build('maizzle-ci', {
94
102
  build: {
95
103
  fail: 'silent',
96
104
  templates: {
@@ -113,7 +121,7 @@ test('copies all files in the `filetypes` option to destination', async t => {
113
121
  })
114
122
 
115
123
  test('outputs files with the correct extension', async t => {
116
- await Maizzle.build('production', {
124
+ await Maizzle.build('maizzle-ci', {
117
125
  build: {
118
126
  fail: 'silent',
119
127
  templates: {
@@ -135,22 +143,22 @@ test('outputs files with the correct extension', async t => {
135
143
  })
136
144
 
137
145
  test('outputs plaintext files', async t => {
138
- const {files} = await Maizzle.build('production', {
146
+ const {files} = await Maizzle.build('maizzle-ci', {
139
147
  fail: 'silent',
140
148
  build: {
141
149
  templates: {
142
150
  source: 'test/stubs/plaintext',
143
151
  destination: {
144
152
  path: t.context.folder
145
- }
153
+ },
154
+ plaintext: true
146
155
  },
147
156
  tailwind: {
148
157
  config: {
149
158
  purge: false
150
159
  }
151
160
  }
152
- },
153
- plaintext: true
161
+ }
154
162
  })
155
163
 
156
164
  const plaintext = files.filter(file => file.includes('.txt'))
@@ -164,13 +172,18 @@ test('outputs plaintext files', async t => {
164
172
  })
165
173
 
166
174
  test('outputs plaintext files (custom path)', async t => {
167
- const {files} = await Maizzle.build('production', {
175
+ const {files} = await Maizzle.build('maizzle-ci', {
168
176
  fail: 'silent',
169
177
  build: {
170
178
  templates: {
171
179
  source: 'test/stubs/plaintext',
172
180
  destination: {
173
181
  path: t.context.folder
182
+ },
183
+ plaintext: {
184
+ destination: {
185
+ path: `${t.context.folder}/nested/plain.text`
186
+ }
174
187
  }
175
188
  },
176
189
  tailwind: {
@@ -178,11 +191,6 @@ test('outputs plaintext files (custom path)', async t => {
178
191
  purge: false
179
192
  }
180
193
  }
181
- },
182
- plaintext: {
183
- destination: {
184
- path: `${t.context.folder}/nested/plain.text`
185
- }
186
194
  }
187
195
  })
188
196
 
@@ -199,7 +207,7 @@ test('renders plaintext string', async t => {
199
207
  })
200
208
 
201
209
  test('copies assets to destination', async t => {
202
- await Maizzle.build('production', {
210
+ await Maizzle.build('maizzle-ci', {
203
211
  build: {
204
212
  fail: 'silent',
205
213
  templates: {
@@ -225,7 +233,7 @@ test('copies assets to destination', async t => {
225
233
  })
226
234
 
227
235
  test('runs the `beforeCreate` event', async t => {
228
- await Maizzle.build('production', {
236
+ await Maizzle.build('maizzle-ci', {
229
237
  build: {
230
238
  fail: 'silent',
231
239
  templates: {
@@ -253,7 +261,7 @@ test('runs the `beforeCreate` event', async t => {
253
261
  })
254
262
 
255
263
  test('runs the `afterBuild` event', async t => {
256
- const {files} = await Maizzle.build('production', {
264
+ const {files} = await Maizzle.build('maizzle-ci', {
257
265
  build: {
258
266
  fail: 'silent',
259
267
  templates: {
@@ -281,7 +289,7 @@ test('runs the `afterBuild` event', async t => {
281
289
  })
282
290
 
283
291
  test('supports multiple asset paths', async t => {
284
- await Maizzle.build('production', {
292
+ await Maizzle.build('maizzle-ci', {
285
293
  build: {
286
294
  fail: 'silent',
287
295
  templates: {
@@ -308,7 +316,7 @@ test('supports multiple asset paths', async t => {
308
316
  })
309
317
 
310
318
  test('warns if a template cannot be rendered and `fail` option is undefined', async t => {
311
- const {files} = await Maizzle.build('production', {
319
+ const {files} = await Maizzle.build('maizzle-ci', {
312
320
  build: {
313
321
  templates: {
314
322
  source: 'test/stubs/breaking',
@@ -328,7 +336,7 @@ test('warns if a template cannot be rendered and `fail` option is undefined', as
328
336
  })
329
337
 
330
338
  test('warns if a template cannot be rendered and `fail` option is `verbose`', async t => {
331
- const {files} = await Maizzle.build('production', {
339
+ const {files} = await Maizzle.build('maizzle-ci', {
332
340
  build: {
333
341
  fail: 'verbose',
334
342
  templates: {
@@ -349,7 +357,7 @@ test('warns if a template cannot be rendered and `fail` option is `verbose`', as
349
357
  })
350
358
 
351
359
  test('warns if a template cannot be rendered and `fail` option is `silent`', async t => {
352
- const {files} = await Maizzle.build('production', {
360
+ const {files} = await Maizzle.build('maizzle-ci', {
353
361
  build: {
354
362
  fail: 'silent',
355
363
  templates: {
@@ -414,5 +422,74 @@ test('local server does not compile unwanted file types', async t => {
414
422
  test('throws if it cannot spin up local development server', async t => {
415
423
  await t.throwsAsync(async () => {
416
424
  await Maizzle.serve('local', {})
417
- }, {instanceOf: TypeError, message: `Cannot read property 'source' of undefined`})
425
+ }, {instanceOf: TypeError})
426
+ })
427
+
428
+ test('works with templates.source defined as function (string paths)', async t => {
429
+ const {files} = await Maizzle.build('maizzle-ci', {
430
+ build: {
431
+ fail: 'silent',
432
+ templates: {
433
+ source: () => 'test/stubs/templates',
434
+ destination: {
435
+ path: t.context.folder
436
+ }
437
+ }
438
+ }
439
+ })
440
+
441
+ t.true(fs.pathExistsSync(t.context.folder))
442
+ t.is(files.length, 3)
443
+ })
444
+
445
+ test('works with templates.source defined as function (array paths)', async t => {
446
+ const {files} = await Maizzle.build('maizzle-ci', {
447
+ build: {
448
+ fail: 'silent',
449
+ customSources: ['test/stubs/templates', 'test/stubs/templates'],
450
+ templates: {
451
+ source: config => {
452
+ return config.build.customSources
453
+ },
454
+ destination: {
455
+ path: t.context.folder
456
+ }
457
+ }
458
+ }
459
+ })
460
+
461
+ t.true(fs.pathExistsSync(t.context.folder))
462
+ t.is(files.length, 3)
463
+ })
464
+
465
+ test('throws if templates path is invalid', async t => {
466
+ await t.throwsAsync(async () => {
467
+ await Maizzle.build('maizzle-ci', {
468
+ build: {
469
+ fail: 'silent',
470
+ templates: {
471
+ source: false,
472
+ destination: {
473
+ path: t.context.folder
474
+ }
475
+ }
476
+ }
477
+ })
478
+ }, {instanceOf: TypeError})
479
+ })
480
+
481
+ test('throws if templates path is invalid (function)', async t => {
482
+ await t.throwsAsync(async () => {
483
+ await Maizzle.build('maizzle-ci', {
484
+ build: {
485
+ fail: 'silent',
486
+ templates: {
487
+ source: () => {},
488
+ destination: {
489
+ path: t.context.folder
490
+ }
491
+ }
492
+ }
493
+ })
494
+ }, {instanceOf: TypeError})
418
495
  })
@@ -10,10 +10,19 @@ 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)
16
+
17
+ t.is(html, source)
18
+ })
19
+
20
+ test('uses environment config file(s) if available', async t => {
21
+ const source = fixture('useConfig')
22
+
23
+ const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
15
24
 
16
- t.is(html, '<div>test</div>')
25
+ t.is(html, expected('useConfig'))
17
26
  })
18
27
 
19
28
  test('inheritance', async t => {