@maizzle/framework 5.0.0-beta.6 → 5.0.0-beta.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "5.0.0-beta.6",
3
+ "version": "5.0.0-beta.7",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,6 +8,7 @@ import posthtmlPostcss from 'posthtml-postcss'
8
8
  import defaultPosthtmlConfig from './defaultConfig.js'
9
9
  import expandLinkTag from './plugins/expandLinkTag.js'
10
10
  import envAttributes from './plugins/envAttributes.js'
11
+ import envTags from './plugins/envTags.js'
11
12
 
12
13
  // PostCSS
13
14
  import tailwindcss from 'tailwindcss'
@@ -51,6 +52,7 @@ export async function process(html = '', config = {}) {
51
52
 
52
53
  return posthtml([
53
54
  ...get(config, 'posthtml.plugins.before', []),
55
+ envTags(config.env),
54
56
  envAttributes(config.env),
55
57
  expandLinkTag,
56
58
  postcssPlugin,
@@ -0,0 +1,33 @@
1
+ const plugin = (env => tree => {
2
+ const process = node => {
3
+ env = env || 'local'
4
+
5
+ // Return the original node if it doesn't have a tag
6
+ if (!node.tag) {
7
+ return node
8
+ }
9
+
10
+ const tagEnv = node.tag.split(':').pop()
11
+
12
+ // Tag targets current env, remove it and return its content
13
+ if (node.tag.endsWith(`:${env}`)) {
14
+ node.tag = false
15
+ }
16
+
17
+ // Tag doesn't target current env, remove it completely
18
+ if (
19
+ typeof node.tag === 'string'
20
+ && node.tag.startsWith('env:')
21
+ && tagEnv !== env
22
+ ) {
23
+ node.content = []
24
+ node.tag = false
25
+ }
26
+
27
+ return node
28
+ }
29
+
30
+ return tree.walk(process)
31
+ })
32
+
33
+ export default plugin