@maizzle/framework 4.0.0-alpha.2 → 4.0.0-alpha.5

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/src/index.js CHANGED
@@ -1,151 +1,13 @@
1
- const ora = require('ora')
2
- const path = require('path')
3
- const fs = require('fs-extra')
4
- const {get, merge} = require('lodash')
5
- const Config = require('./generators/config')
6
- const Output = require('./generators/output')
7
- const transformers = require('./transformers')
8
- const {clearConsole} = require('./utils/helpers')
9
- const Plaintext = require('./generators/plaintext')
10
-
11
- const getBrowserSync = () => {
12
- if (!global.cachedBrowserSync) {
13
- const bs = require('browser-sync')
14
- global.cachedBrowserSync = bs.create()
15
- }
16
-
17
- return global.cachedBrowserSync
18
- }
19
-
20
- const self = module.exports = { // eslint-disable-line
21
- ...transformers,
22
- render: async (html, options) => Output.toString(html, options),
23
- plaintext: async (html, config = {}) => Plaintext.generate(html, false, config),
24
- build: async (env = 'local', config = {}) => {
25
- const start = new Date()
26
- const spinner = ora('Building emails...').start()
27
-
28
- return Output.toDisk(env, spinner, config)
29
- .then(({files, parsed}) => {
30
- const elapsedSeconds = (Date.now() - start) / 1000
31
-
32
- if (get(config, 'build.command') === 'serve') {
33
- if (get(config, 'build.console.clear')) {
34
- clearConsole()
35
- }
36
-
37
- spinner.succeed(`Re-built ${parsed.length} templates in ${elapsedSeconds}s`)
38
- } else {
39
- spinner.succeed(`Built ${parsed.length} templates in ${elapsedSeconds}s`)
40
- }
41
-
42
- return {files}
43
- })
44
- .catch(error => {
45
- throw error
46
- })
47
- },
48
- serve: async (env = 'local', config = {}) => {
49
- config = merge(
50
- config,
51
- await Config.getMerged(env),
52
- {
53
- build: {
54
- command: 'serve'
55
- }
56
- }
57
- )
58
-
59
- await self
60
- .build(env, config)
61
- .then(async () => {
62
- let templates = get(config, 'build.templates')
63
- templates = Array.isArray(templates) ? templates : [templates]
64
-
65
- const templatePaths = [...new Set(templates.map(config => `${get(config, 'source', 'src')}/**`))]
66
- const globalPaths = [
67
- 'src/**',
68
- get(config, 'build.tailwind.config', 'tailwind.config.js'),
69
- [...new Set(get(config, 'build.browsersync.watch', []))]
70
- ]
71
-
72
- const spinner = ora()
73
-
74
- // Watch for Template file changes
75
- getBrowserSync().watch(templatePaths)
76
- .on('change', async file => {
77
- if (get(config, 'build.console.clear')) {
78
- clearConsole()
79
- }
80
-
81
- const start = new Date()
82
-
83
- spinner.start('Building email...')
84
-
85
- file = file.replace(/\\/g, '/')
86
-
87
- const destination = get(config, 'build.currentTemplates.destination.path', 'build_local')
88
- const extension = get(config, 'build.currentTemplates.destination.extension', 'html')
89
- const fileSource = get(config, 'build.currentTemplates.source')
90
- const parts = path.parse(path.join(destination, file.replace(fileSource, '')))
91
- const finalDestination = path.join(parts.dir, `${parts.name}.${extension}`)
92
-
93
- if (config.events && typeof config.events.beforeCreate === 'function') {
94
- await config.events.beforeCreate(config)
95
- }
96
-
97
- const renderOptions = {
98
- maizzle: config,
99
- ...config.events
100
- }
101
-
102
- self
103
- .render(await fs.readFile(file, 'utf8'), renderOptions)
104
- .then(({html, config}) => fs.outputFile(config.permalink || finalDestination, html))
105
- .then(() => {
106
- getBrowserSync().reload()
107
- spinner.succeed(`Compiled in ${(Date.now() - start) / 1000}s [${file}]`)
108
- })
109
- .catch(() => spinner.warn(`Received empty HTML, please save your file again [${file}]`))
110
- })
111
-
112
- // Watch for changes in all other files
113
- getBrowserSync().watch(globalPaths, {ignored: templatePaths})
114
- .on('change', () => self.build(env, config).then(() => getBrowserSync().reload()))
115
- .on('unlink', () => self.build(env, config).then(() => getBrowserSync().reload()))
116
-
117
- // Watch for changes in config files
118
- getBrowserSync().watch('config*.js')
119
- .on('change', async file => {
120
- const parsedEnv = path.parse(file).name.split('.')[1] || 'local'
121
-
122
- Config
123
- .getMerged(parsedEnv)
124
- .then(config => self.build(parsedEnv, config).then(() => getBrowserSync().reload()))
125
- })
126
-
127
- // Browsersync options
128
- const baseDir = templates.map(t => t.destination.path)
129
-
130
- const bsOptions = {
131
- notify: false,
132
- open: false,
133
- port: 3000,
134
- server: {
135
- baseDir,
136
- directory: true
137
- },
138
- tunnel: false,
139
- ui: {port: 3001},
140
- logFileChanges: false,
141
- ...get(config, 'build.browsersync', {})
142
- }
143
-
144
- // Initialize Browsersync
145
- getBrowserSync().init(bsOptions, () => {})
146
- })
147
- .catch(error => {
148
- throw error
149
- })
150
- }
151
- }
1
+ const serve = require('./commands/serve')
2
+ const toFile = require('./commands/build')
3
+ const transformers = require('./transformers')
4
+ const toString = require('./functions/render')
5
+ const toPlaintext = require('./functions/plaintext')
6
+
7
+ module.exports = {
8
+ serve,
9
+ build: toFile,
10
+ ...transformers,
11
+ render: toString,
12
+ plaintext: toPlaintext
13
+ }
@@ -15,8 +15,8 @@ module.exports = async (html, config = {}, direct = false) => {
15
15
 
16
16
  const compileCss = css => Tailwind.compile(css, html, tailwindConfig, maizzleConfig)
17
17
 
18
- replacements.tailwindcss = css => compileCss(`@tailwind components; @tailwind utilities; ${css}`)
19
- replacements.postcss = css => compileCss(`@tailwind components; @tailwind utilities; ${css}`)
18
+ replacements.tailwindcss = css => compileCss(css)
19
+ replacements.postcss = css => compileCss(css)
20
20
 
21
21
  return posthtml([posthtmlContent(replacements)]).process(html, posthtmlOptions).then(result => result.html)
22
22
  }
