Skip to content

Commit

Permalink
Merge pull request #3 from BastianBlokland/feature/generator-3.3
Browse files Browse the repository at this point in the history
Update to EnumGenerator.Core 3.3.1203
  • Loading branch information
BastianBlokland authored Aug 8, 2019
2 parents 1b552b2 + abf6a0c commit 913ed42
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 26 deletions.
25 changes: 15 additions & 10 deletions .ci/update-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,27 @@ saveDll ()
processPackage ()
{
local packageName="$(basename $1)"
local supportedFrameworks=(netstandard2.0 netstandard1.3)
info "Processing package: $packageName"

local netstandard2Dir="$1/lib/netstandard2.0/"
if [ ! -d "$netstandard2Dir" ]
then
fail "No 'netstandard2.0' library found for package: $packageName"
fi

echo "$packageName" >> "$LIBRARY_DIR/manifest.txt"
for dllPath in "$netstandard2Dir"*.dll
for framework in "${supportedFrameworks[@]}"
do
saveDll "$dllPath" "$packageName"
local frameworkDir="$1/lib/$framework/"
if [ -d "$frameworkDir" ]
then
echo "$packageName" >> "$LIBRARY_DIR/manifest.txt"
for dllPath in "$frameworkDir"*.dll
do
saveDll "$dllPath" "$packageName"
done
return 0;
fi
done

fail "No supported framework found for package: $packageName"
}

# Extract all netstandard2.0 dll's from the packages.
# Extract the needed dll's from the packages.
for packageDir in "$NUGET_DIR"/*
do
processPackage $packageDir
Expand Down
11 changes: 9 additions & 2 deletions .ci/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ warn()
fi
}

fail ()
fail()
{
echo $1 >&2
if [ -z "$NO_COLORS" ]
then
RED='\033[0;31m'
NORMAL='\033[0m'
echo -e "${RED}ERROR: ${1}${NORMAL}" >&2
else
echo -e "ERROR: $1" >&2
fi
exit 1
}

Expand Down
Binary file added .example/.ionide/symbolCache.db
Binary file not shown.
Binary file modified .example/Assets/lib/EnumGenerator.Core.dll
Binary file not shown.
Binary file added .example/Assets/lib/Mono.Cecil.Mdb.dll
Binary file not shown.
33 changes: 33 additions & 0 deletions .example/Assets/lib/Mono.Cecil.Mdb.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .example/Assets/lib/Mono.Cecil.Pdb.dll
Binary file not shown.
33 changes: 33 additions & 0 deletions .example/Assets/lib/Mono.Cecil.Pdb.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .example/Assets/lib/Mono.Cecil.Rocks.dll
Binary file not shown.
33 changes: 33 additions & 0 deletions .example/Assets/lib/Mono.Cecil.Rocks.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .example/Assets/lib/Mono.Cecil.dll
Binary file not shown.
33 changes: 33 additions & 0 deletions .example/Assets/lib/Mono.Cecil.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified .lib/EnumGenerator.Core.dll
Binary file not shown.
Binary file added .lib/Mono.Cecil.Mdb.dll
Binary file not shown.
Binary file added .lib/Mono.Cecil.Pdb.dll
Binary file not shown.
Binary file added .lib/Mono.Cecil.Rocks.dll
Binary file not shown.
Binary file added .lib/Mono.Cecil.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion .lib/manifest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EnumGenerator.Core.3.2.1196
EnumGenerator.Core.3.3.1203
Microsoft.Extensions.Configuration.2.2.0
Microsoft.Extensions.Configuration.Abstractions.2.2.0
Microsoft.Extensions.Configuration.Binder.2.2.0
Expand All @@ -7,6 +7,7 @@ Microsoft.Extensions.Logging.2.2.0
Microsoft.Extensions.Logging.Abstractions.2.2.0
Microsoft.Extensions.Options.2.2.0
Microsoft.Extensions.Primitives.2.2.0
Mono.Cecil.0.10.4
Newtonsoft.Json.12.0.1
System.Buffers.4.4.0
System.Collections.Immutable.1.5.0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ having to hard code values, this tool allows you to generate that enum.

```
"dependencies": {
"com.bastianblokland.enumgenerator": "https://github.com/BastianBlokland/enum-generator-unity.git#v1.2",
"com.bastianblokland.enumgenerator": "https://github.com/BastianBlokland/enum-generator-unity.git#v1.3",
...
}
```
2. Add the NuGet dependency to your project.
If your project uses a NuGet package manager you can simply add a dependency to [**EnumGenerator.Core**](https://www.nuget.org/packages/EnumGenerator.Core/) version `3.2.*`.
If your project uses a NuGet package manager you can simply add a dependency to [**EnumGenerator.Core**](https://www.nuget.org/packages/EnumGenerator.Core/) version `3.3.*`.
If you are not using a NuGet package manager you can simply copy the dll's from the [`.lib`](https://github.com/BastianBlokland/enum-generator-unity/tree/master/.lib) directory to your project.
Expand Down
39 changes: 31 additions & 8 deletions src/GeneratorApi.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text;
using Microsoft.Extensions.Logging;

using EnumGenerator.Core.Utilities;
Expand All @@ -15,6 +16,8 @@ namespace EnumGenerator.Editor
/// </summary>
public static class GeneratorApi
{
private static readonly Encoding Utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

/// <summary>
/// Generate enum file.
/// </summary>
Expand Down Expand Up @@ -129,21 +132,21 @@ public static void GenerateEnumToFile(
return;
}

// Export to source-code.
string output = null;
// Export.
byte[] output = null;
switch (outputType)
{
case OutputType.CSharp:
try
{
output = enumDefinition.ExportCSharp(
output = Utf8NoBom.GetBytes(enumDefinition.ExportCSharp(
enumNamespace,
headerMode,
indentMode,
indentSize,
newlineMode,
storageType,
curlyBracketMode);
curlyBracketMode));
}
catch (Exception e)
{
Expand All @@ -156,22 +159,38 @@ public static void GenerateEnumToFile(
case OutputType.Cil:
try
{
output = enumDefinition.ExportCil(
output = Utf8NoBom.GetBytes(enumDefinition.ExportCil(
assemblyName: enumName,
enumNamespace,
headerMode,
indentMode,
indentSize,
newlineMode,
storageType,
curlyBracketMode);
curlyBracketMode));
}
catch (Exception e)
{
logger?.LogCritical($"Failed to generate cil: {e.Message}");
return;
}

break;

case OutputType.ClassLibrary:
try
{
output = enumDefinition.ExportClassLibrary(
assemblyName: enumName,
enumNamespace,
storageType);
}
catch (Exception e)
{
logger?.LogCritical($"Failed to generate classlibrary: {e.Message}");
return;
}

break;
}

Expand All @@ -189,8 +208,8 @@ public static void GenerateEnumToFile(
Directory.CreateDirectory(outputDir);
}

File.WriteAllText(fullPath, output);
logger?.LogInformation($"Saved enum: '{outputPath}'");
File.WriteAllBytes(fullPath, output);
logger?.LogInformation($"Saved enum: '{fullPath}'");
}
catch (Exception e)
{
Expand Down Expand Up @@ -231,6 +250,8 @@ private static string GetRequiredExtension(OutputType outputType)
return ".cs";
case OutputType.Cil:
return ".il";
case OutputType.ClassLibrary:
return ".dll";
default:
throw new InvalidOperationException($"Unknown output: '{outputType}'.");
}
Expand All @@ -244,6 +265,8 @@ private static string GetDesiredExtension(OutputType outputType)
return ".g.cs";
case OutputType.Cil:
return ".g.il";
case OutputType.ClassLibrary:
return ".dll";
default:
throw new InvalidOperationException($"Unknown output: '{outputType}'.");
}
Expand Down
11 changes: 8 additions & 3 deletions src/OutputType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
public enum OutputType
{
/// <summary>
/// Produce a CSharp source file.
/// Produce a CSharp (.cs) source file.
/// </summary>
CSharp = 0,

/// <summary>
/// Produce a Cil source file.
/// Produce a Cil (.il) source file.
/// </summary>
Cil = 1
Cil = 1,

/// <summary>
/// Produce a class-library (.dll) file.
/// </summary>
ClassLibrary = 2
}
}

0 comments on commit 913ed42

Please sign in to comment.