Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
4bc5375bc7 | |||
2fdf476a85 | |||
f460382a64 | |||
1cb6730bb1 | |||
be2cf466b4 | |||
bd51a23da3 | |||
68cd4fdcf2 |
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal 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
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"dotnetresxutils",
|
||||||
|
"Resx"
|
||||||
|
]
|
||||||
|
}
|
41
.vscode/tasks.json
vendored
Normal file
41
.vscode/tasks.json
vendored
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -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>
|
||||||
|
81
DotNetResxUtils/Commands/Generate.cs
Normal file
81
DotNetResxUtils/Commands/Generate.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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>
|
@ -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
20
Jenkinsfile
vendored
@ -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
5
environment.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: dotnetresxutils
|
||||||
|
channels:
|
||||||
|
- conda-forge
|
||||||
|
dependencies:
|
||||||
|
- dotnet-sdk=7.0.*
|
Loading…
Reference in New Issue
Block a user