Skip to content

MavenCentral Snapshot Build

Figmagen

Generate tokens from Figma easily for multiple languages or frameworks

Download

dependencies {
    implementation("com.stuart.figmagen:figmagen-core:$version")

    // Kotlin Compose extensions
    implementation("com.stuart.figmagen:figmagen-kotlin-compose-ext:$version")

    // Swift SwiftUI extensions
    implementation("com.stuart.figmagen:figmagen-swift-swiftui-ext:$version")
}

Usage

  1. Create a new instance of Figmagen:

    // figmaToken is optional as it can be provided
    // using `FIGMA_TOKEN` environment variable
    val figmagen = Figmagen(figmaToken = "...")
    
  2. Add tasks to Figmagen:

    val swiftUiColorsTask: Task =
        SwiftUiColorsTask(
            checkColorCorrectness = true,
            outputPath = "some/path/to/module/with/Colors.kt",
            ThemeFile("light", FileKey("auAVu6zRJ39zECKv6hWDmH")),
            ThemeFile("dark", FileKey("wizOikAT1Wigtx6zHpfC87")),
        )
    
    figmagen.addTask(kotlinComposeColorsTask)
    
  3. Generate all files from all tasks

figmagen.generate()

Basic tasks

The basic tasks are generic tasks which fetch info from Figma files. They have to be extended to add the functionality of each language or platform, for example KotlinComposeColorsTask extends ColorsTask and it has default bindings to generate Kotlin classes, properties and so on.

There are default implementations for all tasks, but if one is missing, they can be extended easily to adapt your needs. Feels free to ask for more tasks or contribute them :)

ColorsTask

After providing a list of theme files, it has a getColors function with return a list of all colors of all themes provided.

Extending ColorsTask

  • themeFiles has to be overridden providing them.
  • run function has to be overridden and should return the list of TaskFile that will be generated.
  • Use getColors function to easily provides a list of TaskFile to the run function.

Implementation for basic tasks

ColorTasks