@maizzle/framework 4.0.0-alpha.9 → 4.0.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.
- package/.editorconfig +9 -9
- package/.github/media/logo-dark.svg +1 -0
- package/.github/media/logo-light.svg +1 -0
- package/.github/workflows/nodejs.yml +28 -28
- package/LICENSE +21 -21
- package/README.md +42 -35
- package/bin/maizzle +3 -3
- package/package.json +91 -91
- package/src/generators/config.js +32 -32
- package/src/generators/output/index.js +4 -4
- package/src/generators/output/to-disk.js +208 -208
- package/src/generators/output/to-string.js +1 -5
- package/src/generators/postcss.js +29 -29
- package/src/generators/posthtml.js +66 -66
- package/src/index.js +17 -17
- package/src/transformers/attributeToStyle.js +90 -90
- package/src/transformers/baseUrl.js +69 -69
- package/src/transformers/extraAttributes.js +26 -26
- package/src/transformers/filters/defaultFilters.js +126 -126
- package/src/transformers/filters/index.js +55 -55
- package/src/transformers/index.js +63 -60
- package/src/transformers/inlineCss.js +37 -50
- package/src/transformers/markdown.js +19 -19
- package/src/transformers/minify.js +21 -21
- package/src/transformers/plaintext.js +23 -23
- package/src/transformers/posthtmlMso.js +10 -10
- package/src/transformers/prettify.js +9 -11
- package/src/transformers/preventWidows.js +13 -13
- package/src/transformers/removeAttributes.js +17 -17
- package/src/transformers/removeInlineBackgroundColor.js +52 -52
- package/src/transformers/removeInlineSizes.js +41 -41
- package/src/transformers/replaceStrings.js +14 -14
- package/src/transformers/safeClassNames.js +24 -24
- package/src/transformers/shorthandInlineCSS.js +19 -0
- package/src/transformers/sixHex.js +33 -33
- package/src/transformers/urlParameters.js +17 -17
- package/src/utils/helpers.js +17 -17
- package/test/expected/posthtml/component.html +1 -1
- package/test/expected/posthtml/extend-template.html +2 -2
- package/test/expected/posthtml/fetch.html +5 -5
- package/test/expected/posthtml/layout.html +3 -3
- package/test/expected/transformers/atimport-in-style.html +12 -13
- package/test/expected/transformers/base-url.html +99 -99
- package/test/expected/transformers/preserve-transform-css.html +33 -45
- package/test/expected/useConfig.html +6 -6
- package/test/fixtures/posthtml/component.html +2 -2
- package/test/fixtures/posthtml/extend-template.html +7 -7
- package/test/fixtures/posthtml/fetch.html +9 -9
- package/test/fixtures/posthtml/layout.html +11 -11
- package/test/fixtures/transformers/base-url.html +101 -101
- package/test/stubs/assets/foo.bar +1 -1
- package/test/stubs/breaking/bad.html +5 -5
- package/test/stubs/config/config.js +10 -10
- package/test/stubs/config/config.maizzle-ci.js +10 -10
- package/test/stubs/data.json +14 -14
- package/test/stubs/events/before-create.html +1 -1
- package/test/stubs/layouts/basic.html +1 -1
- package/test/stubs/layouts/full.html +12 -12
- package/test/stubs/layouts/template.html +5 -5
- package/test/stubs/main.css +5 -5
- package/test/stubs/tailwind/content-source.html +1 -1
- package/test/stubs/tailwind/tailwind.css +3 -3
- package/test/stubs/template.html +10 -10
- package/test/test-config.js +19 -19
- package/test/test-postcss.js +8 -8
- package/test/test-posthtml.js +17 -11
- package/test/test-tailwindcss.js +117 -117
- package/test/test-todisk.js +1 -1
- package/test/test-transformers.js +511 -490
- package/xo.config.js +22 -22
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const fs = require('fs-extra')
|
|
3
|
-
const glob = require('glob-promise')
|
|
4
|
-
const {get, isEmpty, merge} = require('lodash')
|
|
5
|
-
const {asyncForEach} = require('../../utils/helpers')
|
|
6
|
-
const removePlaintextTags = require('../../transformers/plaintext')
|
|
7
|
-
|
|
8
|
-
const Config = require('../config')
|
|
9
|
-
const Tailwind = require('../tailwindcss')
|
|
10
|
-
const Plaintext = require('../plaintext')
|
|
11
|
-
|
|
12
|
-
const render = require('./to-string')
|
|
13
|
-
|
|
14
|
-
module.exports = async (env, spinner, config) => {
|
|
15
|
-
process.env.NODE_ENV = env || 'local'
|
|
16
|
-
|
|
17
|
-
if (isEmpty(config)) {
|
|
18
|
-
config = await Config.getMerged(env).catch(error => {
|
|
19
|
-
spinner.fail('Build failed')
|
|
20
|
-
throw error
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const buildTemplates = get(config, 'build.templates')
|
|
25
|
-
const templatesConfig = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
26
|
-
|
|
27
|
-
const parsed = []
|
|
28
|
-
let files = []
|
|
29
|
-
|
|
30
|
-
const css = (typeof get(config, 'tailwind.compiled') === 'string')
|
|
31
|
-
? config.tailwind.compiled
|
|
32
|
-
: await Tailwind.compile('', '', {}, config, spinner)
|
|
33
|
-
|
|
34
|
-
// Parse each template config object
|
|
35
|
-
await asyncForEach(templatesConfig, async templateConfig => {
|
|
36
|
-
const outputDir = get(templateConfig, 'destination.path', `build_${env}`)
|
|
37
|
-
|
|
38
|
-
await fs.remove(outputDir)
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get all files in the template config's source directory
|
|
42
|
-
* Supports `source` defined as:
|
|
43
|
-
* - string
|
|
44
|
-
* - array of strings
|
|
45
|
-
* - function that returns either of the above
|
|
46
|
-
*
|
|
47
|
-
* */
|
|
48
|
-
const templateSource = []
|
|
49
|
-
const templateTypeErrorMessage = 'Invalid template source: expected string or array of strings, got '
|
|
50
|
-
|
|
51
|
-
if (typeof templateConfig.source === 'function') {
|
|
52
|
-
const sources = templateConfig.source(config)
|
|
53
|
-
|
|
54
|
-
if (Array.isArray(sources)) {
|
|
55
|
-
templateSource.push(...sources)
|
|
56
|
-
} else if (typeof sources === 'string') {
|
|
57
|
-
templateSource.push(sources)
|
|
58
|
-
} else {
|
|
59
|
-
throw new TypeError(templateTypeErrorMessage + typeof sources)
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
if (Array.isArray(templateConfig.source)) {
|
|
63
|
-
templateSource.push(...templateConfig.source)
|
|
64
|
-
} else if (typeof templateConfig.source === 'string') {
|
|
65
|
-
templateSource.push(templateConfig.source)
|
|
66
|
-
} else {
|
|
67
|
-
throw new TypeError(templateTypeErrorMessage + typeof templateConfig.source)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Parse each template source
|
|
72
|
-
await asyncForEach(templateSource, async source => {
|
|
73
|
-
/**
|
|
74
|
-
* Copy single-file sources correctly
|
|
75
|
-
* If `src` is a file, `dest` cannot be a directory
|
|
76
|
-
* https://github.com/jprichardson/node-fs-extra/issues/323
|
|
77
|
-
*/
|
|
78
|
-
const out = fs.lstatSync(source).isFile() ? `${outputDir}/${path.basename(source)}` : outputDir
|
|
79
|
-
|
|
80
|
-
await fs
|
|
81
|
-
.copy(source, out)
|
|
82
|
-
.then(async () => {
|
|
83
|
-
const extensions = Array.isArray(templateConfig.filetypes)
|
|
84
|
-
? templateConfig.filetypes.join('|')
|
|
85
|
-
: templateConfig.filetypes || get(templateConfig, 'filetypes', 'html')
|
|
86
|
-
|
|
87
|
-
const templates = await glob(`${outputDir}/**/*.+(${extensions})`)
|
|
88
|
-
|
|
89
|
-
if (templates.length === 0) {
|
|
90
|
-
spinner.warn(`Error: no files with the .${extensions} extension found in ${templateConfig.source}`)
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (config.events && typeof config.events.beforeCreate === 'function') {
|
|
95
|
-
await config.events.beforeCreate(config)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
await asyncForEach(templates, async file => {
|
|
99
|
-
const html = await fs.readFile(file, 'utf8')
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const compiled = await render(html, {
|
|
103
|
-
maizzle: {
|
|
104
|
-
...config,
|
|
105
|
-
env
|
|
106
|
-
},
|
|
107
|
-
tailwind: {
|
|
108
|
-
compiled: css
|
|
109
|
-
},
|
|
110
|
-
...config.events
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
const destination = config.permalink || file
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Generate plaintext
|
|
117
|
-
*
|
|
118
|
-
* We do this first so that we can remove the <plaintext>
|
|
119
|
-
* tags from the markup before outputting the file.
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
const plaintextConfig = get(templateConfig, 'plaintext')
|
|
123
|
-
const plaintextPath = get(plaintextConfig, 'destination.path', config.permalink || file)
|
|
124
|
-
|
|
125
|
-
if (Boolean(plaintextConfig) || !isEmpty(plaintextConfig)) {
|
|
126
|
-
await Plaintext
|
|
127
|
-
.generate(
|
|
128
|
-
compiled.html,
|
|
129
|
-
plaintextPath,
|
|
130
|
-
merge(plaintextConfig, {filepath: file})
|
|
131
|
-
)
|
|
132
|
-
.then(({plaintext, destination}) => fs.outputFile(destination, plaintext))
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
compiled.html = removePlaintextTags(compiled.html, config)
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Output file
|
|
139
|
-
*/
|
|
140
|
-
const parts = path.parse(destination)
|
|
141
|
-
const extension = get(templateConfig, 'destination.extension', 'html')
|
|
142
|
-
const finalDestination = `${parts.dir}/${parts.name}.${extension}`
|
|
143
|
-
|
|
144
|
-
await fs.outputFile(finalDestination, compiled.html)
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Remove original file if its path is different
|
|
148
|
-
* from the final destination path.
|
|
149
|
-
*
|
|
150
|
-
* This ensures non-HTML files do not pollute
|
|
151
|
-
* the build destination folder.
|
|
152
|
-
*/
|
|
153
|
-
if (finalDestination !== file) {
|
|
154
|
-
await fs.remove(file)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Keep track of handled files
|
|
158
|
-
files.push(file)
|
|
159
|
-
parsed.push(file)
|
|
160
|
-
} catch (error) {
|
|
161
|
-
switch (config.build.fail) {
|
|
162
|
-
case 'silent':
|
|
163
|
-
spinner.warn(`Failed to compile template: ${path.basename(file)}`)
|
|
164
|
-
break
|
|
165
|
-
case 'verbose':
|
|
166
|
-
spinner.warn(`Failed to compile template: ${path.basename(file)}`)
|
|
167
|
-
console.error(error)
|
|
168
|
-
break
|
|
169
|
-
default:
|
|
170
|
-
spinner.fail(`Failed to compile template: ${path.basename(file)}`)
|
|
171
|
-
throw error
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
const assets = {source: '', destination: 'assets', ...get(templateConfig, 'assets')}
|
|
177
|
-
|
|
178
|
-
if (Array.isArray(assets.source)) {
|
|
179
|
-
await asyncForEach(assets.source, async source => {
|
|
180
|
-
if (fs.existsSync(source)) {
|
|
181
|
-
await fs.copy(source, path.join(templateConfig.destination.path, assets.destination)).catch(error => spinner.warn(error.message))
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
} else {
|
|
185
|
-
if (fs.existsSync(assets.source)) {
|
|
186
|
-
await fs.copy(assets.source, path.join(templateConfig.destination.path, assets.destination)).catch(error => spinner.warn(error.message))
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
await glob(path.join(templateConfig.destination.path, '/**/*.*'))
|
|
191
|
-
.then(contents => {
|
|
192
|
-
files = [...new Set([...files, ...contents])]
|
|
193
|
-
})
|
|
194
|
-
})
|
|
195
|
-
.catch(error => spinner.warn(error.message))
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
if (config.events && typeof config.events.afterBuild === 'function') {
|
|
200
|
-
await config.events.afterBuild(files)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
files,
|
|
205
|
-
parsed,
|
|
206
|
-
css
|
|
207
|
-
}
|
|
208
|
-
}
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const fs = require('fs-extra')
|
|
3
|
+
const glob = require('glob-promise')
|
|
4
|
+
const {get, isEmpty, merge} = require('lodash')
|
|
5
|
+
const {asyncForEach} = require('../../utils/helpers')
|
|
6
|
+
const removePlaintextTags = require('../../transformers/plaintext')
|
|
7
|
+
|
|
8
|
+
const Config = require('../config')
|
|
9
|
+
const Tailwind = require('../tailwindcss')
|
|
10
|
+
const Plaintext = require('../plaintext')
|
|
11
|
+
|
|
12
|
+
const render = require('./to-string')
|
|
13
|
+
|
|
14
|
+
module.exports = async (env, spinner, config) => {
|
|
15
|
+
process.env.NODE_ENV = env || 'local'
|
|
16
|
+
|
|
17
|
+
if (isEmpty(config)) {
|
|
18
|
+
config = await Config.getMerged(env).catch(error => {
|
|
19
|
+
spinner.fail('Build failed')
|
|
20
|
+
throw error
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const buildTemplates = get(config, 'build.templates')
|
|
25
|
+
const templatesConfig = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
26
|
+
|
|
27
|
+
const parsed = []
|
|
28
|
+
let files = []
|
|
29
|
+
|
|
30
|
+
const css = (typeof get(config, 'tailwind.compiled') === 'string')
|
|
31
|
+
? config.tailwind.compiled
|
|
32
|
+
: await Tailwind.compile('', '', {}, config, spinner)
|
|
33
|
+
|
|
34
|
+
// Parse each template config object
|
|
35
|
+
await asyncForEach(templatesConfig, async templateConfig => {
|
|
36
|
+
const outputDir = get(templateConfig, 'destination.path', `build_${env}`)
|
|
37
|
+
|
|
38
|
+
await fs.remove(outputDir)
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get all files in the template config's source directory
|
|
42
|
+
* Supports `source` defined as:
|
|
43
|
+
* - string
|
|
44
|
+
* - array of strings
|
|
45
|
+
* - function that returns either of the above
|
|
46
|
+
*
|
|
47
|
+
* */
|
|
48
|
+
const templateSource = []
|
|
49
|
+
const templateTypeErrorMessage = 'Invalid template source: expected string or array of strings, got '
|
|
50
|
+
|
|
51
|
+
if (typeof templateConfig.source === 'function') {
|
|
52
|
+
const sources = templateConfig.source(config)
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(sources)) {
|
|
55
|
+
templateSource.push(...sources)
|
|
56
|
+
} else if (typeof sources === 'string') {
|
|
57
|
+
templateSource.push(sources)
|
|
58
|
+
} else {
|
|
59
|
+
throw new TypeError(templateTypeErrorMessage + typeof sources)
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
if (Array.isArray(templateConfig.source)) {
|
|
63
|
+
templateSource.push(...templateConfig.source)
|
|
64
|
+
} else if (typeof templateConfig.source === 'string') {
|
|
65
|
+
templateSource.push(templateConfig.source)
|
|
66
|
+
} else {
|
|
67
|
+
throw new TypeError(templateTypeErrorMessage + typeof templateConfig.source)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Parse each template source
|
|
72
|
+
await asyncForEach(templateSource, async source => {
|
|
73
|
+
/**
|
|
74
|
+
* Copy single-file sources correctly
|
|
75
|
+
* If `src` is a file, `dest` cannot be a directory
|
|
76
|
+
* https://github.com/jprichardson/node-fs-extra/issues/323
|
|
77
|
+
*/
|
|
78
|
+
const out = fs.lstatSync(source).isFile() ? `${outputDir}/${path.basename(source)}` : outputDir
|
|
79
|
+
|
|
80
|
+
await fs
|
|
81
|
+
.copy(source, out)
|
|
82
|
+
.then(async () => {
|
|
83
|
+
const extensions = Array.isArray(templateConfig.filetypes)
|
|
84
|
+
? templateConfig.filetypes.join('|')
|
|
85
|
+
: templateConfig.filetypes || get(templateConfig, 'filetypes', 'html')
|
|
86
|
+
|
|
87
|
+
const templates = await glob(`${outputDir}/**/*.+(${extensions})`)
|
|
88
|
+
|
|
89
|
+
if (templates.length === 0) {
|
|
90
|
+
spinner.warn(`Error: no files with the .${extensions} extension found in ${templateConfig.source}`)
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (config.events && typeof config.events.beforeCreate === 'function') {
|
|
95
|
+
await config.events.beforeCreate(config)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await asyncForEach(templates, async file => {
|
|
99
|
+
const html = await fs.readFile(file, 'utf8')
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const compiled = await render(html, {
|
|
103
|
+
maizzle: {
|
|
104
|
+
...config,
|
|
105
|
+
env
|
|
106
|
+
},
|
|
107
|
+
tailwind: {
|
|
108
|
+
compiled: css
|
|
109
|
+
},
|
|
110
|
+
...config.events
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const destination = config.permalink || file
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Generate plaintext
|
|
117
|
+
*
|
|
118
|
+
* We do this first so that we can remove the <plaintext>
|
|
119
|
+
* tags from the markup before outputting the file.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
const plaintextConfig = get(templateConfig, 'plaintext')
|
|
123
|
+
const plaintextPath = get(plaintextConfig, 'destination.path', config.permalink || file)
|
|
124
|
+
|
|
125
|
+
if (Boolean(plaintextConfig) || !isEmpty(plaintextConfig)) {
|
|
126
|
+
await Plaintext
|
|
127
|
+
.generate(
|
|
128
|
+
compiled.html,
|
|
129
|
+
plaintextPath,
|
|
130
|
+
merge(plaintextConfig, {filepath: file})
|
|
131
|
+
)
|
|
132
|
+
.then(({plaintext, destination}) => fs.outputFile(destination, plaintext))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
compiled.html = removePlaintextTags(compiled.html, config)
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Output file
|
|
139
|
+
*/
|
|
140
|
+
const parts = path.parse(destination)
|
|
141
|
+
const extension = get(templateConfig, 'destination.extension', 'html')
|
|
142
|
+
const finalDestination = `${parts.dir}/${parts.name}.${extension}`
|
|
143
|
+
|
|
144
|
+
await fs.outputFile(finalDestination, compiled.html)
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Remove original file if its path is different
|
|
148
|
+
* from the final destination path.
|
|
149
|
+
*
|
|
150
|
+
* This ensures non-HTML files do not pollute
|
|
151
|
+
* the build destination folder.
|
|
152
|
+
*/
|
|
153
|
+
if (finalDestination !== file) {
|
|
154
|
+
await fs.remove(file)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Keep track of handled files
|
|
158
|
+
files.push(file)
|
|
159
|
+
parsed.push(file)
|
|
160
|
+
} catch (error) {
|
|
161
|
+
switch (config.build.fail) {
|
|
162
|
+
case 'silent':
|
|
163
|
+
spinner.warn(`Failed to compile template: ${path.basename(file)}`)
|
|
164
|
+
break
|
|
165
|
+
case 'verbose':
|
|
166
|
+
spinner.warn(`Failed to compile template: ${path.basename(file)}`)
|
|
167
|
+
console.error(error)
|
|
168
|
+
break
|
|
169
|
+
default:
|
|
170
|
+
spinner.fail(`Failed to compile template: ${path.basename(file)}`)
|
|
171
|
+
throw error
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
const assets = {source: '', destination: 'assets', ...get(templateConfig, 'assets')}
|
|
177
|
+
|
|
178
|
+
if (Array.isArray(assets.source)) {
|
|
179
|
+
await asyncForEach(assets.source, async source => {
|
|
180
|
+
if (fs.existsSync(source)) {
|
|
181
|
+
await fs.copy(source, path.join(templateConfig.destination.path, assets.destination)).catch(error => spinner.warn(error.message))
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
} else {
|
|
185
|
+
if (fs.existsSync(assets.source)) {
|
|
186
|
+
await fs.copy(assets.source, path.join(templateConfig.destination.path, assets.destination)).catch(error => spinner.warn(error.message))
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
await glob(path.join(templateConfig.destination.path, '/**/*.*'))
|
|
191
|
+
.then(contents => {
|
|
192
|
+
files = [...new Set([...files, ...contents])]
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
.catch(error => spinner.warn(error.message))
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
if (config.events && typeof config.events.afterBuild === 'function') {
|
|
200
|
+
await config.events.afterBuild(files)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
files,
|
|
205
|
+
parsed,
|
|
206
|
+
css
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -24,11 +24,7 @@ module.exports = async (html, options) => {
|
|
|
24
24
|
const tailwindConfig = get(options, 'tailwind.config', {})
|
|
25
25
|
const cssString = get(options, 'tailwind.css', '')
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (frontmatter) {
|
|
30
|
-
frontmatter = await posthtml(frontmatter, config)
|
|
31
|
-
}
|
|
27
|
+
const {frontmatter} = fm(html)
|
|
32
28
|
|
|
33
29
|
html = `---\n${frontmatter}\n---\n\n${fm(html).body}`
|
|
34
30
|
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const {get} = require('lodash')
|
|
3
|
-
const postcss = require('postcss')
|
|
4
|
-
const postcssImport = require('postcss-import')
|
|
5
|
-
const postcssNested = require('tailwindcss/nesting')
|
|
6
|
-
const mergeLonghand = require('postcss-merge-longhand')
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
process: async (css = '', maizzleConfig = {}, spinner = null) => {
|
|
10
|
-
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
11
|
-
|
|
12
|
-
return postcss([
|
|
13
|
-
postcssImport({path: path.dirname(userFilePath)}),
|
|
14
|
-
postcssNested(),
|
|
15
|
-
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
16
|
-
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
17
|
-
])
|
|
18
|
-
.process(css, {from: undefined})
|
|
19
|
-
.then(result => result.css)
|
|
20
|
-
.catch(error => {
|
|
21
|
-
console.error(error)
|
|
22
|
-
if (spinner) {
|
|
23
|
-
spinner.stop()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
throw new Error(`PostCSS processing failed`)
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const {get} = require('lodash')
|
|
3
|
+
const postcss = require('postcss')
|
|
4
|
+
const postcssImport = require('postcss-import')
|
|
5
|
+
const postcssNested = require('tailwindcss/nesting')
|
|
6
|
+
const mergeLonghand = require('postcss-merge-longhand')
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
process: async (css = '', maizzleConfig = {}, spinner = null) => {
|
|
10
|
+
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
11
|
+
|
|
12
|
+
return postcss([
|
|
13
|
+
postcssImport({path: path.dirname(userFilePath)}),
|
|
14
|
+
postcssNested(),
|
|
15
|
+
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
16
|
+
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
17
|
+
])
|
|
18
|
+
.process(css, {from: undefined})
|
|
19
|
+
.then(result => result.css)
|
|
20
|
+
.catch(error => {
|
|
21
|
+
console.error(error)
|
|
22
|
+
if (spinner) {
|
|
23
|
+
spinner.stop()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw new Error(`PostCSS processing failed`)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
const fm = require('front-matter')
|
|
2
|
-
const posthtml = require('posthtml')
|
|
3
|
-
const {get, merge} = require('lodash')
|
|
4
|
-
const fetch = require('posthtml-fetch')
|
|
5
|
-
const layouts = require('posthtml-extend')
|
|
6
|
-
const modules = require('posthtml-modules')
|
|
7
|
-
const expressions = require('posthtml-expressions')
|
|
8
|
-
|
|
9
|
-
module.exports = async (html, config) => {
|
|
10
|
-
const layoutsOptions = get(config, 'build.layouts', {})
|
|
11
|
-
|
|
12
|
-
const modulesOptions = get(config, 'build.components', {})
|
|
13
|
-
// Fake `from` option so we can reference modules relatively
|
|
14
|
-
const modulesRoot = modulesOptions.root || './'
|
|
15
|
-
const modulesFrom = modulesOptions.from || `${modulesRoot}/fake`
|
|
16
|
-
|
|
17
|
-
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
18
|
-
const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
|
|
19
|
-
|
|
20
|
-
const expressionsOptions = merge({strictMode: false}, get(config, 'build.posthtml.expressions', {}))
|
|
21
|
-
|
|
22
|
-
const locals = merge(
|
|
23
|
-
get(expressionsOptions, 'locals', {}),
|
|
24
|
-
get(config, 'locals', {}),
|
|
25
|
-
{page: config}
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
const fetchPlugin = fetch(
|
|
29
|
-
merge(
|
|
30
|
-
{
|
|
31
|
-
expressions: merge({...expressionsOptions, locals})
|
|
32
|
-
},
|
|
33
|
-
get(config, 'build.posthtml.fetch', {})
|
|
34
|
-
)
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return posthtml([
|
|
38
|
-
fetchPlugin,
|
|
39
|
-
expressions({...expressionsOptions, locals}),
|
|
40
|
-
layouts(
|
|
41
|
-
merge(
|
|
42
|
-
{
|
|
43
|
-
strict: false,
|
|
44
|
-
expressions: merge({...expressionsOptions, locals})
|
|
45
|
-
},
|
|
46
|
-
layoutsOptions
|
|
47
|
-
)
|
|
48
|
-
),
|
|
49
|
-
modules({
|
|
50
|
-
parser: posthtmlOptions,
|
|
51
|
-
attributeAsLocals: true,
|
|
52
|
-
from: modulesFrom,
|
|
53
|
-
root: modulesRoot,
|
|
54
|
-
tag: 'component',
|
|
55
|
-
attribute: 'src',
|
|
56
|
-
plugins: [
|
|
57
|
-
fetchPlugin
|
|
58
|
-
],
|
|
59
|
-
locals,
|
|
60
|
-
...modulesOptions
|
|
61
|
-
}),
|
|
62
|
-
...posthtmlPlugins
|
|
63
|
-
])
|
|
64
|
-
.process(html, {...posthtmlOptions})
|
|
65
|
-
.then(result => fm(result.html).body)
|
|
66
|
-
}
|
|
1
|
+
const fm = require('front-matter')
|
|
2
|
+
const posthtml = require('posthtml')
|
|
3
|
+
const {get, merge} = require('lodash')
|
|
4
|
+
const fetch = require('posthtml-fetch')
|
|
5
|
+
const layouts = require('posthtml-extend')
|
|
6
|
+
const modules = require('posthtml-modules')
|
|
7
|
+
const expressions = require('posthtml-expressions')
|
|
8
|
+
|
|
9
|
+
module.exports = async (html, config) => {
|
|
10
|
+
const layoutsOptions = get(config, 'build.layouts', {})
|
|
11
|
+
|
|
12
|
+
const modulesOptions = get(config, 'build.components', {})
|
|
13
|
+
// Fake `from` option so we can reference modules relatively
|
|
14
|
+
const modulesRoot = modulesOptions.root || './'
|
|
15
|
+
const modulesFrom = modulesOptions.from || `${modulesRoot}/fake`
|
|
16
|
+
|
|
17
|
+
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
18
|
+
const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
|
|
19
|
+
|
|
20
|
+
const expressionsOptions = merge({strictMode: false}, get(config, 'build.posthtml.expressions', {}))
|
|
21
|
+
|
|
22
|
+
const locals = merge(
|
|
23
|
+
get(expressionsOptions, 'locals', {}),
|
|
24
|
+
get(config, 'locals', {}),
|
|
25
|
+
{page: config}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const fetchPlugin = fetch(
|
|
29
|
+
merge(
|
|
30
|
+
{
|
|
31
|
+
expressions: merge({...expressionsOptions, locals})
|
|
32
|
+
},
|
|
33
|
+
get(config, 'build.posthtml.fetch', {})
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return posthtml([
|
|
38
|
+
fetchPlugin,
|
|
39
|
+
expressions({...expressionsOptions, locals}),
|
|
40
|
+
layouts(
|
|
41
|
+
merge(
|
|
42
|
+
{
|
|
43
|
+
strict: false,
|
|
44
|
+
expressions: merge({...expressionsOptions, locals})
|
|
45
|
+
},
|
|
46
|
+
layoutsOptions
|
|
47
|
+
)
|
|
48
|
+
),
|
|
49
|
+
modules({
|
|
50
|
+
parser: posthtmlOptions,
|
|
51
|
+
attributeAsLocals: true,
|
|
52
|
+
from: modulesFrom,
|
|
53
|
+
root: modulesRoot,
|
|
54
|
+
tag: 'component',
|
|
55
|
+
attribute: 'src',
|
|
56
|
+
plugins: [
|
|
57
|
+
fetchPlugin
|
|
58
|
+
],
|
|
59
|
+
locals,
|
|
60
|
+
...modulesOptions
|
|
61
|
+
}),
|
|
62
|
+
...posthtmlPlugins
|
|
63
|
+
])
|
|
64
|
+
.process(html, {...posthtmlOptions})
|
|
65
|
+
.then(result => fm(result.html).body)
|
|
66
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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 PostCSS = require('./generators/postcss')
|
|
6
|
-
const toPlaintext = require('./functions/plaintext')
|
|
7
|
-
const TailwindCSS = require('./generators/tailwindcss')
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
serve,
|
|
11
|
-
build: toFile,
|
|
12
|
-
...transformers,
|
|
13
|
-
render: toString,
|
|
14
|
-
postcss: PostCSS,
|
|
15
|
-
plaintext: toPlaintext,
|
|
16
|
-
tailwindcss: TailwindCSS
|
|
17
|
-
}
|
|
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 PostCSS = require('./generators/postcss')
|
|
6
|
+
const toPlaintext = require('./functions/plaintext')
|
|
7
|
+
const TailwindCSS = require('./generators/tailwindcss')
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
serve,
|
|
11
|
+
build: toFile,
|
|
12
|
+
...transformers,
|
|
13
|
+
render: toString,
|
|
14
|
+
postcss: PostCSS,
|
|
15
|
+
plaintext: toPlaintext,
|
|
16
|
+
tailwindcss: TailwindCSS
|
|
17
|
+
}
|