ts_schema_codegen 0.1.0 copy "ts_schema_codegen: ^0.1.0" to clipboard
ts_schema_codegen: ^0.1.0 copied to clipboard

Generate Dart code from a TypeScript data schema. Evaluates the TS entry file with Deno at build time and emits typed Dart constants via build_runner.

example/lib/main.dart

// Smoke script. Run after `dart run build_runner build`:
//   dart run lib/main.dart

import 'field_definition.dart';
import 'ts_schema.g.dart' as g;

void main() {
  _printForm('signup', null);
  _printForm('feedback', null);
  // Subcategory 'bug' routes to the feedback fieldset even though the
  // category is 'feedback' either way — here we show the mechanism works.
  _printForm('other', 'bug');
}

void _printForm(String category, String? subcategory) {
  final fields = g.getFieldsForCategoryGenerated(
    category,
    subcategory: subcategory,
  );
  final sub = subcategory == null ? '' : ' / $subcategory';
  print('── form($category$sub) ────────────────────────');
  for (final f in fields) {
    final opts = f.options == null ? '' : '  [${f.options!.join(" | ")}]';
    final req = f.required ? ' *' : '';
    print('  ${f.label}$req  (${f.type.name})$opts');
  }
  print('');
}
0
likes
160
points
5
downloads

Documentation

API reference

Publisher

verified publisherenraio.com

Weekly Downloads

Generate Dart code from a TypeScript data schema. Evaluates the TS entry file with Deno at build time and emits typed Dart constants via build_runner.

Repository (GitHub)
View/report issues

Topics

#codegen #build-runner #typescript

License

MIT (license)

Dependencies

build, path

More

Packages that depend on ts_schema_codegen