Skip to content

Commit

Permalink
Merge pull request #188 from matatk/sidebar
Browse files Browse the repository at this point in the history
Sidebar
  • Loading branch information
matatk committed Jul 30, 2018
2 parents eed0ef4 + 696558e commit 20672ff
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 74 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ This is a fork of the [original landmarks extension](https://github.com/davidtod
Changes
-------

- 2.4.0 - in development
- Show the current keyboard commands on the splash page and allow the user to update them on Chrome and Opera. \[[\#187](https://github.com/matatk/landmarks/pull/187)\]
- Offer an optional sidebar instead of the pop-up on Firefox and Opera. \[[\#188](https://github.com/matatk/landmarks/pull/188)\]
- 2.3.1 - 9th of June 2018
- Support multiple labelling elements when `aria-labelledby` is used. \[[\#176](https://github.com/matatk/landmarks/pull/176)\]
- Keep labels legible, and borders neat, when landmark regions are narrow, or full-width/height. Also let pointer events through the border so the user can interact as normal with the page below. \[[\#179](https://github.com/matatk/landmarks/pull/179)\]
Expand Down
162 changes: 98 additions & 64 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const srcStaticDir = path.join('src', 'static')
const srcAssembleDir = path.join('src', 'assemble')
const svgPath = path.join(srcAssembleDir, 'landmarks.svg')
const pngCacheDir = path.join(buildDir, 'png-cache')
const localeSubPath = path.join('_locales', 'en_GB')
const messagesSubPath = path.join(localeSubPath, 'messages.json')

const validBrowsers = Object.freeze([
'firefox',
Expand All @@ -28,52 +30,51 @@ const buildTargets = Object.freeze(validBrowsers.concat(['all']))

const browserPngSizes = Object.freeze({
'firefox': [
18, // Firefox (toolbar)
32, // Firefox (menu panel) + Chrome (Windows)
36, // Firefox (toolbar x2)
48, // Both (general)
64, // Firefox (menu panel x2)
96 // Firefox (general x2)
18, // Firefox (toolbar)
32, // Firefox (menu panel) + Chrome (Windows)
36, // Firefox (toolbar x2)
48, // Both (general)
64, // Firefox (menu panel x2)
96 // Firefox (general x2)
],
'chrome': [
16, // Chrome (favicon)
19, // Chrome (toolbar)
32, // Chrome (Windows) + Firefox (menu panel)
38, // Chrome (tooblar x2)
48, // Both (general)
128 // Chrome (store)
16, // Chrome (favicon)
19, // Chrome (toolbar)
32, // Chrome (Windows) + Firefox (menu panel)
38, // Chrome (tooblar x2)
48, // Both (general)
128 // Chrome (store)
],
'opera': [
// https://dev.opera.com/extensions/manifest/#icons
// https://dev.opera.com/extensions/browser-actions/
16, // Icon
19, // Browser action
38, // Browser action
48, // Icon
128, // Icon
16, // Icon
19, // Browser action
38, // Browser action
48, // Icon
128, // Icon
],
'edge': [
// https://docs.microsoft.com/en-us/microsoft-edge/extensions/guides/design
20, // Normal browser action
40, // 2x browser action
24, // Management UI
48, // 2x Management UI
44, // Windows UI (App List, Settings -> System -> Apps & features
50, // Packaging requirement (not visible anywhere)
150 // Icon for Windows Store
20, // Normal browser action
40, // 2x browser action
24, // Management UI
48, // 2x Management UI
44, // Windows UI (App List, Settings -> System -> Apps & features
50, // Packaging requirement (not visible anywhere)
150 // Icon for Windows Store
]
})

const linters = Object.freeze({
'firefox': lintFirefox
})

let testMode = false // are we building a test (alpha/beta) version?
let testMode = false // are we building a test (alpha/beta) version?


function error() {
const argStrings = [...arguments].map((x) =>
typeof x === 'string' ? x : JSON.stringify(x, null, 2))
const argStrings = [...arguments].map(x => String(x))
console.error(chalk.bold.red.apply(this, ['✖'].concat(argStrings)))
process.exit(42)
}
Expand Down Expand Up @@ -116,17 +117,79 @@ function pathToBuild(browser) {
}


function checkMessages() {
logStep('Checking for unused messages (except role names)...')
function copyStaticFiles(browser) {
logStep('Copying static files...')
fse.copySync(srcStaticDir, pathToBuild(browser))

function doReplace(from, to, message) {
try {
const changes = replace.sync({
'files': path.join(pathToBuild(browser), '*.html'),
'from': from,
'to': to
})
console.log(message, changes.join(', '))
} catch (err) {
error('Error occurred:', err)
}
}

if (browser === 'firefox') {
doReplace('\n\t\t<script src="compatibility.js"></script>', '',
'Removed inclusion of compatibility.js from:')
}

if (browser === 'chrome' || browser === 'edge') {
doReplace(/<!-- ui -->[\s\S]*<!-- \/ui -->\s*/,
'',
'Removed UI options in:')
}
}


function copySpecialPagesFile(browser) {
logStep(`Copying special pages file for ${browser}...`)
fse.copySync(
path.join(srcAssembleDir, `specialPages.${browser}.js`),
path.join(pathToBuild(browser), 'specialPages.js'))
}


function mergeMessages(browser) {
logStep('Merging messages JSON files...')
const common = path.join(srcAssembleDir, 'commonMessages.json')
const destinationDir = path.join(pathToBuild(browser), localeSubPath)
const destinationFile = path.join(pathToBuild(browser), messagesSubPath)

fse.ensureDirSync(destinationDir)

if (browser === 'firefox' || browser === 'opera') {
const ui = path.join(srcAssembleDir, 'interfaceMessages.json')
const commonJson = require('../' + common) // TODO check Windows
const uiJson = require('../' + ui) // TODO check Windows
const merged = merge(commonJson, uiJson)
fs.writeFileSync(destinationFile, JSON.stringify(merged, null, 2))
} else {
// Instead of just copying the common file, write it in the same way as
// the merged one, so that diffs between builds are minimal.
const commonJson = require('../' + common)
fs.writeFileSync(destinationFile, JSON.stringify(commonJson, null, 2))
}

const translationsFile = path.join(
srcStaticDir, '_locales', 'en_GB', 'messages.json')
console.log(chalk.green(`✔ messages.json written for ${browser}.`))
}


function checkMessages(browser) {
logStep(`Checking for unused messages (except role names) on ${browser}...`)

const translationsFile = path.join(pathToBuild(browser), messagesSubPath)
const messages = JSON.parse(fs.readFileSync(translationsFile))
const files = glob.sync(path.join('src', '**'), {
nodir: true,
ignore: [translationsFile]
ignore: ['commonMessages.json', 'popupMessages.json']
})
const messageSummary = {} // count usages of each message
const messageSummary = {} // count usages of each message

for (const messageName in messages) {
messageSummary[messageName] = 0
Expand All @@ -150,34 +213,6 @@ function checkMessages() {
}


function copyStaticFiles(browser) {
logStep('Copying static files...')
fse.copySync(srcStaticDir, pathToBuild(browser))

if (browser === 'firefox') {
try {
const changes = replace.sync({
files: path.join(pathToBuild('firefox'), '*.html'),
from: '\n\t\t<script src="compatibility.js"></script>',
to: ''
})
console.log('Removed inclusion of compatibility.js from:',
changes.join(', '))
} catch (error) {
error('Error occurred:', error)
}
}
}


function copySpecialPagesFile(browser) {
logStep(`Copying special pages file for ${browser}...`)
fse.copySync(
path.join(srcAssembleDir, `specialPages.${browser}.js`),
path.join(pathToBuild(browser), 'specialPages.js'))
}


function mergeManifest(browser) {
logStep('Merging manifest.json...')
const common = path.join('..', srcAssembleDir, 'manifest.common.json')
Expand Down Expand Up @@ -326,14 +361,13 @@ function main() {
const sp = oneSvgToManySizedPngs(pngCacheDir, svgPath)
const testModeMessage = testMode ? ' (test version)' : ''

console.log()
checkMessages()

browsers.forEach((browser) => {
console.log()
logStep(chalk.bold(`Building for ${browser}${testModeMessage}...`))
copyStaticFiles(browser)
copySpecialPagesFile(browser)
mergeMessages(browser)
checkMessages(browser)
mergeManifest(browser)
copyCompatibilityShimAndContentScriptInjector(browser)
getPngs(sp, browser)
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions src/assemble/interfaceMessages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"prefsInterface": {
"message": "Show landmarks in"
},

"prefsPopup": {
"message": "Toolbar popup"
},

"prefsSidebar": {
"message": "Sidebar"
}
}
1 change: 1 addition & 0 deletions src/assemble/manifest.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": [
"sendToActiveTab.js",
"specialPages.js",
"defaults.js",
"background.js"
]
},
Expand Down
9 changes: 9 additions & 0 deletions src/assemble/manifest.firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
}
},

"sidebar_action": {
"default_title": "Landmarks",
"default_panel": "popup.html",
"default_icon": {
"32": "landmarks-32.png",
"64": "landmarks-64.png"
}
},

"options_ui": {
"browser_style": true
},
Expand Down
9 changes: 9 additions & 0 deletions src/assemble/manifest.opera.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
}
},

"sidebar_action": {
"default_title": "Landmarks",
"default_panel": "popup.html",
"default_icon": {
"19": "landmarks-19.png",
"38": "landmarks-38.png"
}
},

"options_ui": {
"chrome_style": true
},
Expand Down
Loading

0 comments on commit 20672ff

Please sign in to comment.