feat: add Cake build to produce powershell module (#2)
- Add Cake build project - Change to CPM - Package bumps for security bumps - Reorganise solution structure to group harness projects
This commit is contained in:
parent
274d279732
commit
ecb0a20cbb
27 changed files with 267 additions and 58 deletions
49
build/Tasks/CopyOutputTask.cs
Normal file
49
build/Tasks/CopyOutputTask.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
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";
|
||||
var scriptParams = new
|
||||
{
|
||||
Path = $"{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"
|
||||
};
|
||||
|
||||
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("path", ToPowershellSafeString(scriptParams.Path));
|
||||
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));
|
||||
|
||||
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}'";
|
||||
}
|
||||
Loading…
Reference in a new issue