@maizzle/framework 4.4.0-beta.6 → 4.4.0-beta.8
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/package.json
CHANGED
package/src/commands/serve.js
CHANGED
|
@@ -9,6 +9,10 @@ const renderToString = require('../functions/render')
|
|
|
9
9
|
const {get, merge, isObject} = require('lodash')
|
|
10
10
|
const {clearConsole} = require('../utils/helpers')
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Initialize Browsersync on-demand
|
|
14
|
+
* https://github.com/maizzle/framework/issues/605
|
|
15
|
+
*/
|
|
12
16
|
const browsersync = () => {
|
|
13
17
|
if (!global.cachedBrowserSync) {
|
|
14
18
|
const bs = require('browser-sync')
|
|
@@ -18,16 +22,17 @@ const browsersync = () => {
|
|
|
18
22
|
return global.cachedBrowserSync
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
const getConfig = async (env = 'local', config = {}) => merge(
|
|
26
|
+
config,
|
|
27
|
+
await Config.getMerged(env)
|
|
28
|
+
)
|
|
29
|
+
|
|
21
30
|
const serve = async (env = 'local', config = {}) => {
|
|
22
|
-
config = merge(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
build: {
|
|
27
|
-
command: 'serve'
|
|
28
|
-
}
|
|
31
|
+
config = await getConfig(env, merge(config, {
|
|
32
|
+
build: {
|
|
33
|
+
command: 'serve'
|
|
29
34
|
}
|
|
30
|
-
)
|
|
35
|
+
}))
|
|
31
36
|
|
|
32
37
|
const spinner = ora()
|
|
33
38
|
|
|
@@ -43,14 +48,17 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
43
48
|
'src/**',
|
|
44
49
|
...new Set(get(config, 'build.browsersync.watch', []))
|
|
45
50
|
]
|
|
51
|
+
|
|
46
52
|
if (typeof tailwindConfig === 'string') {
|
|
47
|
-
globalPaths.push(tailwindConfig)
|
|
53
|
+
globalPaths.push(tailwindConfig)
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
// Watch for Template file changes
|
|
51
57
|
browsersync()
|
|
52
58
|
.watch(templatePaths)
|
|
53
59
|
.on('change', async file => {
|
|
60
|
+
config = await getConfig(env, config)
|
|
61
|
+
|
|
54
62
|
if (config.events && typeof config.events.beforeCreate === 'function') {
|
|
55
63
|
await config.events.beforeCreate(config)
|
|
56
64
|
}
|
|
@@ -28,7 +28,7 @@ module.exports = async (env, spinner, config) => {
|
|
|
28
28
|
|
|
29
29
|
const css = (typeof get(config, 'build.tailwind.compiled') === 'string')
|
|
30
30
|
? config.build.tailwind.compiled
|
|
31
|
-
: await Tailwind.compile(
|
|
31
|
+
: await Tailwind.compile({config})
|
|
32
32
|
|
|
33
33
|
// Parse each template config object
|
|
34
34
|
await asyncForEach(templatesConfig, async templateConfig => {
|
|
@@ -209,12 +209,16 @@ module.exports = async (env, spinner, config) => {
|
|
|
209
209
|
if (Array.isArray(assets.source)) {
|
|
210
210
|
await asyncForEach(assets.source, async source => {
|
|
211
211
|
if (fs.existsSync(source)) {
|
|
212
|
-
await fs
|
|
212
|
+
await fs
|
|
213
|
+
.copy(source, path.join(templateConfig.destination.path, assets.destination))
|
|
214
|
+
.catch(error => spinner.warn(error.message))
|
|
213
215
|
}
|
|
214
216
|
})
|
|
215
217
|
} else {
|
|
216
218
|
if (fs.existsSync(assets.source)) {
|
|
217
|
-
await fs
|
|
219
|
+
await fs
|
|
220
|
+
.copy(assets.source, path.join(templateConfig.destination.path, assets.destination))
|
|
221
|
+
.catch(error => spinner.warn(error.message))
|
|
218
222
|
}
|
|
219
223
|
}
|
|
220
224
|
|
|
@@ -22,9 +22,6 @@ module.exports = async (html, options) => {
|
|
|
22
22
|
|
|
23
23
|
let config = merge(fileConfig, get(options, 'maizzle', {}))
|
|
24
24
|
|
|
25
|
-
const tailwindConfig = get(options, 'tailwind.config', {})
|
|
26
|
-
const cssString = get(options, 'tailwind.css', '')
|
|
27
|
-
|
|
28
25
|
const {frontmatter} = fm(html)
|
|
29
26
|
|
|
30
27
|
html = `---\n${frontmatter}\n---\n\n${fm(html).body}`
|
|
@@ -34,7 +31,17 @@ module.exports = async (html, options) => {
|
|
|
34
31
|
if (typeof get(options, 'tailwind.compiled') === 'string') {
|
|
35
32
|
config.css = options.tailwind.compiled
|
|
36
33
|
} else {
|
|
37
|
-
config.css = await Tailwind.compile(
|
|
34
|
+
config.css = await Tailwind.compile({
|
|
35
|
+
css: get(options, 'tailwind.css', ''),
|
|
36
|
+
html,
|
|
37
|
+
config: merge(config, {
|
|
38
|
+
build: {
|
|
39
|
+
tailwind: {
|
|
40
|
+
config: get(options, 'tailwind.config', {})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
})
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
if (options && typeof options.beforeRender === 'function') {
|
|
@@ -9,14 +9,14 @@ const mergeLonghand = require('postcss-merge-longhand')
|
|
|
9
9
|
const {get, isObject, isEmpty, merge} = require('lodash')
|
|
10
10
|
|
|
11
11
|
module.exports = {
|
|
12
|
-
compile: async (css = '', html = '',
|
|
13
|
-
tailwindConfig = (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) ? tailwindConfig : get(maizzleConfig, 'build.tailwind.config', 'tailwind.config.js')
|
|
14
|
-
|
|
12
|
+
compile: async ({css = '', html = '', config = {}}) => {
|
|
15
13
|
// Compute the Tailwind config to use
|
|
16
|
-
const userConfig =
|
|
14
|
+
const userConfig = config => {
|
|
15
|
+
const tailwindUserConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
|
|
16
|
+
|
|
17
17
|
// If a custom config object was passed, use that
|
|
18
|
-
if (isObject(
|
|
19
|
-
return
|
|
18
|
+
if (isObject(tailwindUserConfig) && !isEmpty(tailwindUserConfig)) {
|
|
19
|
+
return tailwindUserConfig
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -24,17 +24,17 @@ module.exports = {
|
|
|
24
24
|
* This will use the default Tailwind config (with rem units etc)
|
|
25
25
|
*/
|
|
26
26
|
try {
|
|
27
|
-
return requireUncached(path.resolve(process.cwd(),
|
|
27
|
+
return requireUncached(path.resolve(process.cwd(), tailwindUserConfig))
|
|
28
28
|
} catch {
|
|
29
29
|
return {}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Merge user's Tailwind config on top of a 'base' config
|
|
34
|
-
const layoutsRoot = get(
|
|
35
|
-
const componentsRoot = get(
|
|
34
|
+
const layoutsRoot = get(config, 'build.layouts.root')
|
|
35
|
+
const componentsRoot = get(config, 'build.components.root')
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const tailwindConfig = merge({
|
|
38
38
|
important: true,
|
|
39
39
|
content: {
|
|
40
40
|
files: [
|
|
@@ -47,20 +47,20 @@ module.exports = {
|
|
|
47
47
|
{raw: html, extension: 'html'}
|
|
48
48
|
]
|
|
49
49
|
}
|
|
50
|
-
}, userConfig())
|
|
50
|
+
}, userConfig(config))
|
|
51
51
|
|
|
52
52
|
// Add back the `{raw: html}` option if user provided own config
|
|
53
|
-
if (Array.isArray(
|
|
54
|
-
|
|
53
|
+
if (Array.isArray(tailwindConfig.content)) {
|
|
54
|
+
tailwindConfig.content = {
|
|
55
55
|
files: [
|
|
56
|
-
...
|
|
56
|
+
...tailwindConfig.content,
|
|
57
57
|
{raw: html, extension: 'html'}
|
|
58
58
|
]
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// Include all `build.templates.source` paths when scanning for selectors to preserve
|
|
63
|
-
const buildTemplates = get(
|
|
63
|
+
const buildTemplates = get(config, 'build.templates')
|
|
64
64
|
|
|
65
65
|
if (buildTemplates) {
|
|
66
66
|
const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
@@ -68,12 +68,12 @@ module.exports = {
|
|
|
68
68
|
const source = get(template, 'source')
|
|
69
69
|
|
|
70
70
|
if (typeof source === 'function') {
|
|
71
|
-
const sources = source(
|
|
71
|
+
const sources = source(config)
|
|
72
72
|
|
|
73
73
|
if (Array.isArray(sources)) {
|
|
74
|
-
sources.map(s =>
|
|
74
|
+
sources.map(s => tailwindConfig.content.files.push(s))
|
|
75
75
|
} else if (typeof sources === 'string') {
|
|
76
|
-
|
|
76
|
+
tailwindConfig.content.files.push(sources)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// Must return a valid `content` entry
|
|
@@ -82,7 +82,7 @@ module.exports = {
|
|
|
82
82
|
|
|
83
83
|
// Support single-file sources i.e. src/templates/index.html
|
|
84
84
|
if (typeof source === 'string' && Boolean(path.extname(source))) {
|
|
85
|
-
|
|
85
|
+
tailwindConfig.content.files.push(source)
|
|
86
86
|
|
|
87
87
|
return {raw: '', extension: 'html'}
|
|
88
88
|
}
|
|
@@ -90,23 +90,24 @@ module.exports = {
|
|
|
90
90
|
return `${source}/**/*.*`
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
tailwindConfig.content.files.push(...templateSources)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const userFilePath = get(
|
|
96
|
+
const userFilePath = get(config, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
97
97
|
const userFileExists = await fs.pathExists(userFilePath)
|
|
98
98
|
|
|
99
99
|
const toProcess = [
|
|
100
100
|
postcssNested(),
|
|
101
|
-
tailwindcss(
|
|
102
|
-
get(
|
|
101
|
+
tailwindcss(tailwindConfig),
|
|
102
|
+
get(config, 'shorthandCSS', get(config, 'shorthandInlineCSS')) === true ?
|
|
103
103
|
mergeLonghand() :
|
|
104
104
|
() => {},
|
|
105
|
-
...get(
|
|
105
|
+
...get(config, 'build.postcss.plugins', [])
|
|
106
106
|
]
|
|
107
107
|
|
|
108
108
|
if (userFileExists) {
|
|
109
109
|
css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
|
|
110
|
+
|
|
110
111
|
toProcess.unshift(
|
|
111
112
|
postcssImport({path: path.dirname(userFilePath)})
|
|
112
113
|
)
|
|
@@ -22,10 +22,19 @@ module.exports = async (html, config = {}, direct = false) => {
|
|
|
22
22
|
* Compile CSS in <style {post|tailwind}css> tags
|
|
23
23
|
*/
|
|
24
24
|
const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
|
|
25
|
-
const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
|
|
26
25
|
|
|
27
26
|
filters.postcss = css => PostCSS.process(css, maizzleConfig)
|
|
28
|
-
filters.tailwindcss = css => Tailwind.compile(
|
|
27
|
+
filters.tailwindcss = css => Tailwind.compile({
|
|
28
|
+
css,
|
|
29
|
+
html,
|
|
30
|
+
config: merge({
|
|
31
|
+
build: {
|
|
32
|
+
tailwind: {
|
|
33
|
+
config: get(config, 'build.tailwind.config', {})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, maizzleConfig)
|
|
37
|
+
})
|
|
29
38
|
|
|
30
39
|
const posthtmlPlugins = [
|
|
31
40
|
styleDataEmbed(),
|