From 5cfc4819febf2a4569942e3557290d75a09ff8a2 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 3 Sep 2026 22:08:48 +1000 Subject: [PATCH] build(git-provider): Generate initial import script --- build/Tasks/CopyOutputTask.cs | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/build/Tasks/CopyOutputTask.cs b/build/Tasks/CopyOutputTask.cs index 9a5bdde..2d531b0 100644 --- a/build/Tasks/CopyOutputTask.cs +++ b/build/Tasks/CopyOutputTask.cs @@ -122,5 +122,51 @@ public class CopyOutputTask : FrostingTask } 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 + } + + private static void GenerateModuleImportScript(string bundleLocation, BuildContext context) + { + context.Log.Information($"Generating module import script"); + + using var scriptFile = File.Create(Path.Combine(bundleLocation, "NulahPowershell.ps1")); + using var fileWriter = new StreamWriter(scriptFile); + // TODO: Document the set up function + // TODO: Create a ticket for fleshing out the set up function (or just do that work later) + 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 + # The intent for this is that a user will have copied this bundle folder alongside their $profile + # location, eg, they'll have a folder called NulahModule that will contain everything within the bundle zip + $testBundleDirectory = $PSScriptRoot + $bundleInPath = ($Env:PSModulePath -split ';').TrimEnd('\') -contains $testBundleDirectory; + + if ($false -eq $bundleInPath) + { + $env:PSModulePath = @( + $env:PSModulePath + $testBundleDirectory + ) -Join [System.IO.Path]::PathSeparator + } + + Import-Module "PowershellModule" + } + """ + ); + context.Log.Information($"Module import script created"); } } \ No newline at end of file