Skip to content

Commit

Permalink
refactor list.js
Browse files Browse the repository at this point in the history
  • Loading branch information
relliv committed Oct 24, 2021
1 parent fe717ba commit de6bbca
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const fs = require('fs');
const hostname = '127.0.0.1',
port = 2021,
sizeList = [16, 24, 32, 48, 64, 128],
baseRepoAddress = 'https://raw.githubusercontent.com/EgoistDeveloper/operating-system-logos/master';
baseRepoAddress = 'https://raw.githubusercontent.com/EgoistDeveloper/operating-system-logos/master',
previewSize = '48x48';

const server = http.createServer((req, res) => {
res.statusCode = 200;
Expand All @@ -23,35 +24,44 @@ const server = http.createServer((req, res) => {
osList = Object.entries(osList);

osList.forEach(osItem => {
const osCode = osItem[0],
osName = osItem[1];

let logoStackCount = 0,
missingSizes = [];

// count exists and missing images for target logo
sizeList.forEach(size => {
let logoPath = `${size}x${size}/${osItem[0]}.png`;
let logoPath = `${size}x${size}/${osCode}.png`;

if (fs.existsSync(logoPath)) {
logoStackCount += 1;
} else {
missingSizes.push(size);
}
});

//#region markdown print

if (logoStackCount == 0) {
tableMarkdown += `| ............ | ${osItem[0]} | ${osItem[1]} | ❌ |\n`;
tableMarkdown += `| ............ | ${osCode} | ${osName} | ❌ |\n`;

console.log(`❌ ${osItem[1]} (${osItem[0]}): all logos not found.\n--------------------------`);
console.log(`❌ ${osName} (${osCode}): all logos not found.\n--------------------------`);
} else if (logoStackCount == sizeList.length) {
tableMarkdown += `| ![](${baseRepoAddress}/src/48x48/${osItem[0]}.png "${osItem[0]}") | ${osItem[0]} | ${osItem[1]} | ✅ |\n`;
tableMarkdown += `| ![](${baseRepoAddress}/src/${previewSize}/${osCode}.png "${osCode} (${previewSize})") | ${osCode} | ${osName} | ✅ |\n`;

availableItems += 1;
} else if (logoStackCount > 0 && logoStackCount < sizeList.length) {
tableMarkdown += `| ............ | ${osItem[0]} | ${osItem[1]} | ⭕ |\n`;
tableMarkdown += `| ............ | ${osCode} | ${osName} | ⭕ |\n`;

console.log(`⭕ ${osItem[1]} (${osItem[0]}): ${sizeList.length - logoStackCount} logos missing (sizes: ${missingSizes.join(', ')})\n--------------------------`);
console.log(`⭕ ${osName} (${osCode}): ${sizeList.length - logoStackCount} logos missing (sizes: ${missingSizes.join(', ')})\n--------------------------`);
}

//#endregion
});

console.log(`\nTotal: ${osList.length}, available: ${availableItems}, unavailable: ${osList.length - availableItems}\n\n`);

res.end(tableMarkdown);
} catch (err) {
res.end(err);
Expand Down

0 comments on commit de6bbca

Please sign in to comment.