liquid_codegen 0.1.2
liquid_codegen: ^0.1.2 copied to clipboard
Optional YAML → typed LiquidEvent codegen for liquid_analytics. Generates sealed-class compatible event classes with no build_runner required.
// Generate typed LiquidEvent classes from a YAML schema.
//
// Normally you would run the bundled CLI:
//
// dart run liquid_codegen:generate --input events.yaml --output lib/events.dart
//
// This example calls the same library API directly.
import 'package:liquid_codegen/liquid_codegen.dart';
const String schemaYaml = '''
events:
checkout_started:
properties:
cart_value: double
item_count: int? # trailing ? = optional
promo_tapped:
category: marketing # routed to the marketing consent gate
properties:
campaign: String
app_opened: {} # no properties
''';
void main() {
final schema = parseEventSchema(schemaYaml);
print('Parsed ${schema.events.length} events:');
for (final event in schema.events) {
print(' ${event.name} -> class ${event.className} '
'(${event.properties.length} properties, ${event.category})');
}
// The generated library is plain Dart — no build_runner, no annotations.
print('\n--- generated ---\n');
print(generateEventsLibrary(schema));
}