Compare commits

..

7 Commits

Author SHA1 Message Date
4bc5375bc7 Added test result publishing.
Some checks failed
RealYHD/dotnetresxutils/pipeline/head There was a failure building this commit
2022-12-04 09:03:21 +00:00
2fdf476a85 Updated Jenkinsfile and .NET version. 2022-12-04 08:51:27 +00:00
f460382a64 Refactored Generation command name. 2022-05-18 22:03:45 -05:00
1cb6730bb1 Switched Generation command to use lambda handler. 2022-05-18 22:03:08 -05:00
be2cf466b4 Moved .vscode to root directory. 2022-05-18 22:02:37 -05:00
bd51a23da3 Program now compiles. Still untested. 2022-05-16 02:25:54 -05:00
68cd4fdcf2 Added an untested generation command. 2022-05-16 01:21:51 -05:00
9 changed files with 185 additions and 15 deletions

26
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/DotNetResxUtils/bin/Debug/net6.0/DotNetResxUtils.dll",
"args": [],
"cwd": "${workspaceFolder}/DotNetResxUtils",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"cSpell.words": [
"dotnetresxutils",
"Resx"
]
}

41
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/DotNetResxUtils/DotNetResxUtils.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/DotNetResxUtils/DotNetResxUtils.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/DotNetResxUtils/DotNetResxUtils.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
@ -18,6 +18,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="XunitXml.TestLogger" Version="3.0.70" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,81 @@
using System.Collections.Generic;
using System.IO;
using System.CommandLine;
using System.Text.Json;
using System.Threading.Tasks;
using System.Resources.NetStandard;
namespace DotNetResxUtils.Commands
{
internal class Generate : Command
{
const string NAME = "generate";
const string DESC = "Generate a .resx file.";
public Generate() : base(NAME, DESC)
{
Argument<FileInfo> destArg = new Argument<FileInfo>("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated.");
Add(destArg);
Option<FileInfo?> fromOpt = new Option<FileInfo?>("--from", "Generates a .resx file from the given file.");
Add(fromOpt);
this.SetHandler(async (FileInfo to, FileInfo? from) =>
{
IDictionary<string, string> flattened = new Dictionary<string, string>();
if (from != null)
{
flattened = await FlattenJson(from);
}
using (ResXResourceWriter resxWriter = new ResXResourceWriter(to.FullName))
{
foreach (KeyValuePair<string, string> keyVal in flattened)
{
resxWriter.AddResource(keyVal.Key, keyVal.Value);
}
}
}, destArg, fromOpt);
}
private async Task<IDictionary<string, string>> FlattenJson(FileInfo jsonFile)
{
JsonElement jsonObj;
using (FileStream readStream = jsonFile.OpenRead())
{
jsonObj = await JsonSerializer.DeserializeAsync<JsonElement>(readStream);
}
Dictionary<string, string> result = new Dictionary<string, string>();
FlattenJsonElement(result, jsonObj, "");
return result;
}
private void FlattenJsonElement(IDictionary<string, string> flattened, JsonElement jsonElement, string namePath)
{
if (jsonElement.ValueKind == JsonValueKind.Array)
{
int itemIndex = 0;
foreach (JsonElement item in jsonElement.EnumerateArray())
{
FlattenJsonElement(flattened, item, namePath + $"[{itemIndex}]");
}
}
else if (jsonElement.ValueKind == JsonValueKind.Object)
{
foreach (JsonProperty item in jsonElement.EnumerateObject())
{
FlattenJsonElement(flattened, item.Value, namePath + $".{item.Name}");
}
}
else
{
string? stored = jsonElement.GetString();
if (stored != null)
{
flattened[namePath] = stored;
}
}
}
}
}

View File

