Skip to content

Commit

Permalink
Fix compilation errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Feb 24, 2024
1 parent 862ed1b commit c46e09a
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions Lombiq.Hosting.MediaTheme.Deployer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Globalization;
using System.IO.Compression;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using static Lombiq.Hosting.MediaTheme.Deployer.Constants.PathConstants;
using static System.Console;
Expand Down Expand Up @@ -68,6 +68,8 @@ public class CommandLineOptions

internal static partial class Program
{
private static readonly JsonSerializerOptions _indentedJsonSerializerOptions = new() { WriteIndented = true };

internal static readonly string[] FeaturesToEnable = ["Lombiq.Hosting.MediaTheme.Bridge", "Lombiq.Hosting.MediaTheme"];

public static Task Main(string[] args) =>
Expand Down Expand Up @@ -104,6 +106,19 @@ private static async Task RunOptionsAsync(CommandLineOptions options)
}
}

private static void AddFile(JsonArray files, string rootPath, string filePath)
{
// These need to use forward slashes on every platform due to Orchard's import logic.
var importPath = Path.Combine(rootPath, filePath).Replace('\\', '/');
var template = new
{
SourcePath = importPath,
TargetPath = importPath,
};

files.Add(template);
}

private static async Task RunOptionsInnerAsync(CommandLineOptions options)
{
// Creating directory for the deployment.
Expand All @@ -130,22 +145,22 @@ private static async Task RunOptionsInnerAsync(CommandLineOptions options)
throw new ArgumentException("The theme's path must be provided.");
}

var recipeSteps = new JArray();
var recipeSteps = new JsonArray();

// Creating Feature step to enable the Media Theme theme and Bridge module.
var featureStep = JObject.FromObject(new
var featureStep = new
{
name = "Feature",
enable = FeaturesToEnable,
});
};
recipeSteps.Add(featureStep);

// Creating Themes step to set Media Theme as the site theme.
var themesStep = JObject.FromObject(new
var themesStep = new
{
name = "Themes",
Site = "Lombiq.Hosting.MediaTheme",
});
};
recipeSteps.Add(themesStep);

var baseThemeId = string.IsNullOrEmpty(options.BaseThemeId) ? null : options.BaseThemeId;
Expand All @@ -163,29 +178,16 @@ private static async Task RunOptionsInnerAsync(CommandLineOptions options)
}

// Creating Media Theme step.
var mediaThemeStep = JObject.FromObject(new
var mediaThemeStep = new
{
name = "mediatheme",
ClearMediaThemeFolder = options.ClearMediaHostingFolder,
BaseThemeId = baseThemeId,
});
};
recipeSteps.Add(mediaThemeStep);

// Creating media step.
var files = new JArray();

void AddFile(string rootPath, string filePath)
{
// These need to use forward slashes on every platform due to Orchard's import logic.
var importPath = Path.Combine(rootPath, filePath).Replace('\\', '/');
var templateJObject = JObject.FromObject(new
{
SourcePath = importPath,
TargetPath = importPath,
});

files.Add(templateJObject);
}
var files = new JsonArray();

// Getting assets.
var assetsPath = Path.Combine(themePath, LocalThemeWwwRootDirectory);
Expand All @@ -195,7 +197,7 @@ void AddFile(string rootPath, string filePath)

foreach (var assetPath in allAssetsPaths)
{
AddFile(MediaThemeAssetsCopyDirectoryPath, assetPath[(assetsPath.Length + 1)..]);
AddFile(files, MediaThemeAssetsCopyDirectoryPath, assetPath[(assetsPath.Length + 1)..]);
}

// Copying assets to deployment directory.
Expand All @@ -214,7 +216,7 @@ void AddFile(string rootPath, string filePath)

foreach (var templatePath in allTemplatesPaths)
{
AddFile(MediaThemeTemplatesCopyDirectoryPath, templatePath[(templatesPath.Length + 1)..]);
AddFile(files, MediaThemeTemplatesCopyDirectoryPath, templatePath[(templatesPath.Length + 1)..]);
}

// Copying templates to deployment directory.
Expand All @@ -225,14 +227,14 @@ void AddFile(string rootPath, string filePath)
recursive: false);
}

var mediaStep = JObject.FromObject(new
var mediaStep = new
{
name = "media",
Files = files,
});
};
recipeSteps.Add(mediaStep);

CreateRecipeAndWriteIt(options, recipeSteps, newDirectoryPath);
await CreateRecipeAndWriteItAsync(options, recipeSteps, newDirectoryPath);

// Zipping the directory.
var zipFilePath = newDirectoryPath + ".zip";
Expand Down Expand Up @@ -320,29 +322,27 @@ private static string CreateNewDirectoryPath(CommandLineOptions values)
+ DateTime.Now.ToString("ddMMMyyyyHHmmss", CultureInfo.CurrentCulture); // #spell-check-ignore-line
}

private static void CreateRecipeAndWriteIt(CommandLineOptions options, JArray steps, string newDirectoryPath)
private static Task CreateRecipeAndWriteItAsync(CommandLineOptions options, JsonArray steps, string newDirectoryPath)
{
// Creating the recipe itself.
var recipe = JObject.FromObject(new
var recipe = new
{
name = options.DeploymentFileName ?? "MediaTheme",
displayName = "Media Theme",
description = "A recipe created with the media-theme-deployment tool.",
author = string.Empty,
website = string.Empty,
version = string.Empty,
issetuprecipe = false, // #spell-check-ignore-line
categories = new JArray(),
tags = new JArray(),
issetuprecipe = false,// #spell-check-ignore-line
categories = Enumerable.Empty<object>(),
tags = Enumerable.Empty<object>(),
steps,
});
};

// Creating JSON file.
using var file = File.CreateText(Path.Join(newDirectoryPath, RecipeFile));
using var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented };
recipe.WriteTo(writer);

file.Close();
var recipePath = Path.Join(newDirectoryPath, RecipeFile);
var recipeBytes = JsonSerializer.SerializeToUtf8Bytes(recipe, recipe.GetType(), _indentedJsonSerializerOptions);
return File.WriteAllBytesAsync(recipePath, recipeBytes);
}

[GeneratedRegex(@"BaseTheme\s*=\s*""(?<baseThemeId>.*)""", RegexOptions.ExplicitCapture, matchTimeoutMilliseconds: 1000)]
Expand Down

0 comments on commit c46e09a

Please sign in to comment.