Skip to content

Commit

Permalink
Build: (0428f02) Merge pull request #11 from AndrewDRX/development
Browse files Browse the repository at this point in the history
Enhancement: Custom CSPROJ
  • Loading branch information
SomeRanDev committed Feb 22, 2024
1 parent 7c68a24 commit 6b35683
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
27 changes: 22 additions & 5 deletions src/cscompiler/CSCompiler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package cscompiler;

#if (macro || cs_runtime)

import sys.io.File;

import haxe.io.Path;
import haxe.macro.Expr;
import haxe.macro.Type;

Expand All @@ -24,6 +27,7 @@ using reflaxe.helpers.TypeHelper;
// ---

import cscompiler.components.*;
import cscompiler.config.Define;

/**
The class that manages the generation of the C# code.
Expand Down Expand Up @@ -126,18 +130,31 @@ namespace Haxe {
}

/**
Generates the .csproj file.
Adds a .csproj file to the output directory.
If the Define `no-csproj` is specified, then nothing is added.
Otherwise, if the Define `csproj` specifies a path to an existing
.csproj file, then that is used.
Otherwise, a default .csproj is generated.
**/
function setupCsProj() {
if(!Context.defined("no-csproj")) {
appendToExtraFile("build.csproj", csProjContent());
if (D_NoCsproj.isDefined()) {
return;
}
if (!D_Csproj.isDefined()) {
appendToExtraFile("build.csproj", csProjDefaultContent());
return;
}
final path = new Path(Context.resolvePath(D_Csproj.getValue()));
appendToExtraFile('${path.file}.${path.ext}', File.getContent(path.toString()));
}

/**
Returns the content of the .csproj file.
Returns the default content of the .csproj file.
**/
function csProjContent() {
function csProjDefaultContent() {
return StringTools.trim('
<Project Sdk="Microsoft.NET.Sdk">

Expand Down
28 changes: 24 additions & 4 deletions src/cscompiler/config/Define.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,41 @@ package cscompiler.config;
import reflaxe.helpers.Context; // same as haxe.macro.Context

/**
Lists all the custom defines available for configuring Reflaxe/C#.
Lists all the custom defines available for configuring Reflaxe/C#.
**/
@:using(cscompiler.config.Define.DefineTools)
enum abstract Define(String) from String to String {
/**
-D csproj=[path to file]
When set, the csproj at the specified path will be used for C#
instead of an auto-generated csproj.
This will be ignored when the `Define` `no-csproj` is set.
**/
var D_Csproj = "csproj";

/**
-D namespace_style=[default|pascal]
Default value: `default`
Default value: `default`
Determines how namespace names are generated for C#.
If set to `pascal`, snake-case package names are converted
to pascal-case C# namespaces.
If set to `pascal`, snake-case package names are converted
to pascal-case C# namespaces.
**/
var D_NamespaceStyle = "namespace_style";

/**
-D no-csproj
When set, a csproj file will not be generated C#.
This also applies to any csproj file specified with
the Define `csproj`.
**/
var D_NoCsproj = "no-csproj";
}

/**
Expand Down

0 comments on commit 6b35683

Please sign in to comment.