@ -1,14 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<!-- not for choosing a file extension, just designating as executable item -->
<OutputType>exe</OutputType> <OutputType>exe</OutputType>
<PublishSingleFile>true</PublishSingleFile> <PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained> <SelfContained>true</SelfContained>
<PublishReadyToRun>true</PublishReadyToRun> <PublishReadyToRun>true</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<TargetFramework>net6.0</TargetFramework> <PublishTrimmed>true</PublishTrimmed>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="ResXResourceReader.NetStandard" Version="1.1.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
</ItemGroup>
</Project> </Project>

View File

@ -1,4 +1,7 @@
using System; using System.IO;
using System;
using System.CommandLine;
using DotNetResxUtils.Commands;
namespace DotNetResxUtils namespace DotNetResxUtils
{ {
@ -6,8 +9,10 @@ namespace DotNetResxUtils
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Hello, World!"); RootCommand rootCmd = new RootCommand(".Net Resx Utils provides tools for generating, and editing .resx files.");
rootCmd.AddCommand(new Generate());
// See: Collection organizers - https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers
} }
} }
} }

20
Jenkinsfile vendored
View File

@ -1,26 +1,24 @@
pipeline { pipeline {
agent any agent any
stages { stages {
stage("Cleanup") { stage("Setup") {
steps { steps {
cleanWs(patterns: [[pattern: '**/bin/Release', type: 'INCLUDE'], [pattern: 'output/**', type: 'INCLUDE']]) sh 'mamba env update --file environment.yml'
} sh 'echo "mamba activate dotnetresxutils" >> ~/.bashrc'
} sh "dotnet restore DotNetResxUtils"
stage("Restore") { sh "dotnet restore DotNetResxUtils.Tests"
steps {
dotnetRestore project: 'DotNetResxUtils'
dotnetRestore project: 'DotNetResxUtils.Tests'
} }
} }
stage("Test") { stage("Test") {
steps { steps {
dotnetTest noRestore: true, project: 'DotNetResxUtils.Tests' sh "dotnet test --logger xunit --no-restore DotNetResxUtils.Tests"
xunit([xUnitDotNet(excludesPattern: '', pattern: '*.Tests/TestResults/*.xml', stopProcessingIfError: true)])
} }
} }
stage("Publish") { stage("Publish") {
steps { steps {
dotnetPublish configuration: 'Release', outputDirectory: 'output/DotNetResxUtils/DotNetResxUtils-win-x64', project: 'DotNetResxUtils', runtime: 'win-x64', selfContained: true sh "dotnet publish DotNetResxUtils --configuration Release --output output/DotNetResxUtils/DotNetResxUtils-win-x64 --runtime win-x64 --self-contained"
dotnetPublish configuration: 'Release', outputDirectory: 'output/DotNetResxUtils/DotNetResxUtils-linux-x64', project: 'DotNetResxUtils', runtime: 'linux-x64', selfContained: true sh "dotnet publish DotNetResxUtils --configuration Release --output output/DotNetResxUtils/DotNetResxUtils-linux-x64 --runtime linux-x64 --self-contained"
fingerprint 'output/DotNetResxUtils/**/DotNetResxUtils*' fingerprint 'output/DotNetResxUtils/**/DotNetResxUtils*'
tar file: "output/DotNetResxUtils-linux-x64.tar.gz", archive: true, compress: true, dir: "output/DotNetResxUtils/DotNetResxUtils-linux-x64" tar file: "output/DotNetResxUtils-linux-x64.tar.gz", archive: true, compress: true, dir: "output/DotNetResxUtils/DotNetResxUtils-linux-x64"
zip zipFile: "output/DotNetResxUtils-win-x64.zip", archive: true, dir: "output/DotNetResxUtils/DotNetResxUtils-win-x64" zip zipFile: "output/DotNetResxUtils-win-x64.zip", archive: true, dir: "output/DotNetResxUtils/DotNetResxUtils-win-x64"

5
environment.yml Normal file
View File

@ -0,0 +1,5 @@
name: dotnetresxutils
channels:
- conda-forge
dependencies:
- dotnet-sdk=7.0.*