Skip to content

Commit aeb43fc

Browse files
committed
Split email task in build and only dev task and add browser sync to watch the email templates
1 parent b9de177 commit aeb43fc

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

config/browser-sync-email.json.sample

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"server": {
3+
"baseDir": "../../../"
4+
},
5+
"files": [
6+
"../../../app/design/frontend/**/email/**/*.html",
7+
"../../../pub/static/frontend/**/email.css"
8+
],
9+
"open": false,
10+
"startPath": "app/design/frontend/Framework/WhiteLabel/Magento_Customer/email/welcome.html"
11+
}

helper/inky.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
33
const theme = config.themes[name],
44
srcBase = config.projectPath + 'var/view_preprocessed/frontools' + theme.dest.replace('pub/static', ''),
55
dest = [],
6+
srcTheme = [],
7+
themeName = srcBase.split('/frontools/frontend/')[1],
8+
enableInliner = plugins.util.env.enableInliner || false,
69
production = plugins.util.env.prod || false;
710

811
function adjustDestinationDirectory(file) {
@@ -14,11 +17,15 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
1417
dest.push(config.projectPath + theme.dest + '/' + locale);
1518
});
1619

20+
srcTheme.push(config.projectPath + theme.src);
21+
1722
// Return empty stream if no email directory is included
1823
if (!plugins.fs.existsSync(srcBase + '/email')) {
1924
return [];
2025
}
2126

27+
plugins.panini.refresh();
28+
2229
return gulp.src(
2330
file || srcBase + '/**/*.email.hbs',
2431
{ base: srcBase }
@@ -37,9 +44,22 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
3744
partials: srcBase + '/email/partials/',
3845
helpers: srcBase + '/email/helpers/'
3946
}))
47+
.pipe(plugins.if(!enableInliner, plugins.replace('###THEME-NAME###', themeName)))
4048
.pipe(plugins.inky())
49+
.pipe(plugins.if(enableInliner, plugins.rename(function (path) {
50+
path.basename = path.basename.replace('.email', '.email.tmp');
51+
52+
return path;
53+
})))
54+
.pipe(plugins.if(!enableInliner, plugins.rename(function (path) {
55+
path.basename = path.basename.replace('.email', '');
56+
path.extname = '.html';
57+
58+
return path;
59+
})))
4160
.pipe(plugins.rename(adjustDestinationDirectory))
42-
.pipe(plugins.multiDest(srcBase))
61+
.pipe(plugins.if(enableInliner, plugins.multiDest(srcBase)))
62+
.pipe(plugins.if(!enableInliner, plugins.multiDest(srcTheme)))
4363
.pipe(plugins.logger({
4464
display : 'name',
4565
beforeEach: 'Theme: ' + name + ' ',

helper/inliner.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
3232
}
3333

3434
return gulp.src(
35-
file || srcBase + '/**/*.email.hbs',
35+
file || srcBase + '/**/*.email.tmp.hbs',
3636
{ base: srcBase }
3737
)
3838
.pipe(
@@ -43,6 +43,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
4343
})
4444
)
4545
)
46+
.pipe(plugins.replace(`<link rel="stylesheet" href="/pub/static/frontend/###THEME-NAME###/de_DE/css/email.css">`, ''))
4647
.pipe(plugins.inlineCss({
4748
extraCss: css,
4849
applyStyleTags: false,
@@ -56,7 +57,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
5657
minifyCSS: true
5758
}))
5859
.pipe(plugins.rename(function (path) {
59-
path.basename = path.basename.replace('.email', '');
60+
path.basename = path.basename.replace('.email.tmp', '');
6061
path.extname = '.html';
6162

6263
return path;

task/dev:email.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
module.exports = function() { // eslint-disable-line func-names
3+
// Global variables
4+
const plugins = this.opts.plugins,
5+
config = this.opts.configs;
6+
7+
// Prevent runing inheritance task more than once
8+
plugins.util.env.pipeline = true;
9+
10+
plugins.runSequence('inheritance', 'styles', 'inky', () => {
11+
plugins.browserSync.create();
12+
plugins.browserSync(
13+
require('../helper/config-loader')('browser-sync-email.json', plugins, config)
14+
);
15+
16+
plugins.runSequence('watch');
17+
});
18+
};
19+

task/email.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
'use strict';
22
module.exports = function() { // eslint-disable-line func-names
3-
// Global variables
3+
// Global variables
44
const plugins = this.opts.plugins,
55
config = this.opts.configs;
66

77
// Prevent runing inheritance task more than once
88
plugins.util.env.pipeline = true;
99

10+
if (!plugins.util.env.enableInliner) {
11+
plugins.util.env.enableInliner = true;
12+
}
13+
1014
plugins.runSequence('inheritance', 'styles', 'inky', 'inliner');
1115
};

0 commit comments

Comments
 (0)