-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul code structure and build process and add support for Firefox
- Loading branch information
Showing
28 changed files
with
3,612 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea/ | ||
dist_*/ | ||
dists/ | ||
node_modules/ | ||
package-lock.json | ||
yarn-error.log | ||
*.zip |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
12.18.0 |
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 |
---|---|---|
@@ -1,55 +1,130 @@ | ||
const webpackConfigFn = require('./webpack.config.js'); | ||
|
||
module.exports = function(grunt) { | ||
var EDITIONS = ['lite', 'beta', 'staging', 'power_user']; | ||
const EDITIONS = ['beta', 'staging', 'production']; | ||
const BROWSERS = ['chrome', 'firefox']; | ||
|
||
var edition = grunt.option('edition'); | ||
if (EDITIONS.indexOf(edition) === -1) { | ||
throw 'No extension specified. Should be one of: ' + EDITIONS; | ||
const edition = grunt.option('edition'); | ||
const browser = grunt.option('browser'); | ||
const instanceUrl = grunt.option('instance'); | ||
try { | ||
if (!EDITIONS.includes(edition)) { | ||
throw 'No edition specified. Should be one of: ' + EDITIONS; | ||
} | ||
if (!BROWSERS.includes(browser)) { | ||
throw 'No browser specified. Should be one of: ' + BROWSERS; | ||
} | ||
if (!instanceUrl) { | ||
throw 'No instance provided, such as "https://trot.to"'; | ||
} | ||
} catch (e) { | ||
grunt.log.error(e); | ||
|
||
grunt.fail.warn('Encountered error. Example usage:' + | ||
' yarn dev --edition=production --browser=chrome --instance=https://trot.to'); | ||
} | ||
|
||
var outputDir = 'dist_' + edition + '/'; | ||
const outputDir = `dists/dist_${edition}_${browser}/`; | ||
const zipPath = outputDir.slice(0, outputDir.length - 1) + '.zip'; | ||
|
||
const webpackConfig = webpackConfigFn('', { | ||
distDir: outputDir, | ||
edition, | ||
browser, | ||
instanceUrl | ||
}); | ||
|
||
const webpackOptions = { | ||
stats: !process.env.NODE_ENV || process.env.NODE_ENV === 'development', | ||
mode: process.env.NODE_ENV || 'development' | ||
}; | ||
|
||
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') { | ||
// ensure dev webpack output doesn't use eval as that won't allow the dev extension to be loaded without messing | ||
// with manifest.json | ||
webpackOptions.devtool = 'source-map'; | ||
} else { | ||
// Don't minimize when building to production in order to simplify review by browser teams. Performance impact | ||
// should be immaterial. | ||
webpackOptions.optimization = { minimize: false }; | ||
} | ||
|
||
var config = { | ||
pkg: grunt.file.readJSON('package.json'), | ||
|
||
clean: { | ||
output_dir: { | ||
src: [ | ||
outputDir + '**', | ||
zipPath | ||
] | ||
} | ||
}, | ||
copy: { | ||
main: { | ||
files: [ | ||
{expand: true, cwd: 'src', src: '**', dest: outputDir}, | ||
{expand: true, cwd: 'editions/' + edition, src: 'icon.png', dest: outputDir} | ||
{expand: true, cwd: 'src', src: '**/*.{html,png,json}', dest: outputDir}, | ||
{expand: true, cwd: 'editions/' + edition, src: 'icon*.png', dest: outputDir} | ||
] | ||
} | ||
}, | ||
update_json: { | ||
manifest_file: { | ||
src: 'editions/' + edition + '/manifest_overrides.json', | ||
src: [ | ||
`editions/${edition}/manifest_overrides.json`, | ||
`editions/${edition}/${browser}/manifest_overrides.json` | ||
], | ||
dest: outputDir + 'manifest.json', | ||
fields: ['name', 'version', 'description', 'permissions', 'optional_permissions', 'storage'] | ||
} | ||
}, | ||
zip: {}, | ||
webpack: { | ||
options: webpackOptions, | ||
prod: webpackConfig, | ||
dev: Object.assign({ watch: true }, webpackConfig) | ||
}, | ||
concurrent: { | ||
dev: { | ||
tasks: ['watch:other_assets', 'webpack:dev'], | ||
options: { | ||
logConcurrentOutput: true | ||
} | ||
} | ||
}, | ||
watch: { | ||
scripts: { | ||
files: ['src/**'], | ||
tasks: ['build-dist'], | ||
other_assets: { | ||
files: [ | ||
'src/*.{html,png,json}', | ||
'editions/**' | ||
], | ||
tasks: ['build_other'], | ||
options: { | ||
spawn: false | ||
} | ||
} | ||
}, | ||
zip: { | ||
'extension': { | ||
cwd: outputDir, | ||
src: outputDir + '*', | ||
dest: zipPath | ||
} | ||
} | ||
}; | ||
|
||
config.zip[outputDir.replace('/', '.zip')] = outputDir + '*'; | ||
|
||
grunt.initConfig(config); | ||
|
||
grunt.loadNpmTasks('grunt-webpack'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-update-json'); | ||
grunt.loadNpmTasks('grunt-zip'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-concurrent'); | ||
|
||
grunt.registerTask('build-dist', function() { | ||
grunt.task.run('copy', 'update_json', 'zip'); | ||
}); | ||
grunt.registerTask('build_other', ['copy', 'update_json']); | ||
|
||
grunt.registerTask('build_dist', ['clean', 'build_other', 'webpack:prod', 'zip:extension']); | ||
|
||
grunt.registerTask('default', ['build-dist', 'watch']); | ||
grunt.registerTask('default', ['clean', 'build_other', 'concurrent:dev']); | ||
}; |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"description": "This extension makes Trotto \"go links\" work seamlessly in Firefox." | ||
} |
4 changes: 2 additions & 2 deletions
4
editions/lite/manifest_overrides.json → editions/production/manifest_overrides.json
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "Trotto Go Links", | ||
"version": "1.21", | ||
"name": "Trotto go links", | ||
"version": "1.23", | ||
"description": "This extension makes Trotto \"go links\" work seamlessly in Chrome." | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "Trotto Go Links [STAGING]", | ||
"version": "1.1", | ||
"version": "1.3", | ||
"description": "Staging version of the Trotto Go Links extension." | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const browser = require('webextension-polyfill'); | ||
|
||
|
||
export class Api { | ||
constructor() { | ||
this.runtime = { | ||
onInstalled: { | ||
// note: this doesn't work: `addListener: chrome.runtime.onInstalled.addListener` | ||
addListener: (callback) => chrome.runtime.onInstalled.addListener(callback) | ||
} | ||
}; | ||
|
||
this.storage = { | ||
onChanged: { | ||
addListener: (callback) => chrome.storage.onChanged.addListener(callback) | ||
}, | ||
managed: { | ||
get: browser.storage.managed.get | ||
} | ||
}; | ||
|
||
this.webRequest = { | ||
onBeforeRequest: browser.webRequest.onBeforeRequest | ||
}; | ||
|
||
this.tabs = { | ||
query: browser.tabs.query, | ||
create: browser.tabs.create, | ||
remove: browser.tabs.remove, | ||
update: browser.tabs.update, | ||
onUpdated: { | ||
addListener: (callback) => browser.tabs.onUpdated.addListener(callback) | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.