@@ -2,6 +2,9 @@ import type { IconSet } from '@iconify/tools'
22import { env , exit } from 'node:process'
33import { exportJSONPackage , importFromFigma } from '@iconify/tools'
44import { IconVariant } from './consts'
5+ import { version } from '../package.json'
6+ import { resolve , dirname } from 'pathe'
7+ import { existsSync , writeFile } from 'node:fs'
58
69export const sanitizeName = ( name : string ) => name . toLocaleLowerCase ( ) . trim ( ) . replace ( / / g, '-' )
710
@@ -49,46 +52,71 @@ export async function checkFigmaVariants() {
4952
5053export 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
8489export 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}
0 commit comments