• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marcomontalbano / figma-export / 4952563450

pending completion
4952563450

Pull #145

github

GitHub
Merge f9fadd50b into e7ae576aa
Pull Request #145: Add `output-styles-as-style-dictionary` package

211 of 231 branches covered (91.34%)

Branch coverage included in aggregate %.

60 of 60 new or added lines in 2 files covered. (100.0%)

561 of 566 relevant lines covered (99.12%)

58.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/packages/core/src/lib/figmaStyles/index.ts
1
import * as Figma from 'figma-js';
2
import * as FigmaExport from '@figma-export/types';
3

4
import { notEmpty } from '../utils';
1✔
5

6
import { parse as parsePaintStyle } from './paintStyle';
1✔
7
import { parse as parseEffectStyle } from './effectStyle';
1✔
8
import { parse as parseTextStyle } from './textStyle';
1✔
9
// import { parse as parseGridStyle } from './gridStyle';
10

11
const fetchStyles = async (
1✔
12
    client: Figma.ClientInterface,
13
    fileId: string,
14
    version?: string,
15
    ids?: string[],
16
): Promise<FigmaExport.StyleNode[]> => {
20✔
17
    const { data: { styles = null } = {} } = await client.file(fileId, { version, ids }).catch((error: Error) => {
20!
18
        throw new Error(`while fetching file "${fileId}${version ? `?version=${version}` : ''}": ${error.message}`);
1!
19
    });
20

21
    if (!styles) {
19✔
22
        throw new Error('\'styles\' are missing.');
2✔
23
    }
24

25
    const { data: { nodes } } = await client.fileNodes(fileId, { ids: Object.keys(styles), version }).catch((error: Error) => {
17✔
26
        throw new Error(`while fetching fileNodes: ${error.message}`);
1✔
27
    });
28

29
    const styleNodes = Object.values(nodes).map((node) => node?.document);
452!
30

31
    return styleNodes.map((node) => ({
452✔
32
        ...(node ? styles[node.id] : ({} as Figma.Style)),
452!
33
        ...(node as Figma.Node),
34
    }));
35
};
36

37
const parseStyles = (styleNodes: FigmaExport.StyleNode[]): FigmaExport.Style[] => {
1✔
38
    return styleNodes.map((node) => {
14✔
39
        const parsedStyles = undefined
101✔
40
            || parsePaintStyle(node)
41
            || parseEffectStyle(node)
42
            || parseTextStyle(node);
43
            // || parseGridStyle(node)
44

45
        if (!parsedStyles) {
101✔
46
            return undefined;
3✔
47
        }
48

49
        return {
98✔
50
            name: node.name,
51
            comment: node.description,
52
            visible: node.visible !== false,
53
            originalNode: node,
54
            ...parsedStyles,
55
        };
56
    }).filter(notEmpty);
57
};
58

59
export {
60
    fetchStyles,
1✔
61
    parseStyles,
1✔
62
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc