@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.
- package/.github/dependabot.yml +11 -11
- package/.github/workflows/nodejs.yml +28 -29
- package/package.json +86 -84
- package/src/generators/output/to-disk.js +144 -111
- package/src/generators/output/to-string.js +71 -64
- package/src/generators/posthtml.js +61 -60
- package/src/generators/tailwindcss.js +57 -34
- package/src/index.js +24 -36
- package/src/transformers/{attribute-to-style.js → attributeToStyle.js} +0 -0
- package/src/transformers/baseUrl.js +45 -0
- package/src/transformers/{extra-attributes.js → extraAttributes.js} +0 -0
- package/src/transformers/index.js +13 -13
- package/src/transformers/{inline.js → inlineCss.js} +0 -0
- package/src/transformers/{posthtml-mso.js → posthtmlMso.js} +0 -0
- package/src/transformers/{prevent-widows.js → preventWidows.js} +0 -0
- package/src/transformers/{remove-attributes.js → removeAttributes.js} +1 -1
- package/src/transformers/{remove-inline-bgcolor.js → removeInlineBackgroundColor.js} +0 -0
- package/src/transformers/{remove-inline-sizes.js → removeInlineSizes.js} +0 -0
- package/src/transformers/{remove-unused-css.js → removeUnusedCss.js} +0 -0
- package/src/transformers/{replace-strings.js → replaceStrings.js} +0 -0
- package/src/transformers/{safe-class-names.js → safeClassNames.js} +8 -2
- package/src/transformers/{six-hex.js → sixHex.js} +10 -10
- package/src/transformers/transform.js +4 -6
- package/src/transformers/{url-params.js → urlParameters.js} +0 -0
- package/src/utils/helpers.js +2 -8
- package/test/expected/transformers/base-image-url.html +83 -7
- package/test/expected/transformers/transform-postcss.html +19 -0
- package/test/expected/useConfig.html +9 -0
- package/test/fixtures/basic.html +9 -0
- package/test/fixtures/transformers/base-image-url.html +85 -7
- package/test/fixtures/useConfig.html +9 -0
- package/test/stubs/tailwind/preserve.html +1 -0
- package/test/test-misc.js +8 -8
- package/test/test-tailwind.js +100 -73
- package/test/test-todisk.js +106 -29
- package/test/test-tostring.js +12 -3
- package/test/test-transformers.js +343 -320
- package/xo.config.js +22 -19
- package/src/transformers/base-image-url.js +0 -9
|
@@ -1,64 +1,71 @@
|
|
|
1
|
-
const fm = require('front-matter')
|
|
2
|
-
const {get, merge} = require('lodash')
|
|
3
|
-
const posthtml = require('../posthtml')
|
|
4
|
-
const Tailwind = require('../tailwindcss')
|
|
5
|
-
const Transformers = require('../../transformers')
|
|
6
|
-
const posthtmlMSO = require('../../transformers/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
config
|
|
63
|
-
}
|
|
64
|
-
|
|
1
|
+
const fm = require('front-matter')
|
|
2
|
+
const {get, merge} = require('lodash')
|
|
3
|
+
const posthtml = require('../posthtml')
|
|
4
|
+
const Tailwind = require('../tailwindcss')
|
|
5
|
+
const Transformers = require('../../transformers')
|
|
6
|
+
const posthtmlMSO = require('../../transformers/posthtmlMso')
|
|
7
|
+
const Config = require('../config')
|
|
8
|
+
|
|
9
|
+
module.exports = async (html, options) => {
|
|
10
|
+
process.env.NODE_ENV = get(options, 'maizzle.env', 'local')
|
|
11
|
+
|
|
12
|
+
if (typeof html !== 'string') {
|
|
13
|
+
throw new TypeError(`first argument must be an HTML string, received ${html}`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (html.length === 0) {
|
|
17
|
+
throw new RangeError('received empty string')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fileConfig = await Config.getMerged(process.env.NODE_ENV)
|
|
21
|
+
|
|
22
|
+
let config = merge(fileConfig, get(options, 'maizzle', {}))
|
|
23
|
+
|
|
24
|
+
const tailwindConfig = get(options, 'tailwind.config', {})
|
|
25
|
+
const cssString = get(options, 'tailwind.css', '@tailwind components; @tailwind utilities;')
|
|
26
|
+
|
|
27
|
+
let {frontmatter} = fm(html)
|
|
28
|
+
|
|
29
|
+
if (frontmatter) {
|
|
30
|
+
frontmatter = await posthtml(frontmatter, config)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
html = `---\n${frontmatter}\n---\n\n${fm(html).body}`
|
|
34
|
+
|
|
35
|
+
config = merge({applyTransformers: true}, config, fm(html).attributes)
|
|
36
|
+
|
|
37
|
+
if (typeof get(options, 'tailwind.compiled') === 'string') {
|
|
38
|
+
config.css = options.tailwind.compiled
|
|
39
|
+
} else {
|
|
40
|
+
config.css = await Tailwind.compile(cssString, html, tailwindConfig, config)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options && typeof options.beforeRender === 'function') {
|
|
44
|
+
html = await options.beforeRender(html, config)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
html = await posthtml(html, config)
|
|
48
|
+
|
|
49
|
+
while (Object.keys(fm(html).attributes).length > 0) {
|
|
50
|
+
html = fm(html).body
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options && typeof options.afterRender === 'function') {
|
|
54
|
+
html = await options.afterRender(html, config)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (config.applyTransformers) {
|
|
58
|
+
html = await Transformers.process(html, config)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options && typeof options.afterTransformers === 'function') {
|
|
62
|
+
html = await options.afterTransformers(html, config)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
html = await posthtmlMSO(html, config)
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
html,
|
|
69
|
+
config
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1,60 +1,61 @@
|
|
|
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 fetchOptions = get(config, 'build.posthtml.fetch', {})
|
|
13
|
-
const fetchPlugin = fetch({...fetchOptions})
|
|
14
|
-
|
|
15
|
-
const modulesOptions = get(config, 'build.components', {})
|
|
16
|
-
// Fake `from` option so we can reference modules relatively
|
|
17
|
-
const modulesRoot = modulesOptions.root || './'
|
|
18
|
-
const modulesFrom = modulesOptions.from || `${modulesRoot}/fake`
|
|
19
|
-
|
|
20
|
-
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
21
|
-
const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
|
|
22
|
-
|
|
23
|
-
const expressionsOptions = merge({strictMode: false}, get(config, 'build.posthtml.expressions', {}))
|
|
24
|
-
|
|
25
|
-
const locals = merge(
|
|
26
|
-
get(expressionsOptions, 'locals', {}),
|
|
27
|
-
get(config, 'locals', {}),
|
|
28
|
-
{page: config}
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
return posthtml([
|
|
32
|
-
fetchPlugin,
|
|
33
|
-
layouts(
|
|
34
|
-
merge(
|
|
35
|
-
{
|
|
36
|
-
strict: false,
|
|
37
|
-
plugins: [
|
|
38
|
-
expressions({...expressionsOptions, locals})
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
layoutsOptions
|
|
42
|
-
)
|
|
43
|
-
),
|
|
44
|
-
modules({
|
|
45
|
-
parser: posthtmlOptions,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
60
|
-
|
|
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 fetchOptions = get(config, 'build.posthtml.fetch', {})
|
|
13
|
+
const fetchPlugin = fetch({...fetchOptions})
|
|
14
|
+
|
|
15
|
+
const modulesOptions = get(config, 'build.components', {})
|
|
16
|
+
// Fake `from` option so we can reference modules relatively
|
|
17
|
+
const modulesRoot = modulesOptions.root || './'
|
|
18
|
+
const modulesFrom = modulesOptions.from || `${modulesRoot}/fake`
|
|
19
|
+
|
|
20
|
+
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
21
|
+
const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
|
|
22
|
+
|
|
23
|
+
const expressionsOptions = merge({strictMode: false}, get(config, 'build.posthtml.expressions', {}))
|
|
24
|
+
|
|
25
|
+
const locals = merge(
|
|
26
|
+
get(expressionsOptions, 'locals', {}),
|
|
27
|
+
get(config, 'locals', {}),
|
|
28
|
+
{page: config}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
return posthtml([
|
|
32
|
+
fetchPlugin,
|
|
33
|
+
layouts(
|
|
34
|
+
merge(
|
|
35
|
+
{
|
|
36
|
+
strict: false,
|
|
37
|
+
plugins: [
|
|
38
|
+
expressions({...expressionsOptions, locals})
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
layoutsOptions
|
|
42
|
+
)
|
|
43
|
+
),
|
|
44
|
+
modules({
|
|
45
|
+
parser: posthtmlOptions,
|
|
46
|
+
attributeAsLocals: true,
|
|
47
|
+
from: modulesFrom,
|
|
48
|
+
root: modulesRoot,
|
|
49
|
+
tag: 'component',
|
|
50
|
+
attribute: 'src',
|
|
51
|
+
plugins: [
|
|
52
|
+
fetchPlugin
|
|
53
|
+
],
|
|
54
|
+
locals,
|
|
55
|
+
...modulesOptions
|
|
56
|
+
}),
|
|
57
|
+
...posthtmlPlugins
|
|
58
|
+
])
|
|
59
|
+
.process(html, {...posthtmlOptions})
|
|
60
|
+
.then(result => fm(result.html).body)
|
|
61
|
+
}
|
|
@@ -9,7 +9,7 @@ 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 = '', tailwindConfig = {}, maizzleConfig = {}) => {
|
|
12
|
+
compile: async (css = '', html = '', tailwindConfig = {}, maizzleConfig = {}, spinner = null) => {
|
|
13
13
|
tailwindConfig = (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) ? tailwindConfig : get(maizzleConfig, 'build.tailwind.config', 'tailwind.config.js')
|
|
14
14
|
|
|
15
15
|
// Compute the Tailwind config to use
|
|
@@ -33,46 +33,61 @@ module.exports = {
|
|
|
33
33
|
// Merge user's Tailwind config on top of a 'base' config
|
|
34
34
|
const config = merge({
|
|
35
35
|
important: true,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
options: get(maizzleConfig, 'purgeCSS', {})
|
|
43
|
-
},
|
|
44
|
-
corePlugins: {
|
|
45
|
-
animation: false,
|
|
46
|
-
backgroundOpacity: false,
|
|
47
|
-
borderOpacity: false,
|
|
48
|
-
boxShadow: false,
|
|
49
|
-
divideOpacity: false,
|
|
50
|
-
placeholderOpacity: false,
|
|
51
|
-
ringColor: false,
|
|
52
|
-
ringWidth: false,
|
|
53
|
-
ringOpacity: false,
|
|
54
|
-
ringOffsetColor: false,
|
|
55
|
-
textOpacity: false
|
|
56
|
-
},
|
|
57
|
-
plugins: []
|
|
36
|
+
content: {
|
|
37
|
+
files: [
|
|
38
|
+
'./src/**/*.*',
|
|
39
|
+
{raw: html, extension: 'html'}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
58
42
|
}, userConfig())
|
|
59
43
|
|
|
60
|
-
//
|
|
61
|
-
config.
|
|
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
|
+
}
|
|
62
54
|
|
|
63
|
-
|
|
55
|
+
// Include all `build.templates.source` paths when scanning for selectors to preserve
|
|
56
|
+
const buildTemplates = get(maizzleConfig, 'build.templates')
|
|
64
57
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
}
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
return `${source}/**/*.*`
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
config.content.files.push(...templateSources)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
83
|
+
const userFileExists = await fs.pathExists(userFilePath)
|
|
84
|
+
|
|
85
|
+
if (userFileExists) {
|
|
86
|
+
css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
|
|
87
|
+
}
|
|
73
88
|
|
|
74
89
|
return postcss([
|
|
75
|
-
postcssImport({path:
|
|
90
|
+
postcssImport({path: path.dirname(userFilePath)}),
|
|
76
91
|
postcssNested(),
|
|
77
92
|
tailwindcss(config),
|
|
78
93
|
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
@@ -80,5 +95,13 @@ module.exports = {
|
|
|
80
95
|
])
|
|
81
96
|
.process(css, {from: undefined})
|
|
82
97
|
.then(result => result.css)
|
|
98
|
+
.catch(error => {
|
|
99
|
+
console.error(error)
|
|
100
|
+
if (spinner) {
|
|
101
|
+
spinner.stop()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw new Error(`Tailwind CSS compilation failed`)
|
|
105
|
+
})
|
|
83
106
|
}
|
|
84
107
|
}
|
package/src/index.js
CHANGED
|
@@ -2,13 +2,20 @@ const ora = require('ora')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const fs = require('fs-extra')
|
|
4
4
|
const {get, merge} = require('lodash')
|
|
5
|
-
const bs = require('browser-sync').create()
|
|
6
5
|
const Config = require('./generators/config')
|
|
7
6
|
const Output = require('./generators/output')
|
|
8
7
|
const transformers = require('./transformers')
|
|
9
8
|
const {clearConsole} = require('./utils/helpers')
|
|
10
9
|
const Plaintext = require('./generators/plaintext')
|
|
11
|
-
|
|
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
|
+
}
|
|
12
19
|
|
|
13
20
|
const self = module.exports = { // eslint-disable-line
|
|
14
21
|
...transformers,
|
|
@@ -23,7 +30,10 @@ const self = module.exports = { // eslint-disable-line
|
|
|
23
30
|
const elapsedSeconds = (Date.now() - start) / 1000
|
|
24
31
|
|
|
25
32
|
if (get(config, 'build.command') === 'serve') {
|
|
26
|
-
|
|
33
|
+
if (get(config, 'build.console.clear')) {
|
|
34
|
+
clearConsole()
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
spinner.succeed(`Re-built ${parsed.length} templates in ${elapsedSeconds}s`)
|
|
28
38
|
} else {
|
|
29
39
|
spinner.succeed(`Built ${parsed.length} templates in ${elapsedSeconds}s`)
|
|
@@ -59,16 +69,14 @@ const self = module.exports = { // eslint-disable-line
|
|
|
59
69
|
[...new Set(get(config, 'build.browsersync.watch', []))]
|
|
60
70
|
]
|
|
61
71
|
|
|
62
|
-
// Pre-compile Tailwind so that updates to tailwind.config.js are reflected
|
|
63
|
-
const cssString = fs.existsSync(get(config, 'build.tailwind.css')) ? fs.readFileSync(get(config, 'build.tailwind.css'), 'utf8') : '@tailwind components; @tailwind utilities;'
|
|
64
|
-
const css = await Tailwind.compile(cssString, '', {}, config)
|
|
65
|
-
|
|
66
72
|
const spinner = ora()
|
|
67
73
|
|
|
68
74
|
// Watch for Template file changes
|
|
69
|
-
|
|
75
|
+
getBrowserSync().watch(templatePaths)
|
|
70
76
|
.on('change', async file => {
|
|
71
|
-
|
|
77
|
+
if (get(config, 'build.console.clear')) {
|
|
78
|
+
clearConsole()
|
|
79
|
+
}
|
|
72
80
|
|
|
73
81
|
const start = new Date()
|
|
74
82
|
|
|
@@ -86,54 +94,34 @@ const self = module.exports = { // eslint-disable-line
|
|
|
86
94
|
await config.events.beforeCreate(config)
|
|
87
95
|
}
|
|
88
96
|
|
|
89
|
-
/**
|
|
90
|
-
* Tailwind CSS compiler
|
|
91
|
-
*
|
|
92
|
-
* Use the Just-In-Time engine if the user enabled it
|
|
93
|
-
* Fall back to the classic Always-On-Time engine
|
|
94
|
-
*/
|
|
95
|
-
let mode = 'aot'
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const tailwindConfig = require(path.resolve(process.cwd(), get(config, 'build.currentTemplates.tailwind.config', 'tailwind.config.js')))
|
|
99
|
-
mode = get(tailwindConfig, 'mode')
|
|
100
|
-
} catch {}
|
|
101
|
-
|
|
102
97
|
const renderOptions = {
|
|
103
98
|
maizzle: config,
|
|
104
99
|
...config.events
|
|
105
100
|
}
|
|
106
101
|
|
|
107
|
-
// AOT: fall back to pre-compiled CSS
|
|
108
|
-
if (mode !== 'jit') {
|
|
109
|
-
renderOptions.tailwind = {
|
|
110
|
-
compiled: css
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
102
|
self
|
|
115
103
|
.render(await fs.readFile(file, 'utf8'), renderOptions)
|
|
116
104
|
.then(({html, config}) => fs.outputFile(config.permalink || finalDestination, html))
|
|
117
105
|
.then(() => {
|
|
118
|
-
|
|
106
|
+
getBrowserSync().reload()
|
|
119
107
|
spinner.succeed(`Compiled in ${(Date.now() - start) / 1000}s [${file}]`)
|
|
120
108
|
})
|
|
121
109
|
.catch(() => spinner.warn(`Received empty HTML, please save your file again [${file}]`))
|
|
122
110
|
})
|
|
123
111
|
|
|
124
112
|
// Watch for changes in all other files
|
|
125
|
-
|
|
126
|
-
.on('change', () => self.build(env, config).then(() =>
|
|
127
|
-
.on('unlink', () => self.build(env, config).then(() =>
|
|
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()))
|
|
128
116
|
|
|
129
117
|
// Watch for changes in config files
|
|
130
|
-
|
|
118
|
+
getBrowserSync().watch('config*.js')
|
|
131
119
|
.on('change', async file => {
|
|
132
120
|
const parsedEnv = path.parse(file).name.split('.')[1] || 'local'
|
|
133
121
|
|
|
134
122
|
Config
|
|
135
123
|
.getMerged(parsedEnv)
|
|
136
|
-
.then(config => self.build(parsedEnv, config).then(() =>
|
|
124
|
+
.then(config => self.build(parsedEnv, config).then(() => getBrowserSync().reload()))
|
|
137
125
|
})
|
|
138
126
|
|
|
139
127
|
// Browsersync options
|
|
@@ -154,7 +142,7 @@ const self = module.exports = { // eslint-disable-line
|
|
|
154
142
|
}
|
|
155
143
|
|
|
156
144
|
// Initialize Browsersync
|
|
157
|
-
|
|
145
|
+
getBrowserSync().init(bsOptions, () => {})
|
|
158
146
|
})
|
|
159
147
|
.catch(error => {
|
|
160
148
|
throw error
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const posthtml = require('posthtml')
|
|
2
|
+
const isUrl = require('is-url-superb')
|
|
3
|
+
const baseUrl = require('posthtml-base-url')
|
|
4
|
+
const {get, isObject, isEmpty} = require('lodash')
|
|
5
|
+
|
|
6
|
+
// VML backgrounds need regex because they're inside HTML comments :(
|
|
7
|
+
const rewriteVMLs = (html, url) => {
|
|
8
|
+
const vImageMatch = html.match(/(<v:image.+)(src=['"]([^'"]+)['"])/)
|
|
9
|
+
const vFillMatch = html.match(/(<v:fill.+)(src=['"]([^'"]+)['"])/)
|
|
10
|
+
|
|
11
|
+
if (vImageMatch && !isUrl(vImageMatch[3])) {
|
|
12
|
+
html = html.replace(vImageMatch[0], `${vImageMatch[1]}src="${url}${vImageMatch[3]}"`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (vFillMatch && !isUrl(vFillMatch[3])) {
|
|
16
|
+
html = html.replace(vFillMatch[0], `${vFillMatch[1]}src="${url}${vFillMatch[3]}"`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return html
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = async (html, config = {}, direct = false) => {
|
|
23
|
+
const url = direct ? config : get(config, 'baseURL')
|
|
24
|
+
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
25
|
+
|
|
26
|
+
// `baseUrl` as a string
|
|
27
|
+
if (typeof url === 'string' && url.length > 0) {
|
|
28
|
+
html = rewriteVMLs(html, url)
|
|
29
|
+
|
|
30
|
+
return posthtml([
|
|
31
|
+
baseUrl({url, allTags: true, styleTag: true, inlineCss: true})
|
|
32
|
+
])
|
|
33
|
+
.process(html, posthtmlOptions)
|
|
34
|
+
.then(result => result.html)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// `baseUrl: {}`
|
|
38
|
+
if (isObject(url) && !isEmpty(url)) {
|
|
39
|
+
html = rewriteVMLs(html, url.url)
|
|
40
|
+
|
|
41
|
+
return posthtml([baseUrl(url)]).process(html, posthtmlOptions).then(result => result.html)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return html
|
|
45
|
+
}
|
|
File without changes
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const inline = require('./
|
|
1
|
+
const inline = require('./inlineCss')
|
|
2
2
|
const minify = require('./minify')
|
|
3
3
|
const markdown = require('./markdown')
|
|
4
4
|
const prettify = require('./prettify')
|
|
5
|
-
const ensureSixHEX = require('./
|
|
6
|
-
const
|
|
5
|
+
const ensureSixHEX = require('./sixHex')
|
|
6
|
+
const applyBaseImageUrl = require('./baseUrl')
|
|
7
|
+
const addURLParams = require('./urlParameters')
|
|
7
8
|
const transformContents = require('./transform')
|
|
8
|
-
const preventWidows = require('./
|
|
9
|
-
const replaceStrings = require('./
|
|
10
|
-
const safeClassNames = require('./
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const removeInlineBgColor = require('./remove-inline-bgcolor')
|
|
9
|
+
const preventWidows = require('./preventWidows')
|
|
10
|
+
const replaceStrings = require('./replaceStrings')
|
|
11
|
+
const safeClassNames = require('./safeClassNames')
|
|
12
|
+
const removeUnusedCSS = require('./removeUnusedCss')
|
|
13
|
+
const removeAttributes = require('./removeAttributes')
|
|
14
|
+
const attributeToStyle = require('./attributeToStyle')
|
|
15
|
+
const removeInlineSizes = require('./removeInlineSizes')
|
|
16
|
+
const applyExtraAttributes = require('./extraAttributes')
|
|
17
|
+
const removeInlineBgColor = require('./removeInlineBackgroundColor')
|
|
18
18
|
|
|
19
19
|
exports.process = async (html, config) => {
|
|
20
20
|
html = await safeClassNames(html, config)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -8,7 +8,7 @@ module.exports = async (html, config = {}, direct = false) => {
|
|
|
8
8
|
|
|
9
9
|
attributes.push({name: 'style'}, {name: 'class'})
|
|
10
10
|
|
|
11
|
-
// Allow
|
|
11
|
+
// Allow omitting `value` key when removing empty attributes
|
|
12
12
|
attributes.forEach(attr => {
|
|
13
13
|
attr.value = attr.value || ''
|
|
14
14
|
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,11 +3,17 @@ const posthtml = require('posthtml')
|
|
|
3
3
|
const safeClassNames = require('posthtml-safe-class-names')
|
|
4
4
|
|
|
5
5
|
module.exports = async (html, config = {}, direct = false) => {
|
|
6
|
-
|
|
6
|
+
const option = get(config, 'safeClassNames')
|
|
7
|
+
|
|
8
|
+
if (option === false) {
|
|
7
9
|
return html
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
/*
|
|
13
|
+
* Setting it to `true` in the config will run `safeClassNames`
|
|
14
|
+
* no matter the environment.
|
|
15
|
+
*/
|
|
16
|
+
if (config.env === 'local' && !option) {
|
|
11
17
|
return html
|
|
12
18
|
}
|
|
13
19
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const {get} = require('lodash')
|
|
2
|
-
const {conv} = require('color-shorthand-hex-to-six-digit')
|
|
3
|
-
|
|
4
|
-
module.exports = async (html, config = {}) => {
|
|
5
|
-
if (get(config, 'sixHex') === false) {
|
|
6
|
-
return html
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return conv(html)
|
|
10
|
-
}
|
|
1
|
+
const {get} = require('lodash')
|
|
2
|
+
const {conv} = require('color-shorthand-hex-to-six-digit')
|
|
3
|
+
|
|
4
|
+
module.exports = async (html, config = {}) => {
|
|
5
|
+
if (get(config, 'sixHex') === false) {
|
|
6
|
+
return html
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return conv(html)
|
|
10
|
+
}
|