@maizzle/framework 4.0.0-alpha.5 → 4.0.0-alpha.6
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 +1 -1
- package/src/generators/tailwindcss.js +116 -116
package/package.json
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
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 = {}, spinner = null) => {
|
|
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
|
-
content: {
|
|
37
|
-
files: [
|
|
38
|
-
'./src/**/*.*',
|
|
39
|
-
{raw: html, extension: 'html'}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
}, userConfig())
|
|
43
|
-
|
|
44
|
-
// Add back the `{raw: html}` option if user provided own config
|
|
45
|
-
if (Array.isArray(config.content)) {
|
|
46
|
-
config.content = {
|
|
47
|
-
files: [
|
|
48
|
-
...config.content,
|
|
49
|
-
'./src/**/*.*',
|
|
50
|
-
{raw: html, extension: 'html'}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Include all `build.templates.source` paths when scanning for selectors to preserve
|
|
56
|
-
const buildTemplates = get(maizzleConfig, 'build.templates')
|
|
57
|
-
|
|
58
|
-
if (buildTemplates) {
|
|
59
|
-
const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
60
|
-
const templateSources = templateObjects.map(template => {
|
|
61
|
-
const source = get(template, 'source')
|
|
62
|
-
|
|
63
|
-
if (typeof source === 'function') {
|
|
64
|
-
const sources = source(maizzleConfig)
|
|
65
|
-
|
|
66
|
-
if (Array.isArray(sources)) {
|
|
67
|
-
sources.map(s => config.content.files.push(s))
|
|
68
|
-
} else if (typeof sources === 'string') {
|
|
69
|
-
config.content.files.push(sources)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Must return a valid `content` entry
|
|
73
|
-
return {raw: '', extension: 'html'}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Support single-file sources i.e. src/templates/index.html
|
|
77
|
-
if (typeof source === 'string' && Boolean(path.extname(source))) {
|
|
78
|
-
config.content.files.push(source)
|
|
79
|
-
|
|
80
|
-
return {raw: '', extension: 'html'}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return `${source}/**/*.*`
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
config.content.files.push(...templateSources)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
90
|
-
const userFileExists = await fs.pathExists(userFilePath)
|
|
91
|
-
|
|
92
|
-
if (userFileExists) {
|
|
93
|
-
css
|
|
94
|
-
} else {
|
|
95
|
-
css = '@
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return postcss([
|
|
99
|
-
postcssImport({path: path.dirname(userFilePath)}),
|
|
100
|
-
postcssNested(),
|
|
101
|
-
tailwindcss(config),
|
|
102
|
-
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
103
|
-
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
104
|
-
])
|
|
105
|
-
.process(css, {from: undefined})
|
|
106
|
-
.then(result => result.css)
|
|
107
|
-
.catch(error => {
|
|
108
|
-
console.error(error)
|
|
109
|
-
if (spinner) {
|
|
110
|
-
spinner.stop()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
throw new Error(`Tailwind CSS compilation failed`)
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
}
|
|
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 = {}, spinner = null) => {
|
|
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
|
+
content: {
|
|
37
|
+
files: [
|
|
38
|
+
'./src/**/*.*',
|
|
39
|
+
{raw: html, extension: 'html'}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}, userConfig())
|
|
43
|
+
|
|
44
|
+
// Add back the `{raw: html}` option if user provided own config
|
|
45
|
+
if (Array.isArray(config.content)) {
|
|
46
|
+
config.content = {
|
|
47
|
+
files: [
|
|
48
|
+
...config.content,
|
|
49
|
+
'./src/**/*.*',
|
|
50
|
+
{raw: html, extension: 'html'}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Include all `build.templates.source` paths when scanning for selectors to preserve
|
|
56
|
+
const buildTemplates = get(maizzleConfig, 'build.templates')
|
|
57
|
+
|
|
58
|
+
if (buildTemplates) {
|
|
59
|
+
const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
|
|
60
|
+
const templateSources = templateObjects.map(template => {
|
|
61
|
+
const source = get(template, 'source')
|
|
62
|
+
|
|
63
|
+
if (typeof source === 'function') {
|
|
64
|
+
const sources = source(maizzleConfig)
|
|
65
|
+
|
|
66
|
+
if (Array.isArray(sources)) {
|
|
67
|
+
sources.map(s => config.content.files.push(s))
|
|
68
|
+
} else if (typeof sources === 'string') {
|
|
69
|
+
config.content.files.push(sources)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Must return a valid `content` entry
|
|
73
|
+
return {raw: '', extension: 'html'}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Support single-file sources i.e. src/templates/index.html
|
|
77
|
+
if (typeof source === 'string' && Boolean(path.extname(source))) {
|
|
78
|
+
config.content.files.push(source)
|
|
79
|
+
|
|
80
|
+
return {raw: '', extension: 'html'}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return `${source}/**/*.*`
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
config.content.files.push(...templateSources)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
90
|
+
const userFileExists = await fs.pathExists(userFilePath)
|
|
91
|
+
|
|
92
|
+
if (userFileExists) {
|
|
93
|
+
css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
|
|
94
|
+
} else {
|
|
95
|
+
css = '@import "tailwindcss/components"; @import "tailwindcss/utilities";' + css
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return postcss([
|
|
99
|
+
postcssImport({path: path.dirname(userFilePath)}),
|
|
100
|
+
postcssNested(),
|
|
101
|
+
tailwindcss(config),
|
|
102
|
+
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
103
|
+
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
104
|
+
])
|
|
105
|
+
.process(css, {from: undefined})
|
|
106
|
+
.then(result => result.css)
|
|
107
|
+
.catch(error => {
|
|
108
|
+
console.error(error)
|
|
109
|
+
if (spinner) {
|
|
110
|
+
spinner.stop()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw new Error(`Tailwind CSS compilation failed`)
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
}
|