Comments (7)
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)
from reinforced.typings.
I'm throwing in my vote for this feature as well.
For anyone interested, here is the workaround I have currently, with a custom TsCodeGeneratorBase.
Basically, you generate each class 2 times: once with a "normal" generator, and once with this "IndexTsGenerator"
public class IndexTsGenerator : TsCodeGeneratorBase<Type, RtRaw>
{
public override RtRaw GenerateNode(Type element, RtRaw node, TypeResolver resolver)
{
return new RtRaw($"export * from './{element.Name}'");
}
}
And when you call the generator, you do something like this:
...
classBuilder
.WithAllProperties()
.ExportTo(filePath);
classBuilder
.ExportTo("index.ts")
.WithCodeGenerator<IndexTsGenerator>();
...
from reinforced.typings.
@zolakt I am trying to use your workaround. But it seems it will only generate once with ExportAS.. method.
from reinforced.typings.
import { ContractA, ContractB, ContractC } from "contracts";
How much Contract
s you would like to have?
Also RT intentionally reveals each import to separate line to avoid long import
at the beginning of file. IMHO it does not improve readability, doesnt it?
from reinforced.typings.
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 GlobalConfigurationBuilder.UseModules()
therefore RT generates a separate TS file for each class/type inside hierarchical directory structure. For those files single import per type is absolutely fine. At the end of the day readability of autogenerated sources is not important.
What I was writing about was actual source code of my TS/Angular application where I have to write something like:
import { Component, OnInit } from "@angular/core";
import { Subscription } from "rxjs/Subscription";
import { Listing } from "../../../contracts/Listing";
import { Selector } from "../../../contracts/Selector";
import { JobCastSnippetListingEntry } from "../../../contracts/Projections/JobCastSnippetListingEntry";
import { CategoryNode } from "../../../contracts/Projections/CategoryNode";
import { JobCastListingFilters } from "../../../contracts/Filters/JobCastListingFilters";
Instead of little bit more compact:
import { Component, OnInit } from "@angular/core";
import { Subscription } from "rxjs/Subscription";
import { Listing, Selector } from "../../../contracts";
import { JobCastSnippetListingEntry, CategoryNode } from "../../../contracts/Projections";
import { JobCastListingFilters } from "../../../contracts/Filters";
Take a look at... let's say angular/http
: https://github.com/angular/angular/tree/master/packages/http/src - several TS files and one index.ts
with exports.
from reinforced.typings.
Ah, got it.. Well.. It might be not so difficult to do that, but I totally do not have free time.
from reinforced.typings.
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.
from reinforced.typings.
Related Issues (20)
- Invalid code generated when C# code inherits from generic
- v1.6.1 does not support .NET 7 HOT 23
- Invalid code generated for explicit interface member implementation
- Export public static properties of static class to enum HOT 2
- Add raw line to output file (for example to disable eslint errors) HOT 3
- Is it possible to generate union?
- RT0999: Input string was not in a correct format.
- Are SDK Projects supported? HOT 3
- MSB6006 "" exited with code -214745073
- Issue when base class is exported as interface HOT 1
- feat: Net8 support HOT 24
- <RtDisable> and <TreatWarningsAsError> not working HOT 1
- Error MSB6006: "" exited with code 1. HOT 2
- The AddImports feature should allow you to select what quotes to use
- Generated Typescript loses information about combined enum flags when using UseString
- Improved compilation of JSDOC
- JSDOC for enums
- Add a custom property to a class HOT 4
- feat: Net9 support
- Empty file generated?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reinforced.typings.