-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
938dfaa
commit fefa208
Showing
18 changed files
with
1,154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NuProj" version="0.9.3-beta" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|AnyCPU"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>AnyCPU</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|AnyCPU"> | ||
<Configuration>Release</Configuration> | ||
<Platform>AnyCPU</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>8d9c370f-e27c-4c1f-86a7-97b33da3f0de</ProjectGuid> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<NuProjPath Condition=" '$(BuildingInsideVisualStudio)' != 'true'">$(MSBuildProjectDirectory)\..\packages\NuProj.0.9.3-beta\tools\</NuProjPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<NuProjPath Condition=" '$(NuProjPath)' == '' ">$(MSBuildExtensionsPath)\NuProj\</NuProjPath> | ||
</PropertyGroup> | ||
<Import Project="$(NuProjPath)\NuProj.props" Condition="Exists('$(NuProjPath)\NuProj.props')" /> | ||
<PropertyGroup Label="Configuration"> | ||
<Id>CS2TS</Id> | ||
<Version>1.0.0-beta1</Version> | ||
<Title>CSharp To Typescript</Title> | ||
<Authors>Alex Perovich</Authors> | ||
<Owners>Alex Perovich</Owners> | ||
<Summary>CS2TS-Nuget</Summary> | ||
<Description>CS2TS-Nuget</Description> | ||
<ReleaseNotes> | ||
</ReleaseNotes> | ||
<ProjectUrl> | ||
</ProjectUrl> | ||
<LicenseUrl> | ||
</LicenseUrl> | ||
<Copyright>Copyright © Alex Perovich</Copyright> | ||
<Tags>C#;CSharp;Typescript</Tags> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Content Include="build\CS2TS.targets" /> | ||
<Content Include="Readme.txt" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\CS2TS\CS2TS.csproj" /> | ||
</ItemGroup> | ||
<Import Project="$(NuProjPath)\NuProj.targets" /> | ||
<Target Name="ExpandProjectReferences" DependsOnTargets="SplitProjectReferences" Inputs="%(_NonNuProjProjectReference.Identity)" Outputs="fake"> | ||
<MSBuild Targets="$(ProjectOutputGroups)" Projects="%(_NonNuProjProjectReference.Identity)" Properties="$(ProjectProperties)"> | ||
<Output TaskParameter="TargetOutputs" ItemName="_NonNuProjProjectOutput" /> | ||
</MSBuild> | ||
<MSBuild Targets="GetTargetPath" Projects="%(_NonNuProjProjectReference.Identity)" Properties="$(ProjectProperties)"> | ||
<Output TaskParameter="TargetOutputs" PropertyName="_NonNuProjProjectTargetPath" /> | ||
</MSBuild> | ||
<PropertyGroup> | ||
<_NonNuProjProjectTargetPath>$([System.IO.Path]::GetDirectoryName($(_NonNuProjProjectTargetPath)))\</_NonNuProjProjectTargetPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<_NonNuProjProjectOutput Remove="@(_NonNuProjProjectOutput)" Condition="!Exists('$(_NonNuProjProjectTargetPath)%(_NonNuProjProjectOutput.Filename)%(_NonNuProjProjectOutput.Extension)') " /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Tool Include="@(_NonNuProjProjectOutput)"> | ||
<TargetPath>%(Filename)%(Extension)</TargetPath> | ||
</Tool> | ||
</ItemGroup> | ||
</Target> | ||
<Target Name="GetPackageDependencies"> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This nuget package provides an MSBuild target for producing Typescript declaration files for data transfer classes and structs defined in C# files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<CS2TSToolDirectory Condition="'$(CS2TSToolDirectory)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\tools\'))</CS2TSToolDirectory> | ||
<CS2TSToolPath Condition="'$(CS2TSToolPath)' == ''">$(CS2TSToolDirectory)\CS2TS.exe</CS2TSToolPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<CS2TSTypeScriptOutput Condition="'$(CS2TSTypeScriptDefinitionFile)' == ''">$(MSBuildProjectDirectory)\Scripts\generatedTypes.ts</CS2TSTypeScriptOutput> | ||
</PropertyGroup> | ||
|
||
<Target BeforeTargets="PreComputeCompileTypeScript;CoreCompile" Name="GenerateTypeDeclarations" Inputs="@(Compile->WithMetadataValue('ProcessToTypescript', 'true'));@(CS2TSInputFile)" Outputs="$(CS2TSTypeScriptDefinitionFile)" | ||
DependsOnTargets="ResolveReferences"> | ||
<ItemGroup> | ||
<CS2TSInputFile Include="@(Compile->WithMetadataValue('ProcessToTypescript', 'true'))"/> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<CS2TSReferencePaths>@(ReferencePath -> '-r "%(FullPath)"', ' ')</CS2TSReferencePaths> | ||
<InputFileList>@(CS2TSInputFile -> '"%(FullPath)"', ' ')</InputFileList> | ||
</PropertyGroup> | ||
<Exec Command='"$(CS2TSToolPath)" -o "$(CS2TSTypeScriptOutput)" $(CS2TSReferencePaths) $(InputFileList)'/> | ||
<ItemGroup> | ||
<FileWrites Include="$(CS2TSTypeScriptOutput)"/> | ||
<TypeScriptCompile Include="$(CS2TSTypeScriptOutput)"/> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<InputFileList/> | ||
<CS2TSReferencePaths/> | ||
</PropertyGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Remoting.Channels; | ||
using Xunit; | ||
|
||
namespace CS2TS.Tests | ||
{ | ||
public class Arrays | ||
{ | ||
public static IEnumerable<object[]> TypeData | ||
{ | ||
get | ||
{ | ||
return TypeInformation.TsTypeAndCsTypeParams.PrependParameters( | ||
new[] | ||
{ | ||
"IEnumerable<{0}>", | ||
"ICollection<{0}>", | ||
"IList<{0}>", | ||
"IReadOnlyCollection<{0}>", | ||
"IReadOnlyList<{0}>", | ||
"{0}[]", | ||
"List<{0}>", | ||
"HashSet<{0}>", | ||
"Collection<{0}>" | ||
}).AppendParameters(new object[] | ||
{ | ||
true, | ||
false | ||
}).AppendParameters(new object[] | ||
{ | ||
"struct", | ||
"class", | ||
"interface" | ||
}); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData("TypeData")] | ||
public void Enumerable(string propertyTypeFormat, string expectedTypescriptType, string memberType, bool generateDeclarations, string typeType) | ||
{ | ||
var input = string.Format(@" | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
namespace Foo | ||
{{ | ||
public {1} Test | ||
{{ | ||
{2}{0} Prop {{ get; set; }} | ||
}} | ||
}} | ||
", string.Format(propertyTypeFormat, memberType), typeType, typeType != "interface" ? "public " : ""); | ||
|
||
var processor = new TypeScriptProcessor(new []{input}, new[] {typeof(HashSet<>).Assembly.Location}); | ||
var output = processor.GetTypescriptAsString(generateDeclarations); | ||
Assert.Equal(string.Format(@"{1} interface Test {{ | ||
Prop?: {0}[]; | ||
}} | ||
", expectedTypescriptType, generateDeclarations ? "declare" : "export"), output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" /> | ||
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0-beta2-build1055\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0-beta2-build1055\build\net20\xunit.runner.visualstudio.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{0738432D-A2CD-4DFA-BCD1-A8212DC71E0D}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CS2TS.Tests</RootNamespace> | ||
<AssemblyName>CS2TS.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<NuGetPackageImportStamp>bfd379d0</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Runtime.Serialization" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath> | ||
</Reference> | ||
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Arrays.cs" /> | ||
<Compile Include="ClassTypeMembers.cs" /> | ||
<Compile Include="PlainStruct.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="TypeInformation.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\CS2TS\CS2TS.csproj"> | ||
<Project>{44cf3e9f-f83f-4b60-97c3-eb1fe140082f}</Project> | ||
<Name>CS2TS</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0-beta2-build1055\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0-beta2-build1055\build\net20\xunit.runner.visualstudio.props'))" /> | ||
<Error Condition="!Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" /> | ||
</Target> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace CS2TS.Tests | ||
{ | ||
public class ClassTypeMembers | ||
{ | ||
public static IEnumerable<object[]> Parameters | ||
{ | ||
get | ||
{ | ||
return TypeInformation.TsTypeAndCsTypeParams.AppendParameters( | ||
new object[] | ||
{ | ||
true, | ||
false | ||
}).AppendParameters(new object[] | ||
{ | ||
"struct", | ||
"class", | ||
"interface" | ||
}); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData("Parameters")] | ||
public void Property( | ||
string typescriptType, | ||
string cSharpType, | ||
bool generateDeclarations, | ||
string typeType) | ||
{ | ||
var input = string.Format(@" | ||
using System; | ||
namespace Foo | ||
{{ | ||
public {1} Test | ||
{{ | ||
{2}{0} Prop {{ get; set; }} | ||
}} | ||
public {1} Test2 | ||
{{ | ||
{2}Test Prop {{ get; set; }} | ||
}} | ||
}} | ||
", cSharpType, typeType, typeType != "interface" ? "public " : ""); | ||
|
||
var processor = new TypeScriptProcessor(input); | ||
var output = processor.GetTypescriptAsString(generateDeclarations); | ||
Assert.Equal(string.Format(@"{2} interface Test {{ | ||
Prop{1}: {0}; | ||
}} | ||
{2} interface Test2 {{ | ||
Prop{3}: Test; | ||
}} | ||
", typescriptType, cSharpType.ToLower().Contains("string") ? "?" : "", generateDeclarations ? "declare" : "export", typeType == "struct" ? "" : "?"), output); | ||
} | ||
} | ||
} |
Oops, something went wrong.