@@ -1,9 +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
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>test></title>
5
+ </head>
6
+ <body>
7
+ <div>test</div>
8
+ </body>
9
+ </html>
@@ -64,7 +64,7 @@ test('works with custom `files` sources', async t => {
64
64
  t.true(css.includes('.hidden'))
65
65
  })
66
66
 
67
- test('uses maizzle template paths when purging', async t => {
67
+ test('uses maizzle template path as content source', async t => {
68
68
  const css = await Tailwind.compile(
69
69
  '@tailwind utilities;',
70
70
  '<div></div>',
@@ -81,6 +81,23 @@ test('uses maizzle template paths when purging', async t => {
81
81
  t.true(css.includes('.hidden'))
82
82
  })
83
83
 
84
+ test('uses maizzle template path as content source (single file)', async t => {
85
+ const css = await Tailwind.compile(
86
+ '@tailwind utilities;',
87
+ '<div></div>',
88
+ {},
89
+ {
90
+ build: {
91
+ templates: {
92
+ source: './test/stubs/tailwind/preserve.html'
93
+ }
94
+ }
95
+ }
96
+ )
97
+
98
+ t.true(css.includes('.hidden'))
99
+ })
100
+
84
101
  test('uses custom postcss plugins from the maizzle config', async t => {
85
102
  const maizzleConfig = {
86
103
  env: 'production',
@@ -96,5 +113,5 @@ test('uses custom postcss plugins from the maizzle config', async t => {
96
113
  const css = await Tailwind.compile('.test {transform: scale(0.5)}', '<div class="test">Test</a>', {}, maizzleConfig)
97
114
 
98
115
  t.not(css, undefined)
99
- t.is(css.trim(), '.test {-webkit-transform: scale(0.5);transform: scale(0.5)}')
116
+ t.is(css.trim(), '.inline {display: inline !important} .table {display: table !important} .contents {display: contents !important} .transform {-webkit-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;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} .test {-webkit-transform: scale(0.5);transform: scale(0.5)}')
100
117
  })