Commit 54e449d0 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Check that no unused logos are present;

parent 78331cd8
/* eslint no-process-exit: 0 */
import * as path from 'path-extra';
import * as fs from 'fs';
import banks from '../shared/banks.json';
let log = require('printit')({
prefix: 'check-logos'
});
......@@ -12,19 +15,45 @@ let imagesDir = path.join(path.dirname(fs.realpathSync(__filename)),
'images',
'banks');
let allLogoHere = true;
let missingLogo = false;
for (let bank of banks) {
try {
let imagePath = path.join(imagesDir, `${bank.uuid}.png`);
fs.accessSync(imagePath, fs.F_OK);
} catch (e) {
log.error(`${bank.uuid} : there is no logo for this module/bank`);
allLogoHere = false;
log.error(`Missing logo for ${bank.uuid}.`);
missingLogo = true;
}
}
if (missingLogo) {
log.error('At least one missing logo.');
process.exit(1);
}
let imageFiles = [];
fs.readdirSync(imagesDir).forEach(child => {
let file = path.join(imagesDir, child);
if (fs.statSync(file).isDirectory()) {
log.error("The images dir shouldn't contain a directory!");
process.exit(1);
}
let cleanName = child.replace('.png', '');
imageFiles.push(cleanName);
});
let bankSet = new Set(banks.map(bank => bank.uuid));
let orphanImage = false;
for (let file of imageFiles) {
if (!bankSet.has(file)) {
log.error(`Superfluous logo in the logo directory: ${file}.`);
orphanImage = true;
}
}
if (!allLogoHere) {
if (orphanImage) {
log.error('At least one orphan image.');
process.exit(1);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment