Skip to content

Commit 83f5e2a

Browse files
committedOct 21, 2019
Move browsersync snippet to above </body> to fix recent Shopify change
1 parent ccdeab9 commit 83f5e2a

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed
 

‎lib/tasks/deploy-sync.js

+31-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
'use strict';
21

3-
var gulp = require('gulp');
4-
var browserSync = require('browser-sync').create();
5-
var fs = require('fs');
6-
var yaml = require('js-yaml');
7-
var debug = require('debug')('slate-tools:deploy');
82

9-
var config = require('./includes/config.js');
10-
var messages = require('./includes/messages.js');
3+
const gulp = require('gulp');
4+
const browserSync = require('browser-sync').create();
5+
const fs = require('fs');
6+
const yaml = require('js-yaml');
7+
const debug = require('debug')('slate-tools:deploy');
8+
9+
const config = require('./includes/config.js');
10+
const messages = require('./includes/messages.js');
1111

1212
/**
1313
* Starts a [browserSync]{@link https://www.browsersync.io/} session proxying your
@@ -17,24 +17,24 @@ var messages = require('./includes/messages.js');
1717
* @memberof slate-cli.tasks.deploy
1818
* @static
1919
*/
20-
gulp.task('deploy:sync-init', function () {
20+
gulp.task('deploy:sync-init', () => {
2121
if (browserSync.active) {
2222
browserSync.exit();
2323
} else {
2424
fs.writeFileSync(config.deployLog, ''); // eslint-disable-line no-sync
2525
}
2626

27-
var file = fs.readFileSync(config.tkConfig, 'utf8'); // eslint-disable-line no-sync
28-
var tkConfig = yaml.safeLoad(file);
29-
var queryStringComponents = [];
30-
var environment = config.environment.split(/\s*,\s*|\s+/)[0];
27+
const file = fs.readFileSync(config.tkConfig, 'utf8'); // eslint-disable-line no-sync
28+
const tkConfig = yaml.safeLoad(file);
29+
const queryStringComponents = [];
30+
const environment = config.environment.split(/\s*,\s*|\s+/)[0];
3131

32-
var envObj = tkConfig[environment];
33-
var proxyTarget = 'https://' + envObj.store;
32+
const envObj = tkConfig[environment];
33+
let proxyTarget = `https://${envObj.store}`;
3434

3535
// break theme preview cache by always setting a preview parameter
36-
var previewParam = envObj.theme_id === 'live' ? '' : envObj.theme_id;
37-
proxyTarget += '?preview_theme_id=' + previewParam;
36+
const previewParam = envObj.theme_id === 'live' ? '' : envObj.theme_id;
37+
proxyTarget += `?preview_theme_id=${previewParam}`;
3838

3939
debug(proxyTarget);
4040

@@ -48,11 +48,19 @@ gulp.task('deploy:sync-init', function () {
4848
proxy: {
4949
target: proxyTarget,
5050
middleware: function middleware(req, res, next) {
51-
var prefix = req.url.indexOf('?') > -1 ? '&' : '?';
51+
const prefix = req.url.indexOf('?') > -1 ? '&' : '?';
5252
req.url += prefix + queryStringComponents.join('&');
5353
next();
54-
}
55-
}
54+
},
55+
},
56+
snippetOptions: {
57+
rule: {
58+
match: /<\/body>/i,
59+
fn: function(snippet, match) {
60+
return snippet + match;
61+
},
62+
},
63+
},
5664
});
5765
});
5866

@@ -64,10 +72,10 @@ gulp.task('deploy:sync-init', function () {
6472
* @memberof slate-cli.tasks.watch
6573
* @static
6674
*/
67-
gulp.task('deploy:sync-reload', ['deploy:sync-init'], function () {
75+
gulp.task('deploy:sync-reload', ['deploy:sync-init'], () => {
6876
gulp.watch(config.tkConfig, ['deploy:sync-init']);
69-
gulp.watch(config.deployLog, function () {
77+
gulp.watch(config.deployLog, () => {
7078
messages.logTransferDone();
7179
browserSync.reload();
7280
});
73-
});
81+
});

‎src/tasks/deploy-sync.js

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ gulp.task('deploy:sync-init', () => {
5151
next();
5252
},
5353
},
54+
snippetOptions: {
55+
rule: {
56+
match: /<\/body>/i,
57+
fn: function (snippet, match) {
58+
return snippet + match;
59+
}
60+
}
61+
}
5462
});
5563
});
5664

0 commit comments

Comments
 (0)
Please sign in to comment.