@ -1,60 +1,82 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var
|
let app
|
||||||
app,
|
const fs = require('fs')
|
||||||
fs = require('fs'),
|
const fileType = require('../node_modules/file-type')
|
||||||
fileType = require('../node_modules/file-type'),
|
const readChunk = require('../node_modules/read-chunk')
|
||||||
readChunk = require('../node_modules/read-chunk'),
|
const isSvg = require('../node_modules/is-svg')
|
||||||
isSvg = require('../node_modules/is-svg'),
|
const json = require('../src/apps.json')
|
||||||
json = require('../src/apps.json'),
|
|
||||||
|
|
||||||
basePath = 'src/icons/',
|
const basePath = 'src/drivers/webextension/images/icons/'
|
||||||
|
|
||||||
iconPaths = [];//Will be used to check for stray icons
|
|
||||||
|
|
||||||
|
const iconPaths = [] // Will be used to check for stray icons
|
||||||
|
|
||||||
for (app in json.apps) {
|
for (app in json.apps) {
|
||||||
(function(app) {
|
;(function(app) {
|
||||||
var
|
const iconPath = json.apps[app].icon || 'default.svg'
|
||||||
iconPath = json.apps[app].icon || 'default.svg',
|
const path = basePath + iconPath
|
||||||
path = basePath + iconPath,
|
const ext = iconPath.substr(iconPath.length - 4)
|
||||||
ext = iconPath.substr(iconPath.length - 4);
|
|
||||||
|
|
||||||
iconPaths.push(iconPath)
|
|
||||||
|
|
||||||
if ( ext !== '.png' && ext !== '.svg' ) {
|
|
||||||
throw err = new Error('Icon file extension specified for app "' + app + '" is not ".png" or ".svg": src/icons/' + iconPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.exists(path, function(exists) {
|
|
||||||
if ( exists ) {
|
|
||||||
if ( ext === '.png' ) {
|
|
||||||
var buffer = fileType(readChunk.sync(path, 0, 262));
|
|
||||||
|
|
||||||
if ( buffer === null ) {
|
|
||||||
throw new Error('Unknown mimetype or bad file for "' + app + '": src/icons/' + iconPath);
|
|
||||||
} else if ( buffer.mime !== 'image/png' ) {
|
|
||||||
throw new Error('Incorrect mimetype "' + buffer.mime + '" when expected PNG for app "' + app + '": src/icons/' + iconPath);
|
|
||||||
}
|
|
||||||
} else if ( ext === '.svg' ) {
|
|
||||||
if ( !isSvg(fs.readFileSync(path)) ) {
|
|
||||||
throw new Error('Incorrect mimetype when expected SVG for app "' + app + '": src/icons/' + iconPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw Error('Missing file for app "' + app + '": src/icons/' + iconPath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
iconPaths.push(iconPath)
|
||||||
|
|
||||||
// Check for stray files in icons folder
|
if (ext !== '.png' && ext !== '.svg') {
|
||||||
fs.readdirSync(basePath).forEach(function(file) {
|
throw (err = new Error(
|
||||||
if (!fs.statSync(basePath + file).isDirectory()) {
|
'Icon file extension specified for app "' +
|
||||||
if(iconPaths.indexOf(file) === -1){
|
app +
|
||||||
throw new Error('Stray file (no associated app): ' + basePath + file);
|
'" is not ".png" or ".svg": src/drivers/webextension/images/icons/' +
|
||||||
}
|
iconPath
|
||||||
}
|
))
|
||||||
});
|
}
|
||||||
|
|
||||||
|
fs.exists(path, function(exists) {
|
||||||
|
if (exists) {
|
||||||
|
if (ext === '.png') {
|
||||||
|
const buffer = fileType(readChunk.sync(path, 0, 262))
|
||||||
|
|
||||||
|
if (buffer === null) {
|
||||||
|
throw new Error(
|
||||||
|
'Unknown mimetype or bad file for "' +
|
||||||
|
app +
|
||||||
|
'": src/drivers/webextension/images/icons/' +
|
||||||
|
iconPath
|
||||||
|
)
|
||||||
|
} else if (buffer.mime !== 'image/png') {
|
||||||
|
throw new Error(
|
||||||
|
'Incorrect mimetype "' +
|
||||||
|
buffer.mime +
|
||||||
|
'" when expected PNG for app "' +
|
||||||
|
app +
|
||||||
|
'": src/drivers/webextension/images/icons/' +
|
||||||
|
iconPath
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (ext === '.svg') {
|
||||||
|
if (!isSvg(fs.readFileSync(path))) {
|
||||||
|
throw new Error(
|
||||||
|
'Incorrect mimetype when expected SVG for app "' +
|
||||||
|
app +
|
||||||
|
'": src/drivers/webextension/images/icons/' +
|
||||||
|
iconPath
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
'Missing file for app "' +
|
||||||
|
app +
|
||||||
|
'": src/drivers/webextension/images/icons/' +
|
||||||
|
iconPath
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})(app)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for stray files in icons folder
|
||||||
|
fs.readdirSync(basePath).forEach(function(file) {
|
||||||
|
if (!fs.statSync(basePath + file).isDirectory()) {
|
||||||
|
if (!iconPaths.includes(file)) {
|
||||||
|
throw new Error('Stray file (no associated app): ' + basePath + file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ -1 +0,0 @@
|
|||||||
../../../icons/
|
|
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 504 B |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 473 B |
Before Width: | Height: | Size: 796 B |
Before Width: | Height: | Size: 499 B |
Before Width: | Height: | Size: 649 B |
Before Width: | Height: | Size: 608 B |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 299 B |
Before Width: | Height: | Size: 307 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 396 B |
Before Width: | Height: | Size: 249 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 374 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 844 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 472 B |
Before Width: | Height: | Size: 831 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 498 B |
Before Width: | Height: | Size: 485 B |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 901 B |
Before Width: | Height: | Size: 205 B |
Before Width: | Height: | Size: 607 B |
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 454 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 567 B |
Before Width: | Height: | Size: 347 B |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 345 B |
Before Width: | Height: | Size: 326 B |
Before Width: | Height: | Size: 733 B |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 566 B |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 227 B |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 356 B |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 131 B |
Before Width: | Height: | Size: 912 B |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 814 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 920 B |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 742 B |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 128 B |
Before Width: | Height: | Size: 617 B |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 132 B |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 254 B |
Before Width: | Height: | Size: 755 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 750 B |
Before Width: | Height: | Size: 184 B |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 218 B |
Before Width: | Height: | Size: 261 B |
Before Width: | Height: | Size: 950 B |
Before Width: | Height: | Size: 1.8 KiB |