CSharpToTypescript2 1.1.2

Transpiles dto.cs files into dto.ts files. Including simple calcualtions.
It is based on Roslyn. So, potentially can transpile code of any complexity but currently intended (and tested) only for simple data transfer classes and simple calculations.
It is compatible with dotnet cli and dotnet watch in particular.
As input takes:
1. List of input folders with cs files (your dtos)
2. Output folder
While the tool is the best of  C#  to Typescript generators I have seen (TypeLite, Typewriter, etc) it does not produce self sufficient set of dto files. The initial setup is more complex then of mentioned tools in exchange of much greater flexebility.
I will try to provide enough information for it to use but it may be not sufficient. In such a case please consult the working example with the transpiler integrated here: https://github.com/alehro/AspNetCoreSpa
Since the transpiler by itself doesn't have public repo please feel free to post its issues to the demo SPA project.

There is a newer version of this package available.
See the version list below for details.
Install-Package CSharpToTypescript2 -Version 1.1.2
dotnet add package CSharpToTypescript2 --version 1.1.2
<PackageReference Include="CSharpToTypescript2" Version="1.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSharpToTypescript2 --version 1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CSharpToTypescript2, 1.1.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install CSharpToTypescript2 as a Cake Addin
#addin nuget:?package=CSharpToTypescript2&version=1.1.2

// Install CSharpToTypescript2 as a Cake Tool
#tool nuget:?package=CSharpToTypescript2&version=1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

This is documentation file for CSharpToTypescript2 nuget package.

Usage

The transpiler is not only nuget package by itself. You need to create runner console application in the solution where you want to use the tool with code:

using System;

namespace Cs2Ts
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine(@"Please specify absolute path to config file as first argument");
                throw new ArgumentException();
            }
            CSharpToTypescript.Runner.Run(args[0]);
        }
    }
}

Configuration yaml file is needed like:

OutputDir: src\AspNetCoreSpa.Web\ClientApp\_Site\_TsDtos
InputDirs: 
    - src\AspNetCoreSpa.Core
    - src\AspNetCoreSpa.Web\ClientApp
InputFilesFilterRegex: .*DTOE?[.]cs$
TsHeader: |
    //Caution, this file is autogenerated by TsGenerator module. Don't change the file by hands.
    import { Gender, DateTimeOffset, ICollection, Dictionary, IEnumerable, IList, List, strEnum} from '../CsTypes';

Also you need to add build hook to your Web project file like:

<Target Name="GenerateTs1" AfterTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
	<Exec Command="echo Ts generation started." />
		<Exec Command="dotnet exec $(ProjectDir)..\Cs2Ts\$(OutDir)Cs2Ts.dll $(ProjectDir)..\..\csharptotypescript.yml" ConsoleToMSBuild="true">
			<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
		</Exec>
	<Exec Command="echo Ts generation started." />
</Target>

This is documentation file for CSharpToTypescript2 nuget package.

Usage

The transpiler is not only nuget package by itself. You need to create runner console application in the solution where you want to use the tool with code:

using System;

namespace Cs2Ts
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine(@"Please specify absolute path to config file as first argument");
                throw new ArgumentException();
            }
            CSharpToTypescript.Runner.Run(args[0]);
        }
    }
}

Configuration yaml file is needed like:

OutputDir: src\AspNetCoreSpa.Web\ClientApp\_Site\_TsDtos
InputDirs: 
    - src\AspNetCoreSpa.Core
    - src\AspNetCoreSpa.Web\ClientApp
InputFilesFilterRegex: .*DTOE?[.]cs$
TsHeader: |
    //Caution, this file is autogenerated by TsGenerator module. Don't change the file by hands.
    import { Gender, DateTimeOffset, ICollection, Dictionary, IEnumerable, IList, List, strEnum} from '../CsTypes';

Also you need to add build hook to your Web project file like:

<Target Name="GenerateTs1" AfterTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
	<Exec Command="echo Ts generation started." />
		<Exec Command="dotnet exec $(ProjectDir)..\Cs2Ts\$(OutDir)Cs2Ts.dll $(ProjectDir)..\..\csharptotypescript.yml" ConsoleToMSBuild="true">
			<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
		</Exec>
	<Exec Command="echo Ts generation started." />
</Target>

Release Notes

This is first working release. See that in work at https://github.com/alehro/AspNetCoreSpa

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.7 819 8/14/2020
1.1.6 157 8/13/2020
1.1.5 171 7/15/2020
1.1.4 229 3/18/2020
1.1.3 552 11/10/2019
1.1.2 196 11/10/2019
1.1.0 197 11/10/2019
0.7.2 207 10/27/2019
0.7.1 205 10/26/2019
0.7.0 213 10/26/2019
Show less