figma_tokens_gen 1.1.0 copy "figma_tokens_gen: ^1.1.0" to clipboard
figma_tokens_gen: ^1.1.0 copied to clipboard

Generate Flutter Color constants and palette maps from Figma design-token JSON exports. Ships a CLI and a customisable library API.

example/figma_tokens_gen_example.dart

import 'dart:io';

import 'package:figma_tokens_gen/figma_tokens_gen.dart';

/// Converts `example/tokens/*.json` into `example/generated/brand_colors.dart`.
///
/// `themes.json` holds the primitives; `semantic.json` shows the two shapes a
/// real export adds on top — nested groups, and `{primitive.token}` aliases
/// pointing across files.
///
/// Run from the package root:
///
/// ```sh
/// dart run example/figma_tokens_gen_example.dart
/// ```
///
/// The equivalent from the command line, with the default names, is:
///
/// ```sh
/// dart run figma_tokens_gen --input tokens --output lib/generated/theme
/// ```
Future<void> main() async {
  final converter = TokenConverter(
    emitter: const DartColorsEmitter(
      className: 'BrandColors',
      paletteClassName: 'BrandPalette',
      fileName: 'brand_colors.dart',
    ),
  );

  try {
    final result = await converter.convert(
      inputPath: 'example/tokens',
      outputPath: 'example/generated',
    );

    for (final warning in result.warnings) {
      stderr.writeln('Warning: $warning');
    }

    stdout.writeln(
      'Wrote ${result.colorCount} colours to ${result.outputFile}',
    );
    for (final category in result.tokens.categories) {
      stdout.writeln('  ${category.name}: ${category.tokens.length}');
    }
  } on ConversionException catch (e) {
    stderr.writeln('Conversion failed: ${e.message}');
    exitCode = 1;
  }
}
1
likes
160
points
204
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Generate Flutter Color constants and palette maps from Figma design-token JSON exports. Ships a CLI and a customisable library API.

Repository (GitHub)
View/report issues

Topics

#figma #design-tokens #codegen #theming

License

MIT (license)

Dependencies

args, meta, path

More

Packages that depend on figma_tokens_gen