feat: Add GitRepoRegistration cmdlets #5
1 changed files with 57 additions and 0 deletions
build(git-provider): Bundle up minimal required module files
commit
9665ed1ae3
|
|
@ -1,10 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Cake.Core.Diagnostics;
|
||||
using Cake.Core.IO;
|
||||
using Cake.Frosting;
|
||||
using Cake.Powershell;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace Build.Tasks;
|
||||
|
||||
|
|
@ -47,6 +49,8 @@ public class CopyOutputTask : FrostingTask<BuildContext>
|
|||
context.StartPowershellFile(context.CreateModuleManifestScript, psSettings);
|
||||
context.Log.Information($"Module output to: {context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment)}");
|
||||
|
||||
BundleMinimalFiles(context);
|
||||
|
||||
base.Run(context);
|
||||
}
|
||||
|
||||
|
|
@ -66,4 +70,57 @@ public class CopyOutputTask : FrostingTask<BuildContext>
|
|||
var commandName = "GitRepoRegistration";
|
||||
return [.. verbs.Select(x => $"{x}-{commandName}")];
|
||||
}
|
||||
|
||||
private static void BundleMinimalFiles(BuildContext context)
|
||||
{
|
||||
// We're effectively replicating PostBuild.ps1 with all of this as Remove-Item at the end of it does not remove files the same way.
|
||||
// TODO: See if that's something I can fix
|
||||
var powershellModuleBuildLocation = context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment).FullPath;
|
||||
// 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}");
|
||||
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
|
||||
// correct e_sqlite3.dll that we need.
|
||||
// TODO: Investigate this later as I'm not entirely happy with this now
|
||||
// // Get the location for the specific version of e_sqlite3.dll we need - PowerShell binary modules resolve dependent dlls
|
||||
// // from the executing assembly directory first, and the built output of the module includes a lot of other dlls that
|
||||
// // are already available with the dotnet runtime so there's no need for us to include them.
|
||||
// // I mean, we could, but we'd also be terrible software engineers if we couldn't do something as basic as reducing files we need.
|
||||
// // TODO: Account for other runtimes such as linux based ones where the dotnet runtime might _not_ provide these files for free.
|
||||
// // It'd require looking into how the module loads for PowerShell on those operating systems, and I might never
|
||||
// // get around to doing that because I use windows (currently).
|
||||
// // TODO: Update this later to handle other runtimes, for now we hardcode to win-x64 because it's what I use
|
||||
// var nativeSqliteDllLocation = System.IO.Path.Combine(powershellModuleBuildLocation, "runtimes", "win-x64", "native", "e_sqlite3.dll");
|
||||
//
|
||||
// if (!File.Exists(nativeSqliteDllLocation))
|
||||
// {
|
||||
// context.Log.Error($"BUNDLE FAILED: Unable to locate ${nativeSqliteDllLocation}");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// context.Log.Information($"Copying '${nativeSqliteDllLocation}' to '${bundleOutputLocation}'");
|
||||
//
|
||||
// File.Copy(nativeSqliteDllLocation, System.IO.Path.Combine(bundleOutputLocation, System.IO.Path.GetFileName(nativeSqliteDllLocation)));
|
||||
|
||||
var moduleCoreFiles = Directory.GetFiles(powershellModuleBuildLocation, "ModuleCore*", searchOption: SearchOption.TopDirectoryOnly);
|
||||
var powershellModuleFiles = Directory.GetFiles(powershellModuleBuildLocation, "PowershellModule*", searchOption: SearchOption.TopDirectoryOnly);
|
||||
var sqliteFiles = Directory.GetFiles(powershellModuleBuildLocation, "*SQLite*", searchOption: SearchOption.TopDirectoryOnly);
|
||||
|
||||
string[] allFiles = [.. moduleCoreFiles, .. powershellModuleFiles, .. sqliteFiles];
|
||||
|
||||
context.Log.Information($"Copying {allFiles.Length} files to the module folder {moduleOutputLocation}");
|
||||
foreach (var file in allFiles)
|
||||
{
|
||||
context.Log.Information($"Copying {Path.GetFileName(file)}");
|
||||
File.Copy(file, Path.Combine(moduleOutputLocation, Path.GetFileName(file)));
|
||||
}
|
||||
|
||||
context.Log.Information($"Bundle files copied");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue