You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.3 KiB
83 lines
2.3 KiB
#!/usr/bin/env node
|
|
|
|
let app
|
|
const fs = require('fs')
|
|
const fileType = require('../node_modules/file-type')
|
|
const readChunk = require('../node_modules/read-chunk')
|
|
const isSvg = require('../node_modules/is-svg')
|
|
const json = require('../src/apps.json')
|
|
|
|
const basePath = 'src/drivers/webextension/images/icons/'
|
|
|
|
const iconPaths = [] // Will be used to check for stray icons
|
|
|
|
for (app in json.apps) {
|
|
;(function(app) {
|
|
const iconPath = json.apps[app].icon || 'default.svg'
|
|
const path = basePath + iconPath
|
|
const 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/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)
|
|
}
|
|
}
|
|
})
|