Skip to content

Commit aa78ee7

Browse files
committed
fix: handle invalid Figma credentials gracefully
1 parent ea5737a commit aa78ee7

File tree

3 files changed

+70
-29
lines changed

3 files changed

+70
-29
lines changed

packages/nimiq-icons/.env.example

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
# Figma API credentials for icon generation
2-
# If these are not set, the icon build script will be skipped
3-
FIGMA_FILE_ID=your_figma_file_id_here
4-
FIGMA_API_TOKEN=your_figma_api_token_here
2+
# These are ONLY needed if you're actively working on updating the icons from Figma
3+
# Most developers can ignore this file - the icon build will be automatically skipped
4+
5+
# How to set up (only if you need to update icons):
6+
# 1. Get a Figma API token from https://www.figma.com/developers/api#access-tokens
7+
# 2. Get the File ID from the Figma file URL: https://www.figma.com/file/{FILE_ID}/...
8+
# 3. Uncomment and fill in the values below
9+
# 4. Make sure you have access to the Nimiq Figma file
10+
11+
# FIGMA_FILE_ID=your_figma_file_id_here
12+
# FIGMA_API_TOKEN=your_figma_api_token_here
13+
14+
# Note: If you see a 404 error when running pnpm dev, either:
15+
# - Delete this .env file (if you don't need to update icons)
16+
# - OR verify you have the correct credentials and access permissions above

packages/nimiq-icons/README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,30 @@ You can preview the icons in the `apps/icons-ui` directory. This directory conta
1818

1919
## Environment Variables
2020

21-
The package requires the following environment variables:
21+
The package uses the following environment variables for Figma integration:
2222

2323
```bash
24-
FIGMA_FILE_ID: The ID of the Figma file.
25-
FIGMA_API_TOKEN: The API token for Figma.
24+
FIGMA_FILE_ID: The ID of the Figma file
25+
FIGMA_API_TOKEN: The API token for Figma
2626
```
2727

28+
**Important:** These are ONLY required if you're actively working on updating icons from Figma. Most developers can ignore this - the icon build will automatically skip if credentials are not configured.
29+
30+
### Setup for Icon Development
31+
32+
1. Copy `.env.example` to `.env` in the `packages/nimiq-icons` directory
33+
2. Get a Figma API token from https://www.figma.com/developers/api#access-tokens
34+
3. Get the File ID from the Nimiq Figma file URL
35+
4. Fill in the values in your `.env` file
36+
5. Ensure you have access permissions to the Nimiq Figma file
37+
38+
### Troubleshooting
39+
40+
If you encounter a 404 error when running `pnpm dev`:
41+
42+
- **Don't need to update icons?** Delete the `.env` file - the build will skip automatically
43+
- **Need to update icons?** Verify your credentials are correct and you have access to the Figma file
44+
2845
## Scripts
2946

30-
The package provides a dev script that you can run with npm run dev. This script uses bun to compile the TypeScript source code.
47+
The package provides a dev script that you can run with `pnpm dev`. This script processes icons from Figma and generates the icon packages.

packages/nimiq-icons/scripts/index.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,40 @@ async function checkFigmaVariants() {
6666

6767
const { file, token } = credentials
6868

69-
const figma = await importFromFigma({
70-
file,
71-
pages: ['Main'],
72-
token,
73-
prefix: 'nimiq',
74-
depth: 2,
75-
ifModifiedSince: '2021-01-01T00:00:00Z', // Force fetch to ensure variants exist
76-
iconNameForNode: node => node.name.startsWith('_') ? null : node.name,
77-
simplifyStroke: true,
78-
})
69+
try {
70+
const figma = await importFromFigma({
71+
file,
72+
pages: ['Main'],
73+
token,
74+
prefix: 'nimiq',
75+
depth: 2,
76+
ifModifiedSince: '2021-01-01T00:00:00Z', // Force fetch to ensure variants exist
77+
iconNameForNode: node => node.name.startsWith('_') ? null : node.name,
78+
simplifyStroke: true,
79+
})
7980

80-
if (figma === 'not_modified') {
81-
consola.info('Figma file has not been modified since last check. Will use cached data.')
82-
return
83-
}
81+
if (figma === 'not_modified') {
82+
consola.info('Figma file has not been modified since last check. Will use cached data.')
83+
return
84+
}
8485

85-
const iconSetVariants = figma.iconSet.list().map(sanitizeName)
86-
const ourVariants = Object.values(IconVariant)
86+
const iconSetVariants = figma.iconSet.list().map(sanitizeName)
87+
const ourVariants = Object.values(IconVariant)
8788

88-
const missingVariants = ourVariants.filter(variant => !iconSetVariants.includes(variant))
89-
const extraUnknownVariants = iconSetVariants.filter(v => !ourVariants.includes(v as IconVariant))
89+
const missingVariants = ourVariants.filter(variant => !iconSetVariants.includes(variant))
90+
const extraUnknownVariants = iconSetVariants.filter(v => !ourVariants.includes(v as IconVariant))
9091

91-
if (missingVariants.length > 0 || extraUnknownVariants.length > 0)
92-
throw new Error(`There is an unknown variant or a missing variant: ${JSON.stringify({ extraUnknownVariants, missingVariants })}`)
92+
if (missingVariants.length > 0 || extraUnknownVariants.length > 0)
93+
throw new Error(`There is an unknown variant or a missing variant: ${JSON.stringify({ extraUnknownVariants, missingVariants })}`)
9394

94-
consola.success('Figma variants are correct.')
95+
consola.success('Figma variants are correct.')
96+
}
97+
catch {
98+
consola.warn('Could not access Figma file. This might be due to invalid credentials or insufficient permissions.')
99+
consola.warn('Icon build will be skipped. If you need to update icons, please check your FIGMA_FILE_ID and FIGMA_API_TOKEN in .env')
100+
consola.info('Tip: If you don\'t need to modify icons, you can delete the .env file to skip this check entirely.')
101+
return null
102+
}
95103
}
96104

97105
async function getFigma(frameName: string) {
@@ -363,7 +371,11 @@ async function main() {
363371
return
364372
}
365373

366-
await checkFigmaVariants()
374+
const variantsCheck = await checkFigmaVariants()
375+
if (variantsCheck === null) {
376+
consola.info('Skipping Figma icon build due to credential issues')
377+
return
378+
}
367379
consola.start('Processing icon variants...')
368380

369381
// Object to store all icon sets

0 commit comments

Comments
 (0)