Skip to content

Commit

Permalink
Ability to provide environment variables to service worker.
Browse files Browse the repository at this point in the history
  • Loading branch information
bourquep committed Oct 26, 2016
1 parent ff4b393 commit 2077ad7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var BroccoliServiceWorker = function BroccoliServiceWorker(inTree, options) {
}
this.swIncludeTree = options.swIncludeTree;
this.swIncludeFiles = options.swIncludeFiles;
this.swEnvironment = options.swEnvironment || {};
};

BroccoliServiceWorker.prototype = Object.create(brocWriter.prototype);
Expand All @@ -60,10 +61,12 @@ BroccoliServiceWorker.prototype.write = function(readTree, destDir) {
});
var swIncludeFiles = this.swIncludeFiles;
var swIncludeTree = this.swIncludeTree;
var swEnvironment = this.swEnvironment;

return readSwIncludeTree(readTree, this.swIncludeTree).then(function(swIncludeDir){
return readTree(serviceWorkerTree).then(function (srcDir) {
var lines = [];
lines.push("var swEnvironment = " + JSON.stringify(swEnvironment) + ";");
lines.push("importScripts('"+toolboxLocation+"');");
lines.push("var CACHE_PREFIX = 'brocsw-v';");
lines.push("var CACHE_VERSION = CACHE_PREFIX+'"+(new Date()).getTime()+"';");
Expand Down

0 comments on commit 2077ad7

Please sign in to comment.