How to run a code-generator on the top of another code-generator?

后端 未结 3 1174
遥遥无期
遥遥无期 2021-02-13 04:26

Using the source_gen stack to make a code generator, how can I make a generator that generates code that would be the input of another generator (more specifically json_se

3条回答
  •  不知归路
    2021-02-13 04:48

    Check the build.yaml config file documentation for more info, but I think you should use the applies_builders param that allows to execute another build after the defined one.

    The example shows a builder that generates .tar.gz files and then executes another build that takes the .tar.gz files as input

    builders:
      # The regular builder config, creates .tar.gz files.
      regular_builder:
        import: "package:my_package/builder.dart"
        builder_factories: ["myBuilder"]
        build_extensions: {".dart": [".tar.gz"]}
        auto_apply: dependents
        apply_builders: [":archive_extract_builder"]
    post_process_builders:
      # The post process builder config, extracts .tar.gz files.
      extract_archive_builder:
        import: "package:my_package/extract_archive_builder.dart"
        builder_factory: "myExtractArchiveBuilder"
        input_extensions: [".tar.gz"]
    

    so with source_gen you should implement for your build

    applies_builders: ["source_gen|combining_builder", "json_serializable"]
    

    and configure the other builder

    json_serializable:
        import: "package:json_serializable/builder.dart"
        builder_factories: ["jsonSerializable"]
        build_extensions: {".dart": ["json_serializable.g.part"]}
        auto_apply: dependents
        build_to: cache
        applies_builders: ["source_gen|combining_builder"]
    

提交回复
热议问题