Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to use this package #322

Closed
Rodsevich opened this issue Apr 5, 2018 · 12 comments
Closed

Explain how to use this package #322

Rodsevich opened this issue Apr 5, 2018 · 12 comments
Assignees

Comments

@Rodsevich
Copy link

I've been trying hard enough to figure out how to use this package, reading all the extense build package documentation and that... and I'm still lost.
Can someone please put some trivial e2e example in the wiki, with both the code and the commands needed to generate code and execute it in your project?
Thanks in advance

@kevmoo
Copy link
Member

kevmoo commented Jun 10, 2018

Here are two examples:

https://github.com/dart-lang/json_serializable/tree/master/json_serializable
https://github.com/kevmoo/build_cli/tree/master/build_cli

build_cli is more simple, so it might be a good spot to start.

Agreed, we need better docs here, but this may get you unblocked...

kevmoo added a commit that referenced this issue Jun 10, 2018
Progress towards #322
by making it easier to include a fully functional example
kevmoo added a commit that referenced this issue Jun 11, 2018
Progress towards #322
by making it easier to include a fully functional example
kevmoo added a commit that referenced this issue Jun 11, 2018
Progress towards #322
by making it easier to include a fully functional example
@matanlurey
Copy link
Contributor

I think @kevmoo's comments are likely all we'll have at this point.

Pull requests welcome!

@kevmoo kevmoo self-assigned this Jul 11, 2018
@kevmoo
Copy link
Member

kevmoo commented Jul 11, 2018

I'm going to reopen and keep this assigned to me. Once we publish the bits on master, I want to come back here and add an example.

@kevmoo
Copy link
Member

kevmoo commented Dec 21, 2018

I have a PR out w/ some initial examples. #390

kevmoo added a commit that referenced this issue Dec 22, 2018
natebosch pushed a commit that referenced this issue Dec 26, 2018
@graphicbeacon
Copy link

Hi @kevmoo, thanks for putting up the examples. After spending hours looking over the code, its beginning to click.

However I've seen in example_usage/build.yaml this build configuration for SharedPartBuilders:

source_gen_example|property_sum:
  generate_for:
    - lib/*.dart
source_gen_example|property_product:
  generate_for:
    - lib/*.dart

And I would like to know:

Why upon removing this configuration, the contents of the build output file example_usage/lib/library_source.g.dart remain the same?

So far I've seen that it relates to this line in example_usage/lib/library_source.dart:

part 'library_source.g.dart';

Removing that line understandably does not create library_source.g.dart, so what then is the purpose of the snippet in example_usage/build.yaml?

@natebosch
Copy link
Member

@graphicbeacon - the purpose of the generate_for argument in the example is to limit the files that are generated. By default a Builder can apply to all files in a target, and by default the target includes everything in lib/, web/, bin/, and example/ among others:

https://github.com/dart-lang/build/blob/92a4482a8407009d36f5c94601c4acdd58b64569/build_runner_core/lib/src/generate/options.dart#L21-L31

By adding a generate_for it means that this Builder would only apply to lib/*.dart (note that this is not a recursive glob, so it would not apply to subdirectories). Removing the statement would make it apply to everything in the target again, which includes the files in that glob. If you want to make it apply to nothing you could use generate_for: [] to give an empty list, or better yet use enabled: false.

@graphicbeacon
Copy link

Thank you @natebosch. That clarifies things.

I wish to cover this on my YouTube channel. I hope that will help with documentation.

@kevmoo
Copy link
Member

kevmoo commented Jan 7, 2019

@graphicbeacon – if you want to send a PR adding notes to clarify what you've learned, we'd happily add it!

@kevmoo kevmoo closed this as completed Jan 7, 2019
@ashokgelal
Copy link

ashokgelal commented Apr 21, 2019

The nicely documented build.yaml is very helpful but how would someone actually run the examples? I've added build_runner package and run pub run build_runner x but no luck. I've already spent more than an hour reading through build, build_runner, and build_config docs (oh, my!) and still confused. They seem to point at each other. This package seriously lacks good documentation.

@ashokgelal
Copy link

ashokgelal commented Apr 21, 2019

Ok. now I kind of feel stupid. Looks like I needed to look into https://github.com/dart-lang/source_gen/tree/master/example_usage. But my comment about lack of good documentation that just doesn't point to each other still stands. Outside the official doc, any good tutorial for source_gen is also seriously lacking. Waiting for @graphicbeacon to jump in and create a serious tutorial ;) Big fan of your videos, BTW :)

@kevmoo
Copy link
Member

kevmoo commented Apr 21, 2019 via email

@ashokgelal
Copy link

I got it working (somehow :). Not sure why but I'm sure it was on my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants