Skip to content

Commit 25d0cb5

Browse files
committed
Added parser option to tool.
Removed fallback namespace of BabylonJS, is now Generated.
1 parent 6b31f9f commit 25d0cb5

File tree

6 files changed

+55
-28
lines changed

6 files changed

+55
-28
lines changed

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/GenerateClassStatementString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ TextFormatter textFormatter
4949
var classGenerationTemplates = ReadTemplates.Read();
5050

5151
// Generate Tokens
52-
var namespaceReplaced = classStatement.Namespace.Replace("BABYLON", "BabylonJS");
52+
var namespaceReplaced = classStatement.Namespace;
5353
if (string.IsNullOrWhiteSpace(namespaceReplaced))
5454
{
55-
namespaceReplaced = "BabylonJS";
55+
namespaceReplaced = "Generated";
5656
}
5757
classTokenMap["[[NAMESPACE]]"] = namespaceReplaced;
5858
classTokenMap["[[CLASS_NAME]]"] = classStatement.Name;

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/GenerateSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public bool Run(
4545
GlobalLogger.Info($"=== Consolidated Source Files | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");
4646

4747
stopwatch.Restart();
48-
GlobalLogger.Info($"=== Generated AST");
48+
GlobalLogger.Info($"=== Generated AST - {parserType}");
4949
var ast = ASTParser.ParseText(
5050
sourceFilesAsText,
5151
new ASTParserOptions

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/ExpectedResults/interface.Expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Generated - Do Not Edit
2-
namespace BabylonJS
2+
namespace Generated
33
{
44
using System;
55
using System.Collections.Generic;

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Generated - Do Not Edit
2-
namespace BabylonJS
2+
namespace Generated
33
{
44
using System;
55
using System.Collections.Generic;

Tool/EventHorizon.Blazor.TypeScript.Interop.Tool/EventHorizon.Blazor.TypeScript.Interop.Tool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PropertyGroup>
1919
<DefaultItemExcludes>$(DefaultItemExcludes);_generated\**\*;_sourceFiles\**\*</DefaultItemExcludes>
2020
</PropertyGroup>
21-
21+
2222
<ItemGroup>
2323
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20371.2" />
2424
</ItemGroup>

Tool/EventHorizon.Blazor.TypeScript.Interop.Tool/Program.cs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.CommandLine;
4-
using System.CommandLine.Invocation;
5-
using System.Diagnostics;
6-
using System.IO;
7-
using System.Net;
8-
using EventHorizon.Blazor.TypeScript.Interop.Generator;
9-
using EventHorizon.Blazor.TypeScript.Interop.Generator.Formatter;
10-
using EventHorizon.Blazor.TypeScript.Interop.Generator.Logging;
11-
using EventHorizon.Blazor.TypeScript.Interop.Generator.Writers.Project;
12-
using EventHorizon.Blazor.TypeScript.Interop.Tool.ToolException;
13-
141
namespace EventHorizon.Blazor.TypeScript.Interop.Tool
152
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.CommandLine;
6+
using System.CommandLine.Invocation;
7+
using System.Diagnostics;
8+
using System.IO;
9+
using System.Net;
10+
using EventHorizon.Blazor.TypeScript.Interop.Generator;
11+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Model;
12+
using EventHorizon.Blazor.TypeScript.Interop.Generator.Formatter;
13+
using EventHorizon.Blazor.TypeScript.Interop.Generator.Logging;
14+
using EventHorizon.Blazor.TypeScript.Interop.Generator.Writers.Project;
15+
using EventHorizon.Blazor.TypeScript.Interop.Tool.ToolException;
16+
1617
class Program
1718
{
1819
private static readonly string SOURCE_FILES_DIRECTORY_NAME = "_sourceFiles";
@@ -50,13 +51,18 @@ static int Main(string[] args)
5051
new string[] { "--force", "-f" },
5152
getDefaultValue: () => false,
5253
description: "This will force generation, by deleting --project-generation-location"
53-
)
54+
),
55+
new Option<string>(
56+
new string[] { "--parser", "-p" },
57+
getDefaultValue: () => "dotnet",
58+
description: "The type of TypeScript parser to use, 'dotnet' will use the embedded .NET parser. 'nodejs' will use the TypeScript compiler through NodeJS (requires NodeJS installed)."
59+
),
5460
};
5561

56-
rootCommand.Description = "Generate a Blazor WASM project from a TypeScript definition file.";
62+
rootCommand.Description = "Generate a Blazor Wasm project from a TypeScript definition file.";
5763

5864
// Note that the parameters of the handler method are matched according to the names of the options
59-
rootCommand.Handler = CommandHandler.Create<IList<string>, IList<string>, string, string, bool>(
65+
rootCommand.Handler = CommandHandler.Create<IList<string>, IList<string>, string, string, bool, string>(
6066
GenerateSources
6167
);
6268

@@ -67,9 +73,10 @@ static int Main(string[] args)
6773
private static int GenerateSources(
6874
IList<string> source,
6975
IList<string> classToGenerate,
70-
string projectAssembly = "Generated.WASM",
76+
string projectAssembly = "Generated.Wasm",
7177
string projectGenerationLocation = "_generated",
72-
bool force = false
78+
bool force = false,
79+
string parser = "dotnet"
7380
)
7481
{
7582
try
@@ -79,10 +86,12 @@ private static int GenerateSources(
7986
source,
8087
classToGenerate,
8188
projectAssembly,
82-
projectGenerationLocation
89+
projectGenerationLocation,
90+
parser
8391
);
8492
GlobalLogger.Info($"projectAssembly: {projectAssembly}");
8593
GlobalLogger.Info($"projectGenerationLocation: {projectGenerationLocation}");
94+
GlobalLogger.Info($"parser: {parser}");
8695

8796
GlobalLogger.Info($"classToGenerate.Length: {classToGenerate.Count}");
8897
foreach (var classToGenerateItem in classToGenerate)
@@ -154,8 +163,8 @@ private static int GenerateSources(
154163
textFormatter,
155164
new Dictionary<string, string>
156165
{
157-
{ "BABYLON.PointerInfoBase | type", "int" }
158-
}
166+
},
167+
GetParserType(parser)
159168
);
160169
stopwatch.Stop();
161170
GlobalLogger.Success($"Took {stopwatch.ElapsedMilliseconds}ms to Generate Source Project.");
@@ -182,7 +191,8 @@ private static void ValidateArguments(
182191
IList<string> sources,
183192
IList<string> classToGenerate,
184193
string projectAssembly,
185-
string projectGenerationLocation
194+
string projectGenerationLocation,
195+
string parser
186196
)
187197
{
188198
if (sources == null || sources.Count == 0)
@@ -217,6 +227,15 @@ string projectGenerationLocation
217227
"Project Generation Location was null or empty."
218228
);
219229
}
230+
if (string.IsNullOrWhiteSpace(
231+
parser
232+
) || (parser.ToLower() != "dotnet" && parser.ToLower() != "nodejs"))
233+
{
234+
throw new ToolArgumentException(
235+
"--parser",
236+
"Invalid parser found. Valid Parsers: [dotnet, nodejs]"
237+
);
238+
}
220239
}
221240

222241
/// <summary>
@@ -305,5 +324,13 @@ private static bool IsUrl(
305324
string sourceFile
306325
) => sourceFile.StartsWith("http://")
307326
|| sourceFile.StartsWith("https://");
327+
328+
private static ASTParserType GetParserType(
329+
string parserType
330+
) => parserType switch
331+
{
332+
"nodejs" => ASTParserType.NodeJS,
333+
_ => ASTParserType.Sdcb,
334+
};
308335
}
309336
}

0 commit comments

Comments
 (0)