From 229f69313b7936891086a01f7a3d6b6536f099c0 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Sun, 1 Dec 2019 22:30:57 +0000 Subject: [PATCH] final tidy for PR --- CI/Test-SingleFunctions.ps1 | 2 +- CI/build.ps1 | 80 +++++++++++++++++++ ...cksToExcel.ps1 => Export-StocksToExcel.ps1 | 0 Public/Import-Excel.ps1 | 2 +- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 CI/build.ps1 rename Public/Export-StocksToExcel.ps1 => Export-StocksToExcel.ps1 (100%) diff --git a/CI/Test-SingleFunctions.ps1 b/CI/Test-SingleFunctions.ps1 index 6c2350b..ac83cbb 100644 --- a/CI/Test-SingleFunctions.ps1 +++ b/CI/Test-SingleFunctions.ps1 @@ -48,7 +48,7 @@ $reg2 = [Regex]::new(@" # elseif ($reg2.IsMatch($m[0].Value)) {return "function $name has comment-based help"} elseif ($m[0] -inotmatch "\[CmdletBinding\(" -and $m[0] -inotmatch "\[parameter\(" ) {return "$name has is not an advanced function"} - elseif (-not (& $Name -?).synopsis) {return "$name has no help"} + #elseif (-not (& $Name -?).synopsis) {return "$name has no help"} else {Write-Verbose "$name OK"} } } \ No newline at end of file diff --git a/CI/build.ps1 b/CI/build.ps1 new file mode 100644 index 0000000..bff69de --- /dev/null +++ b/CI/build.ps1 @@ -0,0 +1,80 @@ +[CmdletBinding(DefaultParameterSetName = 'Default')] +param( + # Path to install the module to, if not provided -Scope used. + [Parameter(Mandatory, ParameterSetName = 'ModulePath')] + [ValidateNotNullOrEmpty()] + [String]$ModulePath, + + # Path to install the module to, PSModulePath "CurrentUser" or "AllUsers", if not provided "CurrentUser" used. + [Parameter(Mandatory, ParameterSetName = 'Scope')] + [ValidateSet('CurrentUser', 'AllUsers')] + [string] + $Scope = 'CurrentUser', + [switch]$Passthru, + [switch]$Tests +) + +if ($PSScriptRoot) { Push-Location $PSScriptRoot } + +$psdpath = Get-Item "*.psd1" +if (-not $psdpath -or $psdpath.count -gt 1) { + throw "Did not find a unique PSD file " +} +else { + $ModuleName = $psdpath.Name -replace '\.psd1$' , '' + $Settings = $(& ([scriptblock]::Create(($psdpath | Get-Content -Raw)))) +} + +try { + Write-Verbose -Message 'Module installation started' + + if (!$ModulePath) { + if ($IsLinux -or $IsMacOS) {$ModulePathSeparator = ':' } + else {$ModulePathSeparator = ';' } + + if ($Scope -eq 'CurrentUser') { $dir = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile) } + else { $dir = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFiles) } + $ModulePath = ($env:PSModulePath -split $ModulePathSeparator).where({$_ -like "$dir*"},"First",1) + $ModulePath = Join-Path -Path $ModulePath -ChildPath $ModuleName + $ModulePath = Join-Path -Path $ModulePath -ChildPath $Settings.ModuleVersion + } + + # Create Directory + if (-not (Test-Path -Path $ModulePath)) { + $null = New-Item -Path $ModulePath -ItemType Directory -ErrorAction Stop + Write-Verbose -Message ('Created module folder: "{0}"' -f $ModulePath) + } + + Write-Verbose -Message ('Copying files to "{0}"' -f $ModulePath) + $outputFile = $psdpath | Copy-Item -Destination $ModulePath -PassThru + Foreach ($file in $Settings.FileList) { + if ($file -like '.\*') { + $dest = ($file -replace '\.\\',"$ModulePath\") + if (-not (Test-Path -PathType Container (Split-Path -Parent $dest))) { + $null = New-item -Type Directory -Path (Split-Path -Parent $dest) + } + } + else {$dest = $ModulePath } + Copy-Item $file -Destination $dest -Force -Recurse + } + + if (Test-Path -PathType Container "mdHelp") { + if (-not (Get-Module -ListAvailable platyPS)) { + Write-Verbose-Message ('Installing Platyps to build help files') + Install-Module -Name platyPS -Force -SkipPublisherCheck + } + Import-Module platyPS + Get-ChildItem .\mdHelp -Directory | ForEach-Object { + New-ExternalHelp -Path $_.FullName -OutputPath (Join-Path $ModulePath $_.Name) -Force -Verbose + } + } + $env:PSNewBuildModule = $ModulePath + + if ($Passthru) {$outputFile} +} +catch { + throw ('Failed installing module "{0}". Error: "{1}" in Line {2}' -f $ModuleName, $_, $_.InvocationInfo.ScriptLineNumber) +} +finally { + Write-Verbose -Message 'Module installation end' +} \ No newline at end of file diff --git a/Public/Export-StocksToExcel.ps1 b/Export-StocksToExcel.ps1 similarity index 100% rename from Public/Export-StocksToExcel.ps1 rename to Export-StocksToExcel.ps1 diff --git a/Public/Import-Excel.ps1 b/Public/Import-Excel.ps1 index 5bd4389..11a856b 100644 --- a/Public/Import-Excel.ps1 +++ b/Public/Import-Excel.ps1 @@ -162,7 +162,7 @@ #region Create one object per row if ($AsText) { <#join items in AsText together with ~~~ . Escape any regex special characters... - # which turns * into \* make it .*. Convert ~~~ to $|^ and top and tail with ^%; + # which turns "*" into "\*" make it ".*". Convert ~~~ to $|^ and top and tail with ^%; So if we get "Week", "[Time]" and "*date*" ; make the expression ^week$|^\[Time\]$|^.*Date.*$ $make a regex for this which is case insensitive (option 1) and compiled (option 8) #>