From 6193d30029bc5d5ed947b45457c92ecbae817706 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 7 Aug 2026 11:05:14 +1000 Subject: [PATCH] feat(git-provider): add Sqlite to PowershellModule - add CopyLocalLockFileAssemblies to PowershellModule.csproj - add postbuild script to copy Sqlite files and remove unneeded files in debug output - add sqlite-net-pcl 1.11.285 --- Directory.Packages.props | 1 + src/PowershellModule/Git/GitProvider.cs | 32 --------------- src/PowershellModule/Git/NewGitRepoCommand.cs | 39 +++++++++++++++++++ src/PowershellModule/PostBuild.ps1 | 27 +++++++++++++ src/PowershellModule/PowershellModule.csproj | 6 +++ 5 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 src/PowershellModule/Git/NewGitRepoCommand.cs create mode 100644 src/PowershellModule/PostBuild.ps1 diff --git a/Directory.Packages.props b/Directory.Packages.props index 1e8aa77..6ef9afe 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,6 +4,7 @@ + diff --git a/src/PowershellModule/Git/GitProvider.cs b/src/PowershellModule/Git/GitProvider.cs index 46ce4cd..5b290be 100644 --- a/src/PowershellModule/Git/GitProvider.cs +++ b/src/PowershellModule/Git/GitProvider.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Management.Automation; using System.Management.Automation.Provider; @@ -66,35 +65,4 @@ public class GitProvider : NavigationCmdletProvider { throw new System.NotImplementedException(); } -} - -[Cmdlet(VerbsCommon.New, Noun)] -public class RegisterGitRepo : PSCmdlet -{ - private const string Noun = "GitRepo"; - - [Parameter( - Mandatory = true, - Position = 0, - ValueFromPipeline = true, - HelpMessage = "Reference name for the repo")] - public string Name { get; set; } - - protected override void BeginProcessing() - { - var pwd = this.SessionState.Path.CurrentLocation.Path; - WriteObject("Checking if current directory is a git repository..."); - var ps = new ProcessStartInfo( //$"git -C \"{pwd}\" rev-parse --show-toplevel") - "git", ["rev-parse", "--show-toplevel"]) - { - RedirectStandardOutput = true, - RedirectStandardError = true, - WorkingDirectory = pwd - }; - var a = Process.Start(ps); - Console.WriteLine(a.StandardOutput.ReadToEnd()); - Console.WriteLine(a.StandardError.ReadToEnd()); - - base.BeginProcessing(); - } } \ No newline at end of file diff --git a/src/PowershellModule/Git/NewGitRepoCommand.cs b/src/PowershellModule/Git/NewGitRepoCommand.cs new file mode 100644 index 0000000..89891f6 --- /dev/null +++ b/src/PowershellModule/Git/NewGitRepoCommand.cs @@ -0,0 +1,39 @@ +using System; +using System.Diagnostics; +using System.Management.Automation; +using SQLite; + +namespace PowershellModule.Git; + +[Cmdlet(VerbsCommon.New, Noun)] +public class NewGitRepoCommand : PSCmdlet +{ + private const string Noun = "GitRepo"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + HelpMessage = "Reference name for the repo")] + public string Name { get; set; } + + protected override void BeginProcessing() + { + using var conn = new SQLiteConnection("./test.db"); + + var pwd = this.SessionState.Path.CurrentLocation.Path; + WriteObject("Checking if current directory is a git repository..."); + var ps = new ProcessStartInfo( //$"git -C \"{pwd}\" rev-parse --show-toplevel") + "git", ["rev-parse", "--show-toplevel"]) + { + RedirectStandardOutput = true, + RedirectStandardError = true, + WorkingDirectory = pwd + }; + var a = Process.Start(ps); + Console.WriteLine(a.StandardOutput.ReadToEnd()); + Console.WriteLine(a.StandardError.ReadToEnd()); + + base.BeginProcessing(); + } +} \ No newline at end of file diff --git a/src/PowershellModule/PostBuild.ps1 b/src/PowershellModule/PostBuild.ps1 new file mode 100644 index 0000000..d4c0725 --- /dev/null +++ b/src/PowershellModule/PostBuild.ps1 @@ -0,0 +1,27 @@ +<# + .SYNOPSIS + Removes all non-core files from build output +#> +param( + [Parameter(ValueFromPipeline = $true, Position = 0, Mandatory = $true)] + $targetDir +) + +$nativeSqliteDllLocation = "$( $targetDir )runtimes\win-x64\native\e_sqlite3.dll"; + +if ($false -eq (Test-Path $nativeSqliteDllLocation)) +{ + Write-Error "POST BUILD FAILED: Unable to locate $nativeSqliteDllLocation" +} + +Write-Host "Copying '$nativeSqliteDllLocation' to '$targetDir'" +Copy-Item -Path $nativeSqliteDllLocation -Destination $targetDir + +# Because we use CopyLocalLockFileAssemblies Files that are needed for the module +$allowList = @( + "ModuleCore*" + "PowershellModule*" + "*SQLite*" +) +Write-Host "Removing all non-module required files from '$targetDir'" +Get-ChildItem -Path $targetDir -exclude $allowList | Remove-Item -Recurse \ No newline at end of file diff --git a/src/PowershellModule/PowershellModule.csproj b/src/PowershellModule/PowershellModule.csproj index c7f5801..95ccbdc 100644 --- a/src/PowershellModule/PowershellModule.csproj +++ b/src/PowershellModule/PowershellModule.csproj @@ -5,16 +5,22 @@ PowershellModule latestmajor enable + true All + + + + +