Skip to content

Commit

Permalink
Porting Darkness to work on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgrossman committed Jul 4, 2018
1 parent 50cf191 commit f11c506
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,9 @@
# Ignores specific to Darkness
/chrome-production
/chrome-zips
/firefox-extension
/firefox-production
/firefox-zips
*.zip
/.idea

Expand Down
1 change: 1 addition & 0 deletions chrome-extension/js/background/file-reader.js
Expand Up @@ -29,6 +29,7 @@ var _readFileUsingHttp = function(debug, filename, callback) {
}
}
};
httpRequest.responseType = 'text';
httpRequest.open('GET', url);
httpRequest.send();
};
Expand Down
11 changes: 8 additions & 3 deletions chrome-extension/js/background/helpers.js
Expand Up @@ -5,10 +5,15 @@ var ENVIRONMENT = 'development';

// Important - don't touch this:
if (chrome.runtime.id == 'imilbobhamcfahccagbncamhpnbkaenm') ENVIRONMENT = 'production'; // Chrome Web Store version
if (chrome.runtime.id == 'darkness@darkness.app') ENVIRONMENT = 'production'; // Firefox Add-on Store version

// Local testing versions
if (chrome.runtime.id == 'koobfbhnpdijhobcdllfkmlgngbpgjep') ENVIRONMENT = 'development'; // Local version (development)
if (chrome.runtime.id == 'blbbhmfjigkmkkobabbgppbhaaeehfjn') ENVIRONMENT = 'staging'; // Local testing version before deploying (staging)
// Development version
if (chrome.runtime.id == 'koobfbhnpdijhobcdllfkmlgngbpgjep') ENVIRONMENT = 'development';
if (chrome.runtime.id == 'development@darkness.app') ENVIRONMENT = 'development';

// Staging (local testing before depoyment to stores)
if (chrome.runtime.id == 'blbbhmfjigkmkkobabbgppbhaaeehfjn') ENVIRONMENT = 'staging';
if (chrome.runtime.id == 'staging@darkness.app') ENVIRONMENT = 'staging';

//----------------------------------------------------------------------------------------------------------------------------------------------------
// Global vars
Expand Down
134 changes: 129 additions & 5 deletions gulpfile.js
Expand Up @@ -8,11 +8,25 @@ var gutil = require('gulp-util');
var rename = require('gulp-rename');
var del = require('del');
var zip = require('gulp-zip');
var jsonTransform = require('gulp-json-transform');
var replace = require('gulp-replace');

const zipFilename = 'Darkness-CWS-latest.zip';
const chromeDevelopmentDir = 'chrome-extension';
const chromeProductionDir = 'chrome-production';
const chromeZipsDir = 'chrome-zips';
const chromeZipFilename = 'Darkness-CWS-latest.zip';

const firefoxDevelopmentDir = 'firefox-extension';
const firefoxProductionDir = 'firefox-production';
const firefoxZipsDir = 'firefox-zips';
const firefoxZipFilename = 'Darkness-FF-latest.zip';

const firefoxAddonIds = {
development: 'development@darkness.app',
staging: 'staging@darkness.app',
production: 'darkness@darkness.app',
}

var manifestJson = JSON.parse(fs.readFileSync(chromeDevelopmentDir + '/manifest.json'));

