diff --git a/.ci/update-dependencies.sh b/.ci/update-dependencies.sh index d4329ea..7423901 100755 --- a/.ci/update-dependencies.sh +++ b/.ci/update-dependencies.sh @@ -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 diff --git a/.ci/utils.sh b/.ci/utils.sh index 75c9028..c699c1d 100755 --- a/.ci/utils.sh +++ b/.ci/utils.sh @@ -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 } diff --git a/.example/.ionide/symbolCache.db b/.example/.ionide/symbolCache.db new file mode 100644 index 0000000..7566b89 Binary files /dev/null and b/.example/.ionide/symbolCache.db differ diff --git a/.example/Assets/lib/EnumGenerator.Core.dll b/.example/Assets/lib/EnumGenerator.Core.dll index 03b284a..978cde9 100755 Binary files a/.example/Assets/lib/EnumGenerator.Core.dll and b/.example/Assets/lib/EnumGenerator.Core.dll differ diff --git a/.example/Assets/lib/Mono.Cecil.Mdb.dll b/.example/Assets/lib/Mono.Cecil.Mdb.dll new file mode 100755 index 0000000..9824532 Binary files /dev/null and b/.example/Assets/lib/Mono.Cecil.Mdb.dll differ diff --git a/.example/Assets/lib/Mono.Cecil.Mdb.dll.meta b/.example/Assets/lib/Mono.Cecil.Mdb.dll.meta new file mode 100644 index 0000000..e1eeab8 --- /dev/null +++ b/.example/Assets/lib/Mono.Cecil.Mdb.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: ec7361bd724fc4eb69d4d62e678e3709 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/.example/Assets/lib/Mono.Cecil.Pdb.dll b/.example/Assets/lib/Mono.Cecil.Pdb.dll new file mode 100755 index 0000000..e9e973b Binary files /dev/null and b/.example/Assets/lib/Mono.Cecil.Pdb.dll differ diff --git a/.example/Assets/lib/Mono.Cecil.Pdb.dll.meta b/.example/Assets/lib/Mono.Cecil.Pdb.dll.meta new file mode 100644 index 0000000..3c3f623 --- /dev/null +++ b/.example/Assets/lib/Mono.Cecil.Pdb.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 576a5c898538b4da3a91c4c5f1acfc17 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/.example/Assets/lib/Mono.Cecil.Rocks.dll b/.example/Assets/lib/Mono.Cecil.Rocks.dll new file mode 100755 index 0000000..fda2ef1 Binary files /dev/null and b/.example/Assets/lib/Mono.Cecil.Rocks.dll differ diff --git a/.example/Assets/lib/Mono.Cecil.Rocks.dll.meta b/.example/Assets/lib/Mono.Cecil.Rocks.dll.meta new file mode 100644 index 0000000..26ebe93 --- /dev/null +++ b/.example/Assets/lib/Mono.Cecil.Rocks.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 304080b919c854124b5872553ac2cb43 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/.example/Assets/lib/Mono.Cecil.dll b/.example/Assets/lib/Mono.Cecil.dll new file mode 100755 index 0000000..f2a9b92 Binary files /dev/null and b/.example/Assets/lib/Mono.Cecil.dll differ diff --git a/.example/Assets/lib/Mono.Cecil.dll.meta b/.example/Assets/lib/Mono.Cecil.dll.meta new file mode 100644 index 0000000..39e1ae3 --- /dev/null +++ b/.example/Assets/lib/Mono.Cecil.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 3f3199587be684dd3a30d39e51a5149b +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/.lib/EnumGenerator.Core.dll b/.lib/EnumGenerator.Core.dll index 03b284a..978cde9 100755 Binary files a/.lib/EnumGenerator.Core.dll and b/.lib/EnumGenerator.Core.dll differ diff --git a/.lib/Mono.Cecil.Mdb.dll b/.lib/Mono.Cecil.Mdb.dll new file mode 100755 index 0000000..9824532 Binary files /dev/null and b/.lib/Mono.Cecil.Mdb.dll differ diff --git a/.lib/Mono.Cecil.Pdb.dll b/.lib/Mono.Cecil.Pdb.dll new file mode 100755 index 0000000..e9e973b Binary files /dev/null and b/.lib/Mono.Cecil.Pdb.dll differ diff --git a/.lib/Mono.Cecil.Rocks.dll b/.lib/Mono.Cecil.Rocks.dll new file mode 100755 index 0000000..fda2ef1 Binary files /dev/null and b/.lib/Mono.Cecil.Rocks.dll differ diff --git a/.lib/Mono.Cecil.dll b/.lib/Mono.Cecil.dll new file mode 100755 index 0000000..f2a9b92 Binary files /dev/null and b/.lib/Mono.Cecil.dll differ diff --git a/.lib/manifest.txt b/.lib/manifest.txt index 51f5e4e..057ccb8 100644 --- a/.lib/manifest.txt +++ b/.lib/manifest.txt @@ -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 @@ -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 diff --git a/README.md b/README.md index dcf954d..465b004 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/GeneratorApi.cs b/src/GeneratorApi.cs index 274f056..6164567 100644 --- a/src/GeneratorApi.cs +++ b/src/GeneratorApi.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using Microsoft.Extensions.Logging; using EnumGenerator.Core.Utilities; @@ -15,6 +16,8 @@ namespace EnumGenerator.Editor /// public static class GeneratorApi { + private static readonly Encoding Utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); + /// /// Generate enum file. /// @@ -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) { @@ -156,7 +159,7 @@ public static void GenerateEnumToFile( case OutputType.Cil: try { - output = enumDefinition.ExportCil( + output = Utf8NoBom.GetBytes(enumDefinition.ExportCil( assemblyName: enumName, enumNamespace, headerMode, @@ -164,7 +167,7 @@ public static void GenerateEnumToFile( indentSize, newlineMode, storageType, - curlyBracketMode); + curlyBracketMode)); } catch (Exception e) { @@ -172,6 +175,22 @@ public static void GenerateEnumToFile( 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; } @@ -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) { @@ -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}'."); } @@ -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}'."); } diff --git a/src/OutputType.cs b/src/OutputType.cs index be6fc22..ff0968e 100644 --- a/src/OutputType.cs +++ b/src/OutputType.cs @@ -6,13 +6,18 @@ public enum OutputType { /// - /// Produce a CSharp source file. + /// Produce a CSharp (.cs) source file. /// CSharp = 0, /// - /// Produce a Cil source file. + /// Produce a Cil (.il) source file. /// - Cil = 1 + Cil = 1, + + /// + /// Produce a class-library (.dll) file. + /// + ClassLibrary = 2 } }