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¶
-
Create a new instance of
Figmagen:// figmaToken is optional as it can be provided // using `FIGMA_TOKEN` environment variable val figmagen = Figmagen(figmaToken = "...") -
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) -
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¶
themeFileshas to be overridden providing them.runfunction has to be overridden and should return the list ofTaskFilethat will be generated.- Use
getColorsfunction to easily provides a list ofTaskFileto therunfunction.