//----------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -35,7 +49,7 @@ function fileExists(filePath) {
gulp.task('cws:replicate', function() {
gutil.log("Replicate started");
// Delete any existing production dir
var deletedFiles = del.sync([chromeProductionDir, chromeZipsDir + '/' + zipFilename], { force: true, dryRun: false });
var deletedFiles = del.sync([chromeProductionDir, chromeZipsDir + '/' + chromeZipFilename], { force: true, dryRun: false });
for (var i in deletedFiles) gutil.log("Deleted: ", deletedFiles[i]);
// Copy dev dir recursively to production dir
return gulp.src([chromeDevelopmentDir + '/**/*']).pipe(gulp.dest(chromeProductionDir));
Expand All @@ -62,21 +76,131 @@ gulp.task('cws:zip', ['cws:cleanup'], function() {
gutil.log("Zipping...");
// Create a zip file
return gulp.src(chromeProductionDir + '/**/*')
.pipe(zip(zipFilename))
.pipe(zip(chromeZipFilename))
.pipe(gulp.dest(chromeZipsDir));
});

// Zip the production directory
// Copy and name the zip file
gulp.task('cws:archive', ['cws:zip'], function() {
var archiveFilename = 'Darkness-CWS-v' + manifestJson.version + '_(' + (new Date()).toISOString().slice(0, 19).replace('T', '__').replace(/:/g, '-') + ').zip';
gutil.log("Copying to archive: " + archiveFilename);
// Copy to archive
return gulp.src(chromeZipsDir + '/' + zipFilename).pipe(rename(archiveFilename)).pipe(gulp.dest(chromeZipsDir));
return gulp.src(chromeZipsDir + '/' + chromeZipFilename).pipe(rename(archiveFilename)).pipe(gulp.dest(chromeZipsDir));
});

gulp.task('cws', ['cws:replicate', 'cws:cleanup', 'cws:zip', 'cws:archive']);
gulp.task('precws', ['cws:replicate', 'cws:cleanup']);


//----------------------------------------------------------------------------------------------------------------------------------------------------
// Preapre a ZIP that is uploaded to Firefox Addon store:
//----------------------------------------------------------------------------------------------------------------------------------------------------

// Replicate dev to production
gulp.task('ffa:replicate', function() {
gutil.log("Replicate started");
// Delete any existing production dir
var deletedFiles = del.sync([firefoxProductionDir, firefoxZipsDir + '/' + firefoxZipFilename], { force: true, dryRun: false });
for (var i in deletedFiles) gutil.log("Deleted: ", deletedFiles[i]);
// Copy dev dir recursively to production dir
return gulp.src([firefoxDevelopmentDir + '/**/*']).pipe(gulp.dest(firefoxProductionDir));
});

gulp.task('ffa:manifest', ['ffa:replicate'], function() {
return gulp.src(firefoxProductionDir + '/manifest.json')
.pipe(jsonTransform(function(manifest, file) {
// Transform the Firefox manifest from dev to production
manifest.applications = {
gecko: {
id: firefoxAddonIds.production
}
};
return manifest;
}, "\t"))
.pipe(gulp.dest(firefoxProductionDir));
});

// Clean up unnecessary files
gulp.task('ffa:cleanup', ['ffa:manifest'], function() {
gutil.log("Cleanup started");
var deletedFiles = del.sync(
[firefoxProductionDir + '/themes',
firefoxProductionDir + '/style'
], { force: true, dryRun: false });
for (var i in deletedFiles) gutil.log("Deleted directory: ", deletedFiles[i]);

deletedFiles = del.sync(
[firefoxProductionDir + '/**/*.scss',
firefoxProductionDir + '/**/*.map'
], { force: true, dryRun: false });
for (var i in deletedFiles) gutil.log("Deleted file: ", deletedFiles[i]);
});

// Zip the production directory
gulp.task('ffa:zip', ['ffa:cleanup'], function() {
gutil.log("Zipping...");
// Create a zip file
return gulp.src(firefoxProductionDir + '/**/*')
.pipe(zip(firefoxZipFilename))
.pipe(gulp.dest(firefoxZipsDir));
});

// Copy and name the zip file
gulp.task('ffa:archive', ['ffa:zip'], function() {
var archiveFilename = 'Darkness-FF-v' + manifestJson.version + '_(' + (new Date()).toISOString().slice(0, 19).replace('T', '__').replace(/:/g, '-') + ').zip';
gutil.log("Copying to archive: " + archiveFilename);
// Copy to archive
return gulp.src(firefoxZipsDir + '/' + firefoxZipFilename).pipe(rename(archiveFilename)).pipe(gulp.dest(firefoxZipsDir));
});

gulp.task('ffa', ['ffa:replicate', 'ffa:cleanup', 'ffa:zip', 'ffa:archive']);
gulp.task('preffa', ['ffa:replicate', 'ffa:cleanup']);


//----------------------------------------------------------------------------------------------------------------------------------------------------
// Port Darkness Chrome Extension to a Firefox add-on
//----------------------------------------------------------------------------------------------------------------------------------------------------

// Replicate dev to production
gulp.task('ff:replicate', function() {
gutil.log("Replicate to Firefox started");
// Delete any existing production dir
var deletedFiles = del.sync([firefoxDevelopmentDir], { force: true, dryRun: false });
for (var i in deletedFiles) gutil.log("Deleted: ", deletedFiles[i]);
// Copy dev dir recursively to production dir
return gulp.src([chromeDevelopmentDir + '/**/*']).pipe(gulp.dest(firefoxDevelopmentDir));
});

gulp.task('ff:manifest', ['ff:replicate'], function() {
return gulp.src(firefoxDevelopmentDir + '/manifest.json')
.pipe(jsonTransform(function(manifest, file) {
// Transform the Chrome manifest to a Firefox manifest
delete manifest.background.persistent;
delete manifest.options_page;
manifest.applications = {
gecko: {
id: firefoxAddonIds.development
}
};
return manifest;
}, "\t"))
.pipe(gulp.dest(firefoxDevelopmentDir));
});


gulp.task('ff:replace', ['ff:manifest'], function() {
return gulp.src([
firefoxDevelopmentDir + '/**/*.js',
firefoxDevelopmentDir + '/**/*.css',
firefoxDevelopmentDir + '/**/*.scss',
firefoxDevelopmentDir + '/**/*.html',
])
.pipe(replace(/chrome-extension:\/\//g, 'moz-extension://'))
.pipe(gulp.dest(firefoxDevelopmentDir));
});

gulp.task('ff', ['ff:replicate', 'ff:manifest', 'ff:replace']);

//----------------------------------------------------------------------------------------------------------------------------------------------------
// SASS compilation
//----------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"del": "2.2.1",
"gulp": "3.9.1",
"gulp-json-transform": "0.4.5",
"gulp-rename": "1.2.2",
"gulp-replace": "0.5.4",
"gulp-sass": "4.0.0",
Expand Down

0 comments on commit f11c506

Please sign in to comment.