build(git-provider): Add GitRepoRegistration commands to build
This commit is contained in:
parent
5448fa3f9e
commit
270d545e56
2 changed files with 31 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cake.Core.Diagnostics;
|
||||
using Cake.Core.IO;
|
||||
|
|
@ -13,17 +14,20 @@ 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
|
||||
{
|
||||
Path = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1",
|
||||
PowershellModuleFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1",
|
||||
Guid = Guid.Parse("5cdf4635-edb0-428c-8d9b-92d0bcd47443"),
|
||||
Author = "Me",
|
||||
NestedModules = new[] { $"{powershellModuleName}.dll" },
|
||||
RootModule = $"{powershellModuleName}.psm1",
|
||||
CmdletsToExport = new[] { "Get-Calendar" },
|
||||
ManifestFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psm1"
|
||||
CmdletsToExport = GetExportedCmdlets(),
|
||||
ManifestFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psm1",
|
||||
OutputLocation = context.PowershellModuleOutputDir,
|
||||
};
|
||||
|
||||
|
||||
var psSettings = new PowershellSettings()
|
||||
{
|
||||
Arguments = new ProcessArgumentBuilder(),
|
||||
|
|
@ -31,13 +35,14 @@ public class CopyOutputTask : FrostingTask<BuildContext>
|
|||
|
||||
// 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("path", ToPowershellSafeString(scriptParams.Path));
|
||||
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)}");
|
||||
|
|
@ -46,4 +51,19 @@ public class CopyOutputTask : FrostingTask<BuildContext>
|
|||
}
|
||||
|
||||
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}")];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue