Compare commits
No commits in common. "develop" and "master" have entirely different histories.
26
.vscode/launch.json
vendored
26
.vscode/launch.json
vendored
@ -1,26 +0,0 @@
|
||||
{
|
||||
"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
6
.vscode/settings.json
vendored
@ -1,6 +0,0 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"dotnetresxutils",
|
||||
"Resx"
|
||||
]
|
||||
}
|
41
.vscode/tasks.json
vendored
41
.vscode/tasks.json
vendored
@ -1,41 +0,0 @@
|
||||
{
|
||||
"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">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
@ -18,7 +18,6 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="XunitXml.TestLogger" Version="3.0.70" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,81 +0,0 @@
|
||||
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,21 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- not for choosing a file extension, just designating as executable item -->
|
||||
<OutputType>exe</OutputType>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<SelfContained>true</SelfContained>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ResXResourceReader.NetStandard" Version="1.1.0" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,7 +1,4 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using DotNetResxUtils.Commands;
|
||||
using System;
|
||||
|
||||
namespace DotNetResxUtils
|
||||
{
|
||||
@ -9,10 +6,8 @@ namespace DotNetResxUtils
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
RootCommand rootCmd = new RootCommand(".Net Resx Utils provides tools for generating, and editing .resx files.");
|
||||
rootCmd.AddCommand(new Generate());
|
||||
Console.WriteLine("Hello, World!");
|
||||
|
||||
// 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,24 +1,26 @@
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage("Setup") {
|
||||
stage("Cleanup") {
|
||||
steps {
|
||||
sh 'mamba env update --file environment.yml'
|
||||
sh 'echo "mamba activate dotnetresxutils" >> ~/.bashrc'
|
||||
sh "dotnet restore DotNetResxUtils"
|
||||
sh "dotnet restore DotNetResxUtils.Tests"
|
||||
cleanWs(patterns: [[pattern: '**/bin/Release', type: 'INCLUDE'], [pattern: 'output/**', type: 'INCLUDE']])
|
||||
}
|
||||
}
|
||||
stage("Restore") {
|
||||
steps {
|
||||
dotnetRestore project: 'DotNetResxUtils'
|
||||
dotnetRestore project: 'DotNetResxUtils.Tests'
|
||||
}
|
||||
}
|
||||
stage("Test") {
|
||||
steps {
|
||||
sh "dotnet test --logger xunit --no-restore DotNetResxUtils.Tests"
|
||||
xunit([xUnitDotNet(excludesPattern: '', pattern: '*.Tests/TestResults/*.xml', stopProcessingIfError: true)])
|
||||
dotnetTest noRestore: true, project: 'DotNetResxUtils.Tests'
|
||||
}
|
||||
}
|
||||
stage("Publish") {
|
||||
steps {
|
||||
sh "dotnet publish DotNetResxUtils --configuration Release --output output/DotNetResxUtils/DotNetResxUtils-win-x64 --runtime win-x64 --self-contained"
|
||||
sh "dotnet publish DotNetResxUtils --configuration Release --output output/DotNetResxUtils/DotNetResxUtils-linux-x64 --runtime linux-x64 --self-contained"
|
||||
dotnetPublish configuration: 'Release', outputDirectory: 'output/DotNetResxUtils/DotNetResxUtils-win-x64', project: 'DotNetResxUtils', runtime: 'win-x64', selfContained: true
|
||||
dotnetPublish configuration: 'Release', outputDirectory: 'output/DotNetResxUtils/DotNetResxUtils-linux-x64', project: 'DotNetResxUtils', runtime: 'linux-x64', selfContained: true
|
||||
fingerprint 'output/DotNetResxUtils/**/DotNetResxUtils*'
|
||||
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"
|
||||
|
@ -1,5 +0,0 @@
|
||||
name: dotnetresxutils
|
||||
channels:
|
||||
- conda-forge
|
||||
dependencies:
|
||||
- dotnet-sdk=7.0.*
|
Loading…
Reference in New Issue
Block a user