build(git-provider): Create bundle zip for module
This commit is contained in:
parent
5cfc4819fe
commit
a399b29df3
1 changed files with 21 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Cake.Core.Diagnostics;
|
using Cake.Core.Diagnostics;
|
||||||
using Cake.Core.IO;
|
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
|
// PowershellModule is here so that the script that adds to the users $Env:PSModulePath correctly resolves when using
|
||||||
// Import-Module "PowershellModule"
|
// Import-Module "PowershellModule"
|
||||||
// TODO: Generate the script to add to the PSModulePath in the bundleOutputLocation directory
|
// 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}");
|
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
|
// 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];
|
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)
|
foreach (var file in allFiles)
|
||||||
{
|
{
|
||||||
context.Log.Information($"Copying {Path.GetFileName(file)}");
|
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");
|
context.Log.Information($"Bundle files copied");
|
||||||
|
|
||||||
GenerateModuleImportScript(bundleOutputLocation, context);
|
GenerateModuleImportScript(moduleFolderLocation, context);
|
||||||
// TODO: zip the bundle directory contents to NulahModule.zip, and have a top level folder inside that called NulahModule.
|
CreateBundleZip(bundleRootLocation, moduleFolderLocation, context);
|
||||||
// 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)
|
private static void GenerateModuleImportScript(string bundleLocation, BuildContext context)
|
||||||
|
|
@ -169,4 +173,10 @@ public class CopyOutputTask : FrostingTask<BuildContext>
|
||||||
);
|
);
|
||||||
context.Log.Information($"Module import script created");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue