From 0735c0ed930499f7cfbd3290094c6a84f8fd79a0 Mon Sep 17 00:00:00 2001 From: Karin Touchie Date: Mon, 4 Jun 2018 14:14:17 +0200 Subject: [PATCH] BDE-139: Remove highlighting from FF extension --- app/json.html | 1 - app/scripts.babel/json.js | 6 +++++- gulpfile.babel.js | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/json.html b/app/json.html index 289dc9ef..4501b2f2 100644 --- a/app/json.html +++ b/app/json.html @@ -15,7 +15,6 @@ - diff --git a/app/scripts.babel/json.js b/app/scripts.babel/json.js index f5a8b110..85b92fc3 100644 --- a/app/scripts.babel/json.js +++ b/app/scripts.babel/json.js @@ -17,6 +17,10 @@ limitations under the License. $(() => { chrome.runtime.getBackgroundPage((bkg) => { document.getElementById('json-string').textContent = bkg._text; - hljs.initHighlighting(); + try { + hljs.initHighlighting(); + } catch (e) { + console.log('Sorry! JSON highlighting only available in Chrome.'); + } }); }); diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 1735a377..e38dce24 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -124,6 +124,10 @@ function prependScript(node, file) { node.prepend(``); } +function appendScript(node, file) { + node.append(``); +} + gulp.task('lint', lint([ 'app/scripts.babel/*.js', 'app/vendor.babel/**/*.js', @@ -136,6 +140,7 @@ gulp.task('extras', () => { 'app/*.*', 'app/_locales/**', 'app/libs/**', + '!app/libs/highlight.js', '!app/vendor.babel', '!app/scripts.babel', '!app/*.json', @@ -197,6 +202,7 @@ gulp.task('build:chrome', ['build:base'], (done) => { } gulp.src(dist('base', '**/*')) .pipe(filter(['**', '!**/about.html'])) + .pipe(filter(['**', '!**/json.html'])) .pipe(gulp.dest(dist('chrome'))); gulp.src(dist('base', 'about.html')) @@ -207,6 +213,15 @@ gulp.task('build:chrome', ['build:base'], (done) => { })) .pipe(gulp.dest(dist('chrome'))); + gulp.src(dist('base', 'json.html')) + .pipe(cheerio(($) => { + const $body = $('body'); + appendScript($body, 'libs/highlight.js'); + })) + .pipe(gulp.dest(dist('chrome'))); + + gulp.src('app/libs/highlight.js').pipe(gulp.dest(dist('chrome/libs'))); + util.log(`Building Chrome Extension: ${version}`); gulp.src('app/vendor/chrome/manifest.json') @@ -233,6 +248,15 @@ gulp.task('build:sinon-chrome', ['build:chrome'], () => { .pipe(filter(['**', '!**/es-reindex.html'])) .pipe(gulp.dest(dist(target))); + gulp.src(dist('base', 'json.html')) + .pipe(cheerio(($) => { + const $body = $('body'); + appendScript($body, 'libs/highlight.js'); + })) + .pipe(gulp.dest(dist('chrome'))); + + gulp.src('app/libs/highlight.js').pipe(gulp.dest(dist('chrome/libs'))); + // Add sinon-chrome.min script gulp.src(require.resolve('sinon-chrome/bundle/sinon-chrome.min.js')) .pipe(gulp.dest(dist(target, 'scripts'))) @@ -251,7 +275,7 @@ gulp.task('build:sinon-chrome', ['build:chrome'], () => { const $head = $('head'); // !! Order matters; as we use `prepend`, last added will be first. prependScript($head, 'scripts/background.js'); - prependScript($head, 'scripts/injecter.js') + prependScript($head, 'scripts/injecter.js'); prependScript($head, 'scripts/sinon-chrome.min.js'); })) .pipe(gulp.dest(dist(target))); @@ -261,7 +285,7 @@ gulp.task('build:sinon-chrome', ['build:chrome'], () => { const $head = $('head'); // !! Order matters; as we use `prepend`, last added will be first. prependScript($head, 'scripts/background.js'); - prependScript($head, 'scripts/injecter.js') + prependScript($head, 'scripts/injecter.js'); prependScript($head, 'scripts/sinon-chrome.min.js'); const date = new Date().getFullYear(); $('#version').text(`Version ${version}`);