Skip to content

Commit

Permalink
Build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Dec 12, 2018
1 parent e91bdfb commit 00453da
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
*.user
*.vs
*.log
*.zip

.vscode

# Build results
build/
bin/
out/
obj/
publish/

Expand Down
151 changes: 89 additions & 62 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Squidex.CLI.Commands
{
public partial class App
{
[ApplicationMetadata(Name = "content", Description = "Manage Contents.")]
[ApplicationMetadata(Name = "content", Description = "Manage content.")]
[SubCommand]
public class Content
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task Export(ExportArguments arguments)
{
if (string.IsNullOrWhiteSpace(fileOrFolder))
{
fileOrFolder = $"{arguments.Schema}";
fileOrFolder = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}";
}

if (!Directory.Exists(fileOrFolder))
Expand All @@ -76,7 +76,7 @@ public async Task Export(ExportArguments arguments)
{
if (string.IsNullOrWhiteSpace(fileOrFolder))
{
fileOrFolder = $"{arguments.Schema}.json";
fileOrFolder = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}.json";
}

if (File.Exists(fileOrFolder))
Expand All @@ -91,27 +91,37 @@ public async Task Export(ExportArguments arguments)

var consoleTop = Console.CursorTop;

var handled = new HashSet<string>();

do
{
var content = await client.GetAsync();
var content = await client.GetAsync(skip: currentPage * 100, top: 100);

total = content.Total;

foreach (var entity in content.Items)
if (content.Items.Count == 0)
{
totalRead++;
break;
}

if (arguments.FilePerContent)
{
File.WriteAllText(Path.Combine(fileOrFolder, $"{arguments.Schema}_{entity.Id}.json"), entity.JsonPrettyString());
}
else
foreach (var entity in content.Items)
{
if (handled.Add(entity.Id))
{
File.AppendAllText(fileOrFolder, entity.JsonPrettyString());
}
totalRead++;

Console.WriteLine("> Exported: {0} of {1}.", totalRead, total);
Console.SetCursorPosition(0, consoleTop);
if (arguments.FilePerContent)
{
File.WriteAllText(Path.Combine(fileOrFolder, $"{arguments.Schema}_{entity.Id}.json"), entity.JsonPrettyString());
}
else
{
File.AppendAllText(fileOrFolder, entity.JsonPrettyString());
}

Console.WriteLine("> Exported: {0} of {1}.", totalRead, total);
Console.SetCursorPosition(0, consoleTop);
}
}

currentPage++;
Expand All @@ -136,40 +146,10 @@ public async Task Export(ExportArguments arguments)

if (string.IsNullOrWhiteSpace(file))
{
file = $"{arguments.Schema}.csv";
file = $"{arguments.Schema}_{DateTime.UtcNow:yyyy-MM-dd-hh-mm-ss}.csv";
}

var fields = new List<(string Name, string[] Path)>();

foreach (var item in arguments.Fields.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
{
var parts = item.Split('=');

string[] GetPath(string value)
{
var path = value.Split('.', StringSplitOptions.RemoveEmptyEntries);

if (path.Length == 2 && string.Equals(path[0], "Data", StringComparison.OrdinalIgnoreCase))
{
return path.Union(Enumerable.Repeat("iv", 1)).ToArray();
}

return path;
}

if (parts.Length == 1)
{
fields.Add((parts[0], GetPath(parts[0])));
}
else if (parts.Length == 2)
{
fields.Add((parts[0], GetPath(parts[1])));
}
else
{
throw new SquidexException("Field definition not valid.");
}
}
var fields = GetFields(arguments);

using (var stream = new FileStream(file, FileMode.Create, FileAccess.Write))
{
Expand All @@ -195,34 +175,44 @@ string[] GetPath(string value)

var consoleTop = Console.CursorTop;

var handled = new HashSet<string>();

do
{
var content = await client.GetAsync();
var content = await client.GetAsync(skip: currentPage * 100, top: 100);

total = content.Total;

foreach (var entity in content.Items)
if (content.Items.Count == 0)
{
totalRead++;
break;
}

foreach (var field in fields)
foreach (var entity in content.Items)
{
if (handled.Add(entity.Id))
{
var value = GetValue(entity, field.Path);
totalRead++;

if (value is string s)
{
writer.WriteField(s.Replace("\n", "\\n"), true);
}
else
foreach (var field in fields)
{
writer.WriteField(value);
var value = GetValue(entity, field.Path);

if (value is string s)
{
writer.WriteField(s.Replace("\n", "\\n"), true);
}
else
{
writer.WriteField(value);
}
}
}

writer.NextRecord();
writer.NextRecord();

Console.WriteLine("> Exported: {0} of {1}.", totalRead, total);
Console.SetCursorPosition(0, consoleTop);
Console.WriteLine("> Exported: {0} of {1}.", totalRead, total);
Console.SetCursorPosition(0, consoleTop);
}
}

currentPage++;
Expand All @@ -241,6 +231,43 @@ string[] GetPath(string value)
}
}

private static List<(string Name, string[] Path)> GetFields(ExportArguments arguments)
{
var fields = new List<(string Name, string[] Path)>();

foreach (var item in arguments.Fields.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
{
var parts = item.Split('=');

string[] GetPath(string value)
{
var path = value.Split('.', StringSplitOptions.RemoveEmptyEntries);

if (path.Length == 2 && string.Equals(path[0], "Data", StringComparison.OrdinalIgnoreCase))
{
return path.Union(Enumerable.Repeat("iv", 1)).ToArray();
}

return path;
}

if (parts.Length == 1)
{
fields.Add((parts[0], GetPath(parts[0])));
}
else if (parts.Length == 2)
{
fields.Add((parts[0], GetPath(parts[1])));
}
else
{
throw new SquidexException("Field definition not valid.");
}
}

return fields;
}

private object GetValue(object current, string[] path)
{
foreach (var element in path)
Expand Down
12 changes: 12 additions & 0 deletions cli/Squidex.CLI/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$runtimes = @("win-x64", "win-x86", "linux-x64", "ubuntu-x64", "osx-x64")

foreach ($runtime in $runtimes) {
Write-Host "> Compiling for $runtime"

dotnet publish -c Release -r $runtime

xcopy "Squidex.CLI\bin\Release\netcoreapp2.2\$runtime\publish" "out\$runtime\" /S /Y /Q

Write-Host "> Compiling for $runtime completed"
Write-Host ""
}

0 comments on commit 00453da

Please sign in to comment.