From a399b29df3abe591b2b12a2964600e7c6bee922b Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 4 Sep 2026 09:29:15 +1000 Subject: [PATCH] build(git-provider): Create bundle zip for module --- build/Tasks/CopyOutputTask.cs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/build/Tasks/CopyOutputTask.cs b/build/Tasks/CopyOutputTask.cs index 2d531b0..8bccce5 100644 --- a/build/Tasks/CopyOutputTask.cs +++ b/build/Tasks/CopyOutputTask.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Linq; using Cake.Core.Diagnostics; using Cake.Core.IO; @@ -79,10 +80,15 @@ public class CopyOutputTask : FrostingTask // PowershellModule is here so that the script that adds to the users $Env:PSModulePath correctly resolves when using // Import-Module "PowershellModule" // TODO: Generate the script to add to the PSModulePath in the bundleOutputLocation directory - var bundleOutputLocation = Directory.CreateDirectory(Path.Combine(powershellModuleBuildLocation, "bundle")).FullName; - var moduleOutputLocation = Directory.CreateDirectory(Path.Combine(bundleOutputLocation, "PowershellModule")).FullName; - context.Log.Information($"Bundle location: {bundleOutputLocation}"); + // Top level bundle output location + var bundleRootLocation = Directory.CreateDirectory(Path.Combine(powershellModuleBuildLocation, "bundle")).FullName; + // Module folder location that will be zipped up and will contain any setup scripts/readme etc + var moduleFolderLocation = Directory.CreateDirectory(Path.Combine(bundleRootLocation, "NulahModule")).FullName; + // Location to put all the module dlls and other files + var powershelModuleOutputLocation = Directory.CreateDirectory(Path.Combine(moduleFolderLocation, "PowershellModule")).FullName; + + context.Log.Information($"Bundle location: {bundleRootLocation}"); context.Log.Information($"Built file location: {powershellModuleBuildLocation}"); // PostBuild.ps1 for PowershellModule should have already been run at this point - it won't remove files, but it will copy the @@ -114,19 +120,17 @@ public class CopyOutputTask : FrostingTask string[] allFiles = [.. moduleCoreFiles, .. powershellModuleFiles, .. sqliteFiles]; - context.Log.Information($"Copying {allFiles.Length} files to the module folder {moduleOutputLocation}"); + context.Log.Information($"Copying {allFiles.Length} files to the module folder {powershelModuleOutputLocation}"); foreach (var file in allFiles) { context.Log.Information($"Copying {Path.GetFileName(file)}"); - File.Copy(file, Path.Combine(moduleOutputLocation, Path.GetFileName(file))); + File.Copy(file, Path.Combine(powershelModuleOutputLocation, Path.GetFileName(file))); } context.Log.Information($"Bundle files copied"); - GenerateModuleImportScript(bundleOutputLocation, context); - // TODO: zip the bundle directory contents to NulahModule.zip, and have a top level folder inside that called NulahModule. - // The intent is that users will drop this zip next to their $profile, and then extract the contents directly so everything - // is contained as it should be + GenerateModuleImportScript(moduleFolderLocation, context); + CreateBundleZip(bundleRootLocation, moduleFolderLocation, context); } private static void GenerateModuleImportScript(string bundleLocation, BuildContext context) @@ -140,13 +144,13 @@ public class CopyOutputTask : FrostingTask fileWriter.Write( """ # To use, first copy all files to the same location as your $profile under ./NulahModule, then open your powershell profile located at $profile and add the following: - + # Script setup style: Using the setup script to import as needed (this method will also set custom prompts and other alias functions) # . "$PSScriptRoot/NulahModule/NulahPowershell.ps1" # SetupNulahPowershell # Just the module: Use the following to just import just the powershell module # Import-Module -Name "$PSScriptRoot/NulahModule/PowershellModule" - + function SetupNulahPowershell { # only add to our module path once @@ -169,4 +173,10 @@ public class CopyOutputTask : FrostingTask ); context.Log.Information($"Module import script created"); } + + private static void CreateBundleZip(string bundleLocation, string moduleFolderLocation, BuildContext context) + { + var bundleZipFileLocaiton = Path.Combine(bundleLocation, "NulahModule.zip"); + ZipFile.CreateFromDirectory(moduleFolderLocation, bundleZipFileLocaiton, CompressionLevel.Fastest, true); + } } \ No newline at end of file