Skip to content

Commit

Permalink
add missing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Dec 20, 2024
1 parent 1c7f74d commit 22e8181
Show file tree
Hide file tree
Showing 3 changed files with 1,269 additions and 0 deletions.
71 changes: 71 additions & 0 deletions deploy/tools/favicon-generator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint-disable no-console */
const { favicons } = require('favicons');
const fs = require('fs/promises');
const path = require('path');

generateFavicons();

async function generateFavicons() {
console.log('Generating favicons...');
const masterUrl = process.env.MASTER_URL;
try {
if (!masterUrl) {
throw new Error('FAVICON_MASTER_URL or NEXT_PUBLIC_NETWORK_ICON must be set');
}

const fetch = await import('node-fetch');
const response = await fetch.default(masterUrl);
const buffer = await response.arrayBuffer();
const source = Buffer.from(buffer);

const configuration = {
path: '/output',
appName: 'Blockscout',
icons: {
android: true,
appleIcon: {
background: 'transparent',
},
appleStartup: false,
favicons: true,
windows: false,
yandex: false,
},
};

try {
const result = await favicons(source, configuration);

const outputDir = path.resolve(process.cwd(), 'output');
await fs.mkdir(outputDir, { recursive: true });

for (const image of result.images) {
// keep only necessary files
if (image.name === 'apple-touch-icon-180x180.png' || image.name === 'android-chrome-192x192.png' ||
(!image.name.startsWith('apple-touch-icon') && !image.name.startsWith('android-chrome'))
) {
await fs.writeFile(path.join(outputDir, image.name), image.contents);
}

// copy android-chrome-192x192.png to logo-icon.png for marketing purposes
if (image.name === 'android-chrome-192x192.png') {
await fs.writeFile(path.join(outputDir, 'logo-icon.png'), image.contents);
}
}

for (const file of result.files) {
if (file.name !== 'manifest.webmanifest') {
await fs.writeFile(path.join(outputDir, file.name), file.contents);
}
}

console.log('Favicons generated successfully!');
} catch (faviconError) {
console.error('Error generating favicons:', faviconError);
process.exit(1);
}
} catch (error) {
console.error('Error in favicon generation process:', error);
process.exit(1);
}
}
20 changes: 20 additions & 0 deletions deploy/tools/favicon-generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "favicon-generator",
"version": "1.0.0",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"favicons": "^7.2.0",
"ts-loader": "^9.4.4",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
"node-loader": "^2.0.0",
"tsconfig-paths-webpack-plugin": "^4.1.0"
}
}
Loading

0 comments on commit 22e8181

Please sign in to comment.