Skip to content

Commit ecc6d5a

Browse files
committed
feat: add Nimiq icons package with initial structure and metadata
1 parent c50cbe1 commit ecc6d5a

File tree

12 files changed

+666
-614
lines changed

12 files changed

+666
-614
lines changed

packages/nimiq-icons/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.figma-cache/

packages/nimiq-icons/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "nimiq-icons-builder",
33
"type": "module",
4-
"version": "1.0.0",
4+
"version": "1.0.0-beta.5",
5+
"private": true,
56
"packageManager": "pnpm@10.4.1",
67
"description": "",
78
"exports": {
@@ -20,6 +21,7 @@
2021
},
2122
"devDependencies": {
2223
"@types/jsdom": "^21.1.7",
24+
"pathe": "catalog:",
2325
"dotenv": "^16.4.7",
2426
"esno": "^4.8.0"
2527
}

packages/nimiq-icons/scripts/client.ts

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import type { IconSet } from '@iconify/tools'
22
import { env, exit } from 'node:process'
33
import { exportJSONPackage, importFromFigma } from '@iconify/tools'
44
import { IconVariant } from './consts'
5+
import { version } from '../package.json'
6+
import { resolve, dirname } from 'pathe'
7+
import { existsSync, writeFile } from 'node:fs'
58

69
export const sanitizeName = (name: string) => name.toLocaleLowerCase().trim().replace(/ /g, '-')
710

@@ -49,46 +52,71 @@ export async function checkFigmaVariants() {
4952

5053
export async function getFigma(frameName: string) {
5154
const { file, token } = getFigmaSecrets()
52-
const figma = await importFromFigma({
53-
file,
54-
pages: ['Main'],
55-
token,
56-
prefix: 'nimiq',
57-
depth: 3,
58-
ifModifiedSince: '2021-01-01T00:00:00Z',
59-
simplifyStroke: true,
60-
iconNameForNode: (node) => {
61-
if (
62-
// Icons are stored after 2 parents: page -> container frame -> icon
63-
node.parents.length !== 2
64-
// Icons use frames
65-
|| node.type !== 'FRAME'
66-
// !node.parents.find(parent => parent.name === frameName)
67-
// It is direct child of the frameName
68-
|| sanitizeName(node.parents.at(-1)?.name || '') !== frameName
69-
) {
70-
return null
71-
}
72-
return sanitizeName(node.name)
73-
},
74-
})
55+
try {
56+
const figma = await importFromFigma({
57+
file,
58+
pages: ['Main'],
59+
token,
60+
cacheDir: resolve(dirname('..'), '.figma-cache'),
61+
prefix: 'nimiq',
62+
depth: 3,
63+
ifModifiedSince: true,
64+
simplifyStroke: true,
65+
iconNameForNode: (node) => {
66+
if (
67+
node.parents.length !== 2
68+
|| node.type !== 'FRAME'
69+
|| sanitizeName(node.parents.at(-1)?.name || '') !== frameName
70+
) {
71+
return null
72+
}
73+
return sanitizeName(node.name)
74+
},
75+
})
7576

76-
if (figma === 'not_modified') {
77-
console.log('Figma file has not been modified since last import.')
77+
if (figma === 'not_modified' && existsSync(resolve('../src'))) {
78+
console.log('Figma file has not been modified since last build.')
79+
exit(0)
80+
}
81+
82+
return figma
83+
} catch (error) {
84+
console.error('Error fetching from Figma:', error)
7885
exit(1)
7986
}
80-
81-
return figma
8287
}
8388

8489
export async function prepareNpmPackage(iconSet: IconSet) {
8590
await exportJSONPackage(iconSet, {
86-
target: 'dist',
91+
target: 'src',
8792
package: {
8893
name: 'nimiq-icons',
89-
version: '0.0.1',
90-
description: 'Nimiq icons',
94+
version,
95+
description: 'The Nimiq Icons as a iconify icon set.',
96+
homepage: "https://github.com/onmax/nimiq-ui#readme",
97+
repository: {
98+
type: "git",
99+
url: "git+https://github.com/onmax/nimiq-ui.git"
100+
},
101+
bugs: "https://github.com/onmax/nimiq-ui/issues",
102+
keywords: [
103+
"nimiq",
104+
"nimiq-ui",
105+
"nimiq-icons",
106+
"vitepress-theme"
107+
],
91108
license: 'MIT',
92109
},
93110
})
111+
const content = `# auto-generated folder
112+
This folder is auto-generated by the nimiq-icons package.
113+
Do not modify it directly.
114+
If you want to make changes, please refer to the Figma file.
115+
`
116+
writeFile(resolve('../src/README.md'), content, (err) => {
117+
if (err) {
118+
console.error('Error writing README.md:', err)
119+
exit(1)
120+
}
121+
})
94122
}

packages/nimiq-icons/scripts/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ const iconsSets: IconSet[] = []
1111

1212
for (const variant of Object.values(IconVariant)) {
1313
const figma = await getFigma(variant)
14+
if (figma === 'not_modified')
15+
continue
16+
1417
const variantName = sanitizeName(variant)
18+
1519
console.log(`Icons: ${figma.iconSet.list().join(', ')}`)
1620
const iconSet = optimizeIconSet(figma.iconSet, variantName as IconVariant)
1721
iconsSets.push(iconSet)
1822
console.log(`Generated icon set for ${variantName}: ${iconSet.list().join(', ')}`)
1923
}
2024

25+
if (iconsSets.length === 0) {
26+
console.log('No new icons found.')
27+
process.exit(0)
28+
}
29+
2130
const combinedIconSet = iconsSets.reduce((prev, curr) => mergeIconSets(prev, curr))
2231

2332
console.log('Preparing npm package...')
File renamed without changes.

packages/nimiq-icons/dist/icons.json renamed to packages/nimiq-icons/src/icons.json

Lines changed: 581 additions & 581 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)