55
66import type { AssetCoreData , AssetsMetadata } from "../@types/AssetsMetadata" ;
77
8+ import { PublishedComponent , PublishedComponentSet } from '@figma/rest-api-spec' ;
9+
810import { config } from '../config' ;
911
1012import chalk from 'chalk' ;
@@ -30,10 +32,11 @@ export async function getAssetsMetadata(): Promise<AssetsMetadata> {
3032 const componentSetsResponse = await api . getFileComponentSets ( { file_key : config . figmaFile . id } ) ;
3133 const componentSetData : ComponentSetData = { } ;
3234 if ( componentSetsResponse . meta && componentSetsResponse . meta . component_sets ) {
33- componentSetsResponse . meta . component_sets . forEach ( component_set => {
35+ componentSetsResponse . meta . component_sets . forEach ( ( component_set : PublishedComponentSet ) => {
3436 // check that the component_set is inside the expected page/frame
3537 if (
3638 component_set . containing_frame &&
39+ component_set . containing_frame . name &&
3740 component_set . containing_frame . pageName === config . figmaFile . page &&
3841 ! config . figmaFile . excludeFrames . includes ( component_set . containing_frame . name )
3942 ) {
@@ -49,10 +52,11 @@ export async function getAssetsMetadata(): Promise<AssetsMetadata> {
4952
5053 const componentsResponse = await api . getFileComponents ( { file_key : config . figmaFile . id } ) ;
5154 if ( componentsResponse . meta && componentsResponse . meta . components ) {
52- componentsResponse . meta . components . forEach ( component => {
55+ componentsResponse . meta . components . forEach ( ( component : PublishedComponent ) => {
5356 // check that the component is inside the expected page/frame
5457 if (
5558 component . containing_frame &&
59+ component . containing_frame . name &&
5660 component . containing_frame . pageName === config . figmaFile . page &&
5761 ! config . figmaFile . excludeFrames . includes ( component . containing_frame . name )
5862 ) {
@@ -67,7 +71,12 @@ export async function getAssetsMetadata(): Promise<AssetsMetadata> {
6771 // by convention the category of an icon is the containing frame's name
6872 assetsMetadata [ component . node_id ] . category = component . containing_frame . name ;
6973 }
74+ // this (missing `containingStateGroup` property) is a known issue:
75+ // - https://forum.figma.com/t/missing-containingstategroup-parameter-in-documentation-for-frameinfo/2558
76+ // - https://github.com/figma/rest-api-spec/issues/29
77+ // @ts -ignore
7078 if ( component . containing_frame . containingStateGroup ) {
79+ // @ts -ignore
7180 const parentComponentSet = componentSetData [ component . containing_frame . containingStateGroup . nodeId ]
7281 if ( parentComponentSet ) {
7382 assetsMetadata [ component . node_id ] . iconName = parentComponentSet . name ;
0 commit comments