Skip to content

Commit

Permalink
Merge pull request #239 from api3dao/main
Browse files Browse the repository at this point in the history
Release 2.9.0
  • Loading branch information
hiletmis authored Feb 13, 2024
2 parents 6f3689d + f1e0223 commit b521990
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-yaks-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@phase21/logos": minor
---

Light version support improved
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ optimized/
package-lock.json
logos.tgz
yarn.lock
.env
.env

changeset-details.md
2 changes: 1 addition & 1 deletion helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function generateFunction(batchName, switchCase, mode) {
return ${getPlaceholderImage(mode)}
}
switch (sanitizeName(\`\${id}\${light ? "l" : ""}\`).toLowerCase()) {
switch (sanitizeName(\`\${id}\${light ? "light" : ""}\`).toLowerCase()) {
${switchCase}
default:
return light ? ${batchName}(id) : ${getPlaceholderImage(mode)}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dropbox": "^10.34.0",
"node-fetch": "^2.7.0",
"dotenv": "^16.4.1",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"svgo": "^3.2.0"
},
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 2 additions & 20 deletions raw/chains/Chain11155420.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions raw/chains/Chain25.svg

This file was deleted.

File renamed without changes
File renamed without changes
14 changes: 0 additions & 14 deletions raw/chains/Chain43288.svg

This file was deleted.

File renamed without changes
File renamed without changes
19 changes: 0 additions & 19 deletions raw/chains/Chain534352.svg

This file was deleted.

File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion raw/chains/Chain599.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions raw/symbols/et-hx-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
29 changes: 25 additions & 4 deletions scripts/build-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ const outputPath = './dist';

const categories = ['chain', 'symbol', 'api-provider'];

let chainLightLogos = [];
let apiProviderLightLogos = [];
let symbolLightLogos = [];

function getManualLogos(mode) {
switch (mode) {
case 'chain':
return ['5001L', '5000L', '280L', '324L', '59140L', '59144L'];
return [...chainLightLogos];
case 'symbol':
return [];
return [...symbolLightLogos];
case 'api-provider':
return [];
return [...apiProviderLightLogos];
default:
break;
}
Expand Down Expand Up @@ -133,10 +137,27 @@ async function renameFiles() {
});
}

async function findLightLogos() {
const [chainFiles, apiProviderFiles, symbolFiles] = await Promise.all([
fs.readdir('./optimized/chain', 'utf-8'),
fs.readdir('./optimized/api-provider', 'utf-8'),
fs.readdir('./optimized/symbol', 'utf-8')
]);

chainLightLogos = chainFiles
.filter((file) => file.includes('light'))
.map((file) => file.replace('Chain', ''))

apiProviderLightLogos = apiProviderFiles.filter((file) => file.includes('light'));

symbolLightLogos = symbolFiles.filter((file) => file.includes('light'));
}

async function main() {
console.log('🏗 Building logo package...');
rimraf(`${outputPath}/`)
.then(() => Promise.all([renameFiles()]))
.then(findLightLogos)
.then(renameFiles)
.then(() => Promise.all([generateLogos('cjs'), generateLogos('esm')]))
.then(() => console.log('✅ Finished building package.'));
}
Expand Down
46 changes: 38 additions & 8 deletions scripts/fetch-missing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('dotenv').config();
const chains = require('@phase21/chains');
const fs = require('fs/promises');
const { existsSync } = require('node:fs');
const utils = require('../helpers/utils');
const { apisData, getApiProviderAliases } = require('@phase21/api-integrations');
const dropbox = require('dropbox');
Expand Down Expand Up @@ -68,36 +69,57 @@ function getLogoList(mode) {
}
}

async function checkAlternateLogos(foundLogos) {
categories.forEach(async (category) => {
const alternateLogos = getLogoList(category).reduce((acc, chain) => {
const foundLogo = foundLogos.find((foundLogo) => foundLogo.name.toLowerCase().includes(chain.toLowerCase() + '-light'));
if (foundLogo) {
acc.push(foundLogo);
}
return acc;
}, []);
alternateLogos.map((foundLogo) => {
const prefix = category === 'chain' ? 'Chain' : '';
if (existsSync(`./raw/${category}s/${prefix}${foundLogo.name}`)) {
return;
}
console.log('Found alternate logo:', foundLogo.name);
downloadLogos(category, foundLogo);
});
});
}

async function searchLogos() {
console.log('🏗 Fetching logo files...');
const foundLogos = await fetchLogos();

missingLogos.map((missingLogoCategory) => {
missingLogoCategory.logos.map((missingLogo) => {
foundLogos.map((foundLogo) => {
if (foundLogo.name.toLowerCase() === `${missingLogo.toLowerCase()}.svg`) {
downloadLogos(missingLogoCategory.category, foundLogo.name);
if (utils.sanitizeName(foundLogo.name).toLowerCase() === `${utils.sanitizeName(missingLogo).toLowerCase()}`) {
downloadLogos(missingLogoCategory.category, foundLogo);
}
});
});
});

console.log('🏗 Checking for alternate logos...');
await checkAlternateLogos(foundLogos) // Check for alternate logos
console.log('✅ Finished fetching logo files.');
}

async function fetchLogos() {
const dbx = await getDropbox();
try {
const response = await dbx.filesListFolder({ path: '' });
const response = await dbx.filesListFolder({ path: '', recursive: true });
return response.result.entries;
} catch (error) {
console.error(error);
return [];
}
}

async function saveToDisk(file, category, blob) {
const prefix = category === 'chain' ? 'Chain' : '';
async function saveToDisk(prefix, file, category, blob) {
fs.writeFile(`./raw/${category}s/${prefix}${file}`, blob, function (err) {
if (err) {
console.error(err);
Expand All @@ -106,12 +128,20 @@ async function saveToDisk(file, category, blob) {
}

async function downloadLogos(category, file) {
const prefix = category === 'chain' ? 'Chain' : '';
if (existsSync(`./raw/${category}s/${prefix}${file.name}`)) {
console.log(`File ${file.name} already exists`);
return;
}

const dbx = await getDropbox();
try {
const response = await dbx.filesDownload({ path: `/${file}` });
const response = await dbx.filesDownload({ path: file.path_lower });
var blob = response.result.fileBinary;
await saveToDisk(file, category, blob);
console.log(`Downloaded ${file}`);
await saveToDisk(prefix, file.name, category, blob);
const path = `../raw/${category}s/${prefix}${file.name}`;
await fs.appendFile('./.changeset/changeset-details.md', `|<img src=" ${path}" width="36" alt="">|${file.name.replace('.svg', '')}|${category}|\n`, 'utf-8');
console.log(`Downloaded ${file.name}`);
} catch (error) {
console.error(error);
}
Expand Down
Loading

0 comments on commit b521990

Please sign in to comment.