|
|
|
@ -6,23 +6,45 @@ var
|
|
|
|
|
fs = require('fs'),
|
|
|
|
|
fileType = require(modulesPath + 'file-type'),
|
|
|
|
|
readChunk = require(modulesPath + 'read-chunk')
|
|
|
|
|
isSvg = require(modulesPath + 'is-svg')
|
|
|
|
|
json = require(process.env.WAPPALYZER_ROOT + '/src/apps.json');
|
|
|
|
|
|
|
|
|
|
for ( app in json.apps ) {
|
|
|
|
|
for (app in json.apps) {
|
|
|
|
|
(function(app) {
|
|
|
|
|
var path = process.env.WAPPALYZER_ROOT + '/src/icons/' + app + '.png';
|
|
|
|
|
var basePath = process.env.WAPPALYZER_ROOT + '/src/icons/';
|
|
|
|
|
var iconPath = json.apps[app].icon;
|
|
|
|
|
var path = basePath + iconPath;
|
|
|
|
|
|
|
|
|
|
fs.exists(path, function(exists) {
|
|
|
|
|
var buffer;
|
|
|
|
|
|
|
|
|
|
if ( exists ) {
|
|
|
|
|
buffer = fileType(readChunk.sync(path, 0, 262));
|
|
|
|
|
var type;
|
|
|
|
|
if (path.substr(path.length - 4) === '.png') {
|
|
|
|
|
type = "PNG";
|
|
|
|
|
}
|
|
|
|
|
else if (path.substr(path.length - 4) === '.svg') {
|
|
|
|
|
type = "SVG";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var err = new Error('Icon file extension specified for app "' + app + '" is not ".png" or ".svg": src/icons/' + iconPath);
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( buffer.mime !== 'image/png' ) {
|
|
|
|
|
throw new Error('Incorrect mimetype "' + buffer.mime + '": src/icons/' + app + '.png');
|
|
|
|
|
fs.exists(path, function(exists) {
|
|
|
|
|
if (exists) {
|
|
|
|
|
if (type === "PNG") {
|
|
|
|
|
var buffer = fileType(readChunk.sync(path, 0, 262));
|
|
|
|
|
if (buffer.mime !== 'image/png') {
|
|
|
|
|
var err = new Error('Incorrect mimetype "' + buffer.mime + '" when expected PNG for app "' + app + '": src/icons/' + iconPath);
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (type === "SVG") {
|
|
|
|
|
if (!isSvg(fs.readFileSync(path))) {
|
|
|
|
|
var err = new Error('Incorrect mimetype when expected SVG for app "' + app + '": src/icons/' + iconPath);
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Missing file: src/icons/' + app + '.png');
|
|
|
|
|
var err = new Error('Missing file for app "' + app + '": src/icons/' + iconPath);
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}(app));
|
|
|
|
|