Skip to content

Commit

Permalink
Merge pull request #235 from api3dao/234-improve-dropbox-integration
Browse files Browse the repository at this point in the history
Improve dropbox integration
  • Loading branch information
hiletmis authored Feb 9, 2024
2 parents a9fdea2 + 0b4b203 commit 6155946
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 68 deletions.
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
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 scripts/build-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
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
23 changes: 18 additions & 5 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,36 @@ 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.');
}


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();
Expand Down

0 comments on commit 6155946

Please sign in to comment.