Skip to content

Commit

Permalink
Merge pull request #2319 from blockscout/fe-2287
Browse files Browse the repository at this point in the history
Favicon generator: replace realfavicon with favicons package
  • Loading branch information
isstuev authored Nov 1, 2024
2 parents d5863de + 6626275 commit af0baef
Show file tree
Hide file tree
Showing 32 changed files with 1,296 additions and 182 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ NEXT_PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID=UA-XXXXXX-X
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
NEXT_PUBLIC_AUTH0_CLIENT_ID=xxx
FAVICON_GENERATOR_API_KEY=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules_linux

playwright/envs.js
deploy/tools/envs-validator/index.js
deploy/tools/favicon-generator/index.js
deploy/tools/feature-reporter/build/**
deploy/tools/feature-reporter/index.js
public/**
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ WORKDIR /envs-validator
COPY ./deploy/tools/envs-validator/package.json ./deploy/tools/envs-validator/yarn.lock ./
RUN yarn --frozen-lockfile

### FAVICON GENERATOR
# Install dependencies
WORKDIR /favicon-generator
COPY ./deploy/tools/favicon-generator/package.json ./deploy/tools/favicon-generator/yarn.lock ./
RUN yarn --frozen-lockfile


# *****************************
# ****** STAGE 2: Build *******
Expand Down Expand Up @@ -77,6 +83,10 @@ COPY --from=deps /envs-validator/node_modules ./deploy/tools/envs-validator/node
RUN cd ./deploy/tools/envs-validator && yarn build


### FAVICON GENERATOR
# Copy dependencies and source code
COPY --from=deps /favicon-generator/node_modules ./deploy/tools/favicon-generator/node_modules

# *****************************
# ******* STAGE 3: Run ********
# *****************************
Expand Down Expand Up @@ -113,7 +123,7 @@ COPY --chmod=755 ./deploy/scripts/make_envs_script.sh .
COPY --chmod=755 ./deploy/scripts/download_assets.sh .
## Favicon generator
COPY --chmod=755 ./deploy/scripts/favicon_generator.sh .
COPY ./deploy/tools/favicon-generator ./deploy/tools/favicon-generator
COPY --from=builder /app/deploy/tools/favicon-generator ./deploy/tools/favicon-generator
RUN ["chmod", "-R", "777", "./deploy/tools/favicon-generator"]
RUN ["chmod", "-R", "777", "./public"]

Expand Down
5 changes: 1 addition & 4 deletions configs/envs/.env.eth_sepolia
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ NEXT_PUBLIC_GRAPHIQL_TRANSACTION=0xbf69c7abc4fee283b59a9633dadfdaedde5c5ee0fba3e
NEXT_PUBLIC_HAS_BEACON_CHAIN=true
NEXT_PUBLIC_HAS_USER_OPS=true
NEXT_PUBLIC_HOMEPAGE_CHARTS=['daily_txs']
NEXT_PUBLIC_HOMEPAGE_PLATE_BACKGROUND=rgba(51, 53, 67, 1)
NEXT_PUBLIC_HOMEPAGE_PLATE_TEXT_COLOR=rgba(165, 252, 122, 1)
NEXT_PUBLIC_IS_ACCOUNT_SUPPORTED=true
NEXT_PUBLIC_IS_TESTNET=true
NEXT_PUBLIC_LOGOUT_URL=https://blockscout-goerli.us.auth0.com/v2/logout
Expand Down Expand Up @@ -61,5 +59,4 @@ NEXT_PUBLIC_SAFE_TX_SERVICE_URL=https://safe-transaction-sepolia.safe.global
NEXT_PUBLIC_SENTRY_ENABLE_TRACING=true
NEXT_PUBLIC_STATS_API_HOST=https://stats-sepolia.k8s-dev.blockscout.com
NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER=noves
NEXT_PUBLIC_VIEWS_CONTRACT_SOLIDITYSCAN_ENABLED=true
NEXT_PUBLIC_VISUALIZE_API_HOST=https://visualizer.services.blockscout.com
NEXT_PUBLIC_VIEWS_CONTRACT_SOLIDITYSCAN_ENABLED=true
2 changes: 1 addition & 1 deletion deploy/scripts/favicon_generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ master_url="${FAVICON_MASTER_URL:-$NEXT_PUBLIC_NETWORK_ICON}"
export MASTER_URL="$master_url"

cd ./deploy/tools/favicon-generator
./script.sh
node "$(dirname "$0")/index.js"
if [ $? -ne 0 ]; then
cd ../../../
exit 1
Expand Down
1 change: 0 additions & 1 deletion deploy/tools/envs-validator/test/.env.base
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ NEXT_PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID=UA-XXXXXX-X
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
NEXT_PUBLIC_AUTH0_CLIENT_ID=xxx
FAVICON_GENERATOR_API_KEY=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
NEXT_PUBLIC_AD_TEXT_PROVIDER=coinzilla
NEXT_PUBLIC_AD_BANNER_PROVIDER=slise
Expand Down
8 changes: 4 additions & 4 deletions deploy/tools/favicon-generator/.gitignore
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/output
config.json
response.json
favicon_package**
/node_modules
/public
.env
/output
41 changes: 0 additions & 41 deletions deploy/tools/favicon-generator/config.template.json

This file was deleted.

70 changes: 70 additions & 0 deletions deploy/tools/favicon-generator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* 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.warn('Error generating favicons:', faviconError);
}
} 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"
}
}
113 changes: 0 additions & 113 deletions deploy/tools/favicon-generator/script.sh

This file was deleted.

Loading

0 comments on commit af0baef

Please sign in to comment.