Skip to content

Commit

Permalink
Split email task in build and only dev task and add browser sync to w…
Browse files Browse the repository at this point in the history
…atch the email templates
  • Loading branch information
marvinhuebner committed Nov 8, 2018
1 parent b9de177 commit aeb43fc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
11 changes: 11 additions & 0 deletions config/browser-sync-email.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"server": {
"baseDir": "../../../"
},
"files": [
"../../../app/design/frontend/**/email/**/*.html",
"../../../pub/static/frontend/**/email.css"
],
"open": false,
"startPath": "app/design/frontend/Framework/WhiteLabel/Magento_Customer/email/welcome.html"
}
22 changes: 21 additions & 1 deletion helper/inky.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
const theme = config.themes[name],
srcBase = config.projectPath + 'var/view_preprocessed/frontools' + theme.dest.replace('pub/static', ''),
dest = [],
srcTheme = [],
themeName = srcBase.split('/frontools/frontend/')[1],
enableInliner = plugins.util.env.enableInliner || false,
production = plugins.util.env.prod || false;

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

srcTheme.push(config.projectPath + theme.src);

// Return empty stream if no email directory is included
if (!plugins.fs.existsSync(srcBase + '/email')) {
return [];
}

plugins.panini.refresh();

return gulp.src(
file || srcBase + '/**/*.email.hbs',
{ base: srcBase }
Expand All @@ -37,9 +44,22 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
partials: srcBase + '/email/partials/',
helpers: srcBase + '/email/helpers/'
}))
.pipe(plugins.if(!enableInliner, plugins.replace('###THEME-NAME###', themeName)))
.pipe(plugins.inky())
.pipe(plugins.if(enableInliner, plugins.rename(function (path) {
path.basename = path.basename.replace('.email', '.email.tmp');

return path;
})))
.pipe(plugins.if(!enableInliner, plugins.rename(function (path) {
path.basename = path.basename.replace('.email', '');
path.extname = '.html';

return path;
})))
.pipe(plugins.rename(adjustDestinationDirectory))
.pipe(plugins.multiDest(srcBase))
.pipe(plugins.if(enableInliner, plugins.multiDest(srcBase)))
.pipe(plugins.if(!enableInliner, plugins.multiDest(srcTheme)))
.pipe(plugins.logger({
display : 'name',
beforeEach: 'Theme: ' + name + ' ',
Expand Down
5 changes: 3 additions & 2 deletions helper/inliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
}

return gulp.src(
file || srcBase + '/**/*.email.hbs',
file || srcBase + '/**/*.email.tmp.hbs',
{ base: srcBase }
)
.pipe(
Expand All @@ -43,6 +43,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
})
)
)
.pipe(plugins.replace(`<link rel="stylesheet" href="/pub/static/frontend/###THEME-NAME###/de_DE/css/email.css">`, ''))
.pipe(plugins.inlineCss({
extraCss: css,
applyStyleTags: false,
Expand All @@ -56,7 +57,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
minifyCSS: true
}))
.pipe(plugins.rename(function (path) {
path.basename = path.basename.replace('.email', '');
path.basename = path.basename.replace('.email.tmp', '');
path.extname = '.html';

return path;
Expand Down
19 changes: 19 additions & 0 deletions task/dev:email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
module.exports = function() { // eslint-disable-line func-names
// Global variables
const plugins = this.opts.plugins,
config = this.opts.configs;

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

plugins.runSequence('inheritance', 'styles', 'inky', () => {
plugins.browserSync.create();
plugins.browserSync(
require('../helper/config-loader')('browser-sync-email.json', plugins, config)
);

plugins.runSequence('watch');
});
};

6 changes: 5 additions & 1 deletion task/email.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict';
module.exports = function() { // eslint-disable-line func-names
// Global variables
// Global variables
const plugins = this.opts.plugins,
config = this.opts.configs;

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

if (!plugins.util.env.enableInliner) {
plugins.util.env.enableInliner = true;
}

plugins.runSequence('inheritance', 'styles', 'inky', 'inliner');
};

0 comments on commit aeb43fc

Please sign in to comment.