contracts_generator 0.2.0+1
contracts_generator: ^0.2.0+1 copied to clipboard

Dart contracts client generator for a CQRS API.

contracts_generator #

Dart contracts client generator for a CQRS API. Generated code is based on the format described in https://github.com/leancodepl/contractsgenerator.

Installation #

dart pub add contracts_generator --dev

Then install dependencies needed by generated contracts:

dart pub add cqrs
dart pub add equatable
dart pub add json_annotation

Usage #

First run will take longer due to the need to download external dependencies.

CLI #

$ dart run contracts_generator --help
Command line utility for generating dart CQRS contracts

Usage: contracts_generator <command> [arguments]

Global options:
-h, --help    Print this usage information.

Available commands:
  init   Initialize a config file

Run "contracts_generator help <command>" for more information about a command.

Library #

import 'dart:io';

import 'package:contracts_generator/contracts_generator.dart';

Future<void> main(List<String> arguments) async {
  final generator = ContractsGenerator(
    ContractsGeneratorConfig(
      input: GeneratorScript.path(['ExampleContracts/**']),
      name: 'cool_name',
      output: Directory('lib'),
      extra: '// :)',
      include: RegExp(r'\w+(\.\w+)*'),
    ),
  );

  await generator.writeAll();
}

Todo #

  • Attributes. Currently completely ignored