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

Add option for generating index file #24

Merged
merged 4 commits into from Jul 1, 2018

Conversation

Projects
None yet
2 participants
@stephtr
Copy link
Contributor

commented Jun 30, 2018

This PR would add the option CreateIndexFile, with which TypeGen would also generate an index.ts which reexports all generated types, such that one can write for example:

import { A, B, C } from './api';

instead of:

import { A } from './api/a';
import { B } from './api/b';
import { C } from './api/c';

I just wonder: Would it be better to access _fileSystem and _templateService from the Generator instead of creating my own instances (which on the other hand would mean having to add them to the IGenerator interface)?

@jburzynski jburzynski changed the base branch from master to dev Jul 1, 2018

@jburzynski jburzynski merged commit 5b79fd2 into jburzynski:dev Jul 1, 2018

1 check passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jul 1, 2018

Thanks for the pull request!

I think it's worth moving the code that generates the index file from Program.cs to Generator.cs. This way it would also be possible to generate index if you're using TypeGen programmatically. Also, createIndexFile parameter would need to be in GeneratorOptions (because Generator only has access to GeneratorOptions). This would also solve the problem of creating services (template service, file system etc.), since they're already in Generator.cs.

I have one question though: do you need to use this functionality in your project? The thing I'm wondering about is: you usually generate many different classes for many different 'domains'/uses/categories (Angular components etc.) per one run (execution) of TypeGen. So I'm not sure if you need an index file with all files in the 'root' directory in most cases (as many of these files are unrelated to each other). Unless you need it for your project, in which case it makes sense to add this functionality (because others may use it this way too).

@stephtr

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2018

I think it's worth moving the code that generates the index file from Program.cs to Generator.cs.

That's absolutely true, yesterday I struggled finding a suitable place, but I just had to make some small modifications (#25).

The thing I'm wondering about is: you usually generate many different classes for many different 'domains'/uses/categories (Angular components etc.) per one run (execution) of TypeGen.

I'm using TypeGen for generating the typing of my web API (request and response objects). For each request written in my client code I import the relevant type definitions. Thankfully I don't have a second category of type definitions created from C#, so creating an index file works (also logically) just fine for reducing the size of the import list in my client code.

@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jul 2, 2018

That makes sense, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.