5
5
6
6
import type { AssetCoreData , AssetsMetadata } from "../@types/AssetsMetadata" ;
7
7
8
+ import { PublishedComponent , PublishedComponentSet } from '@figma/rest-api-spec' ;
9
+
8
10
import { config } from '../config' ;
9
11
10
12
import chalk from 'chalk' ;
@@ -30,10 +32,11 @@ export async function getAssetsMetadata(): Promise<AssetsMetadata> {
30
32
const componentSetsResponse = await api . getFileComponentSets ( { file_key : config . figmaFile . id } ) ;
31
33
const componentSetData : ComponentSetData = { } ;
32
34
if ( componentSetsResponse . meta && componentSetsResponse . meta . component_sets ) {
33
- componentSetsResponse . meta . component_sets . forEach ( component_set => {
35
+ componentSetsResponse . meta . component_sets . forEach ( ( component_set : PublishedComponentSet ) => {
34
36
// check that the component_set is inside the expected page/frame
35
37
if (
36
38
component_set . containing_frame &&
39
+ component_set . containing_frame . name &&
37
40
component_set . containing_frame . pageName === config . figmaFile . page &&
38
41
! config . figmaFile . excludeFrames . includes ( component_set . containing_frame . name )
39
42
) {
@@ -49,10 +52,11 @@ export async function getAssetsMetadata(): Promise<AssetsMetadata> {
49
52
50
53
const componentsResponse = await api . getFileComponents ( { file_key : config . figmaFile . id } ) ;
51
54
if ( componentsResponse . meta && componentsResponse . meta . components ) {
52
- componentsResponse . meta . components . forEach ( component => {
55
+ componentsResponse . meta . components . forEach ( ( component : PublishedComponent ) => {
53
56
// check that the component is inside the expected page/frame
54
57
if (
55
58
component . containing_frame &&
59
+ component . containing_frame . name &&
56
60
component . containing_frame . pageName === config . figmaFile . page &&
57
61
! config . figmaFile . excludeFrames . includes ( component . containing_frame . name )
58
62
) {
@@ -67,7 +71,12 @@ export async function getAssetsMetadata(): Promise<AssetsMetadata> {
67
71
// by convention the category of an icon is the containing frame's name
68
72
assetsMetadata [ component . node_id ] . category = component . containing_frame . name ;
69
73
}
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
70
78
if ( component . containing_frame . containingStateGroup ) {
79
+ // @ts -ignore
71
80
const parentComponentSet = componentSetData [ component . containing_frame . containingStateGroup . nodeId ]
72
81
if ( parentComponentSet ) {
73
82
assetsMetadata [ component . node_id ] . iconName = parentComponentSet . name ;
0 commit comments