Coder Social home page Coder Social logo

Comments (7)

cyptus avatar cyptus commented on May 19, 2024 2

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.

zolakt avatar zolakt commented on May 19, 2024 1

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.

Rudokus avatar Rudokus commented on May 19, 2024 1

@zolakt I am trying to use your workaround. But it seems it will only generate once with ExportAS.. method.

from reinforced.typings.

pavel-b-novikov avatar pavel-b-novikov commented on May 19, 2024

import { ContractA, ContractB, ContractC } from "contracts";

How much Contracts 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.

Crozin avatar Crozin commented on May 19, 2024

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.

pavel-b-novikov avatar pavel-b-novikov commented on May 19, 2024

Ah, got it.. Well.. It might be not so difficult to do that, but I totally do not have free time.

from reinforced.typings.

mikejf-pr avatar mikejf-pr commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.