69 lines
No EOL
3 KiB
C#
69 lines
No EOL
3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cake.Core.Diagnostics;
|
|
using Cake.Core.IO;
|
|
using Cake.Frosting;
|
|
using Cake.Powershell;
|
|
|
|
namespace Build.Tasks;
|
|
|
|
[TaskName("CopyOutput")]
|
|
public class CopyOutputTask : FrostingTask<BuildContext>
|
|
{
|
|
public override void Run(BuildContext context)
|
|
{
|
|
var powershellModuleName = "PowershellModule";
|
|
// TODO: probably don't create full file locations when I can pass the output dir in and have the script
|
|
// make the path
|
|
var scriptParams = new
|
|
{
|
|
PowershellModuleFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1",
|
|
Guid = Guid.Parse("5cdf4635-edb0-428c-8d9b-92d0bcd47443"),
|
|
Author = "Me",
|
|
NestedModules = new[] { $"{powershellModuleName}.dll" },
|
|
RootModule = $"{powershellModuleName}.psm1",
|
|
CmdletsToExport = GetExportedCmdlets(),
|
|
ManifestFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psm1",
|
|
OutputLocation = context.PowershellModuleOutputDir,
|
|
};
|
|
|
|
var psSettings = new PowershellSettings()
|
|
{
|
|
Arguments = new ProcessArgumentBuilder(),
|
|
};
|
|
|
|
// This feels a bit ugly/redundant seeing as I've defined the scriptParams above, but I'm leaving it as is
|
|
// until I want to come back and clean this up properly
|
|
psSettings.Arguments.Append("powershellModuleFileLocation", ToPowershellSafeString(scriptParams.PowershellModuleFileLocation));
|
|
psSettings.Arguments.Append("guid", ToPowershellSafeString(scriptParams.Guid.ToString()));
|
|
psSettings.Arguments.Append("author", ToPowershellSafeString(scriptParams.Author));
|
|
psSettings.Arguments.Append("nestedModules", $"@({string.Join(",", scriptParams.NestedModules.Select(ToPowershellSafeString))})");
|
|
psSettings.Arguments.Append("rootModule", ToPowershellSafeString(scriptParams.RootModule));
|
|
psSettings.Arguments.Append("cmdletsToExport", $"@({string.Join(",", scriptParams.CmdletsToExport.Select(ToPowershellSafeString))})");
|
|
psSettings.Arguments.Append("manifestFileLocation", ToPowershellSafeString(scriptParams.ManifestFileLocation));
|
|
psSettings.Arguments.Append("outputDir", ToPowershellSafeString(scriptParams.OutputLocation));
|
|
|
|
context.StartPowershellFile(context.CreateModuleManifestScript, psSettings);
|
|
context.Log.Information($"Module output to: {context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment)}");
|
|
|
|
base.Run(context);
|
|
}
|
|
|
|
private static string ToPowershellSafeString(string unescapedString) => $"'{unescapedString}'";
|
|
|
|
private static List<string> GetExportedCmdlets()
|
|
{
|
|
return ["Get-Calendar", .. GetGitRepoRegistrationVerbs()];
|
|
}
|
|
|
|
private static List<string> GetGitRepoRegistrationVerbs()
|
|
{
|
|
// TODO: I should make some reference file for these verbs and name but that'd pull in powershell dependencies
|
|
// to the build and I'd like to avoid that.
|
|
// This isn't great but commands are unlikely to change that frequently
|
|
string[] verbs = ["Get", "New", "Remove", "Show"];
|
|
var commandName = "GitRepoRegistration";
|
|
return [.. verbs.Select(x => $"{x}-{commandName}")];
|
|
}
|
|
} |