-
Notifications
You must be signed in to change notification settings - Fork 76
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 index.ts file when using modules #34
Comments
How much Also RT intentionally reveals each import to separate line to avoid long |
Right now I'm working on a project with few dozen of C# contract classes (input/output DTOs for WebAPI) divided into serveral namespaces. I'm using What I was writing about was actual source code of my TS/Angular application where I have to write something like:
Instead of little bit more compact:
Take a look at... let's say |
Ah, got it.. Well.. It might be not so difficult to do that, but I totally do not have free time. |
i managed this by generating the models into single files per namespace: [assembly: TsGlobal(
GenerateDocumentation = true,
UseModules = true,
DiscardNamespacesWhenUsingModules = true)]
namespace xxx.Shared.DTO
{
public class TypingsGeneratorConfiguration
{
public static void Configure(ConfigurationBuilder builder)
{
var dtoInterface = typeof(IDataTransferObject);
var dtoTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => dtoInterface.IsAssignableFrom(x))
.Except(new Type[] { typeof(IDataTransferObject) });
builder.ExportAsClasses(dtoTypes, x => x.WithPublicProperties().ExportTo(NamespaceToFilename(x.Type.Namespace)));
}
public static string NamespaceToFilename(string namespaceName)
{
return String.Join("/", namespaceName.Replace("xxx.Shared.", "").Split('.')) + ".ts";
}
}
} (i replace the namespace prefix to shorten the path to the models) |
I'd like to throw my voice behind this request: we prefer to split out the classes into separate files for convenience and avoiding git merge hell in large many-person projects, but it does cause the irritations that Crozin has raised. |
I'm throwing in my vote for this feature as well. Basically, you generate each class 2 times: once with a "normal" generator, and once with this "IndexTsGenerator"
And when you call the generator, you do something like this:
|
@zolakt I am trying to use your workaround. But it seems it will only generate once with ExportAS.. method. |
Automatic generation of
index.ts
file containing imports would be a pretty neat feature. AFAIK right now if we're using modules we need to import each file independently in TS code:If Reinforced.Typings would generate two
index.ts
files insidecontracts
andcontracts/sub
directories we would be able to improve readability:The text was updated successfully, but these errors were encountered: