From 734ebc8bdc24cb1acad0c4500cdcfa63bcd65ffc Mon Sep 17 00:00:00 2001 From: hiletmis Date: Fri, 9 Feb 2024 12:15:42 +0300 Subject: [PATCH 1/6] Add new chain SVG files --- raw/chains/Chain25.svg | 19 ------------------- .../{Chain280L.svg => Chain280-light.svg} | 0 .../{Chain324L.svg => Chain324-light.svg} | 0 raw/chains/Chain43288.svg | 14 -------------- .../{Chain5000L.svg => Chain5000-light.svg} | 0 .../{Chain5001L.svg => Chain5001-light.svg} | 0 raw/chains/Chain534352.svg | 19 ------------------- .../{Chain59140L.svg => Chain59140-light.svg} | 0 .../{Chain59144L.svg => Chain59144-light.svg} | 0 9 files changed, 52 deletions(-) delete mode 100644 raw/chains/Chain25.svg rename raw/chains/{Chain280L.svg => Chain280-light.svg} (100%) rename raw/chains/{Chain324L.svg => Chain324-light.svg} (100%) delete mode 100644 raw/chains/Chain43288.svg rename raw/chains/{Chain5000L.svg => Chain5000-light.svg} (100%) rename raw/chains/{Chain5001L.svg => Chain5001-light.svg} (100%) delete mode 100644 raw/chains/Chain534352.svg rename raw/chains/{Chain59140L.svg => Chain59140-light.svg} (100%) rename raw/chains/{Chain59144L.svg => Chain59144-light.svg} (100%) diff --git a/raw/chains/Chain25.svg b/raw/chains/Chain25.svg deleted file mode 100644 index ef24586b..00000000 --- a/raw/chains/Chain25.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/raw/chains/Chain280L.svg b/raw/chains/Chain280-light.svg similarity index 100% rename from raw/chains/Chain280L.svg rename to raw/chains/Chain280-light.svg diff --git a/raw/chains/Chain324L.svg b/raw/chains/Chain324-light.svg similarity index 100% rename from raw/chains/Chain324L.svg rename to raw/chains/Chain324-light.svg diff --git a/raw/chains/Chain43288.svg b/raw/chains/Chain43288.svg deleted file mode 100644 index cb504527..00000000 --- a/raw/chains/Chain43288.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/raw/chains/Chain5000L.svg b/raw/chains/Chain5000-light.svg similarity index 100% rename from raw/chains/Chain5000L.svg rename to raw/chains/Chain5000-light.svg diff --git a/raw/chains/Chain5001L.svg b/raw/chains/Chain5001-light.svg similarity index 100% rename from raw/chains/Chain5001L.svg rename to raw/chains/Chain5001-light.svg diff --git a/raw/chains/Chain534352.svg b/raw/chains/Chain534352.svg deleted file mode 100644 index b5cb2df4..00000000 --- a/raw/chains/Chain534352.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/raw/chains/Chain59140L.svg b/raw/chains/Chain59140-light.svg similarity index 100% rename from raw/chains/Chain59140L.svg rename to raw/chains/Chain59140-light.svg diff --git a/raw/chains/Chain59144L.svg b/raw/chains/Chain59144-light.svg similarity index 100% rename from raw/chains/Chain59144L.svg rename to raw/chains/Chain59144-light.svg From 26743bcea064e14ab048b1fe2b014ebf201aa7e0 Mon Sep 17 00:00:00 2001 From: hiletmis Date: Fri, 9 Feb 2024 12:15:55 +0300 Subject: [PATCH 2/6] Update switch case to use "light" instead of "l" in generateFunction() and update manual logos in getManualLogos() --- helpers/utils.js | 2 +- scripts/build-svg.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers/utils.js b/helpers/utils.js index 68c7dd30..eb989e92 100644 --- a/helpers/utils.js +++ b/helpers/utils.js @@ -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)} diff --git a/scripts/build-svg.js b/scripts/build-svg.js index 908dcb48..c258011c 100644 --- a/scripts/build-svg.js +++ b/scripts/build-svg.js @@ -13,7 +13,7 @@ const categories = ['chain', 'symbol', 'api-provider']; function getManualLogos(mode) { switch (mode) { case 'chain': - return ['5001L', '5000L', '280L', '324L', '59140L', '59144L']; + return ['5001-light', '5000-light', '280-light', '324-light', '59140-light', '59144-light']; case 'symbol': return []; case 'api-provider': From 4e3ed7fc1c4d15bba6359e95eff72ebf0d2c0cf1 Mon Sep 17 00:00:00 2001 From: hiletmis Date: Fri, 9 Feb 2024 12:16:10 +0300 Subject: [PATCH 3/6] Add check for alternate logos in fetch-missing.js --- scripts/fetch-missing.js | 45 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/scripts/fetch-missing.js b/scripts/fetch-missing.js index c9164fd1..08219ff7 100644 --- a/scripts/fetch-missing.js +++ b/scripts/fetch-missing.js @@ -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'); @@ -68,6 +69,26 @@ 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(); @@ -75,20 +96,22 @@ async function searchLogos() { 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); @@ -96,8 +119,7 @@ async function fetchLogos() { } } -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); @@ -106,12 +128,19 @@ 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); + console.log(`Downloaded ${file.name}`); } catch (error) { console.error(error); } From 95ae01a4330cc31bc11b553d539e09be2965ffce Mon Sep 17 00:00:00 2001 From: hiletmis Date: Fri, 9 Feb 2024 14:23:07 +0300 Subject: [PATCH 4/6] Add .env and changeset-details.md to .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index faf4c630..cc124816 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ optimized/ package-lock.json logos.tgz yarn.lock -.env \ No newline at end of file +.env + +changeset-details.md \ No newline at end of file From 6ea64b8721d7fb9436cd67a2ea18168a055f5f77 Mon Sep 17 00:00:00 2001 From: hiletmis Date: Fri, 9 Feb 2024 14:23:23 +0300 Subject: [PATCH 5/6] Add image change to changeset-details.md --- scripts/fetch-missing.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/fetch-missing.js b/scripts/fetch-missing.js index 08219ff7..a626aef5 100644 --- a/scripts/fetch-missing.js +++ b/scripts/fetch-missing.js @@ -134,12 +134,13 @@ async function downloadLogos(category, file) { return; } - const dbx = await getDropbox(); try { const response = await dbx.filesDownload({ path: file.path_lower }); var blob = response.result.fileBinary; await saveToDisk(prefix, file.name, category, blob); + const path = `../raw/${category}s/${prefix}${file.name}`; + await fs.appendFile('./.changeset/changeset-details.md', `||${file.name.replace('.svg', '')}|${category}|\n`, 'utf-8'); console.log(`Downloaded ${file.name}`); } catch (error) { console.error(error); From 0b4b203ccbddc652ab4c0efa09bf0d1588886de1 Mon Sep 17 00:00:00 2001 From: hiletmis Date: Fri, 9 Feb 2024 14:23:28 +0300 Subject: [PATCH 6/6] Update release script to include changeset details --- scripts/release.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/release.js b/scripts/release.js index 293b1751..cc5171fc 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -4,15 +4,28 @@ async function getChangeset() { return await fs.readdir('./.changeset'); } +async function getDetails() { + try { + const details = await fs.readFile('./.changeset/changeset-details.md', 'utf-8'); + return details; + } catch (error) { + return ''; + } +} + async function createChangeset() { + const details = await getDetails(); + const changeset = `--- "@phase21/logos": patch --- -# What's Changed -Release created by the release script. -Logos updated. -`; +Some changes have been made to the \`logos\`. + +|Logo|Name|Category| +|---|---|---| +` + details; + await fs.writeFile('./.changeset/changeset.md', changeset); console.log('✨ Created changeset file.'); } @@ -20,7 +33,7 @@ Logos updated. async function checkChangeset() { const changeset = await getChangeset(); - if (changeset.some(file => file.endsWith('.md'))) { + if (changeset.some(file => file.match(/changeset.md$/))) { console.log('There is already a .md file in the .changeset directory.'); } else { await createChangeset();