#!/usr/bin/env node var app, fs = require('fs'), fileType = require('../node_modules/file-type'), readChunk = require('../node_modules/read-chunk') isSvg = require('../node_modules/is-svg') json = require('../src/apps.json'); for (app in json.apps) { (function(app) { var basePath = 'src/icons/'; iconPath = json.apps[app].icon || 'default.svg'; path = basePath + iconPath, ext = iconPath.substr(iconPath.length - 4); 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)); }