forked from liorgrossman/darkness
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50cf191
commit f11c506
Showing
5 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 == '[email protected]') 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 == '[email protected]') ENVIRONMENT = 'development'; | ||
|
||
// Staging (local testing before depoyment to stores) | ||
if (chrome.runtime.id == 'blbbhmfjigkmkkobabbgppbhaaeehfjn') ENVIRONMENT = 'staging'; | ||
if (chrome.runtime.id == '[email protected]') ENVIRONMENT = 'staging'; | ||
|
||
//---------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Global vars | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]', | ||
staging: '[email protected]', | ||
production: '[email protected]', | ||
} | ||
|
||
var manifestJson = JSON.parse(fs.readFileSync(chromeDevelopmentDir + '/manifest.json')); | ||
|
||
//---------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
@@ -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)); | ||
|
@@ -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 | ||
//---------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters