feat: Add GitRepoRegistration cmdlets #5

Merged
pascal_nulah merged 69 commits from feature/git-provider into dev 2026-09-06 09:33:36 +10:00
Showing only changes of commit a399b29df3 - Show all commits

build(git-provider): Create bundle zip for module

Scott 2026-09-04 09:29:15 +10:00

View file

@ -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<BuildContext>
// 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<BuildContext>
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<BuildContext>
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<BuildContext>
);
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);
}
}