From ee25d91cb83930bb9dce04e7c984eb9eb48a4e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 14 Feb 2021 20:54:21 +0100 Subject: [PATCH 01/10] feat(format): Always use backslashes in paths --- bin/format.ps1 | 5 +- bin/formatjson.ps1 | 140 +-------------------------------------------- 2 files changed, 5 insertions(+), 140 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index 6d05f8e592..b092a2589f 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -145,8 +145,11 @@ foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { } #endregion Architecture properties sort + #region Backslash replaces (bin, shortcuts, extract_dir, persist, env_add_path, env_set) + #endregion Backslash replaces (bin, shortcuts, extract_dir, persist, env_add_path, env_set) + $newManifest = [PSCustomObject] @{ } - '##', '_comment', 'version', 'description', 'homepage', 'license', 'notes', 'changelog', 'depends' | ForEach-Object { + '##', 'version', 'description', 'homepage', 'license', 'notes', 'changelog', 'depends' | ForEach-Object { if ($manifest.$_) { $newManifest | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $manifest.$_ $manifest.PSObject.Properties.Remove($_) diff --git a/bin/formatjson.ps1 b/bin/formatjson.ps1 index 5eb3bccc68..bc108537ac 100644 --- a/bin/formatjson.ps1 +++ b/bin/formatjson.ps1 @@ -28,142 +28,4 @@ param( . (Join-Path $PSScriptRoot "..\lib\$_.ps1") } -$Dir = Resolve-Path $Dir -$exitCode = 0 -$problems = 0 - -function _infoMes ($name, $mes) { Write-UserMessage -Message "${name}: $mes" -Info } - -foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { - $name = $gci.Basename - if ($gci.Extension -notmatch "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)") { - Write-UserMessage "Skipping $($gci.Name)" -Info - continue - } - - try { - $manifest = ConvertFrom-Manifest -Path $gci.FullName - } catch { - Write-UserMessage -Message "Invalid manifest: $($gci.Name)" -Err - ++$problems - - continue - } - - #region Migrations and fixes - #region Checkver - $checkver = $manifest.checkver - if ($checkver -and ($checkver.GetType() -ne [System.String])) { - # Remove not needed url - if ($checkver.url -and ($checkver.url -eq $manifest.homepage)) { - _infoMes $name 'Removing checkver.url (same as homepage)' - $checkver.PSObject.Properties.Remove('url') - } - - if ($checkver.jp) { - _infoMes $name 'checkver.jp -> checkver.jsonpath' - - $checkver | Add-Member -MemberType 'NoteProperty' -Name 'jsonpath' -Value $checkver.jp - $checkver.PSObject.Properties.Remove('jp') - } - - if ($checkver.re) { - _infoMes $name 'checkver.re -> checkver.regex' - - $checkver | Add-Member -MemberType 'NoteProperty' -Name 'regex' -Value $checkver.re - $checkver.PSObject.Properties.Remove('re') - - if ($checkver.reverse) { - _infoMes $name 'checkver.reverse -> after regex' - - $rev = $checkver.reverse - $checkver.PSObject.Properties.Remove('reverse') - $checkver | Add-Member -MemberType 'NoteProperty' -Name 'reverse' -Value $rev - } - } - - # Only one property regex - if (($checkver.PSObject.Properties.Name.Count -eq 1) -and $checkver.regex) { - _infoMes $name 'alone checkver.regex -> checkver' - $checkver = $checkver.regex - } - - if (($checkver.PSObject.Properties.Name -eq 'replace') -and ($checkver.PSObject.Properties.Name[-1] -ne 'replace')) { - _infoMes $name 'Sort: checkver.replace -> latest' - - $repl = $checkver.replace - $checkver.PSObject.Properties.Remove('replace') - $checkver | Add-Member -MemberType 'NoteProperty' -Name 'replace' -Value $repl - } - - # Only one github property and homepage is set to github repository - if (($checkver.PSObject.Properties.Name.Count -eq 1) -and $checkver.github -and ($checkver.github -eq $manifest.homepage)) { - _infoMes $name 'alone checkver.github -> checkver github string' - - $checkver = 'github' - } - - $manifest.checkver = $checkver - } - #endregion Checkver - - #region Architecture properties sort - foreach ($mainProp in 'architecture', 'autoupdate') { - if ($mainProp -eq 'autoupdate') { - if ($manifest.$mainProp.architecture) { - $arch = $manifest.$mainProp.architecture - } else { - continue - } - } else { - if ($manifest.$mainProp) { - $arch = $manifest.$mainProp - } else { - continue - } - } - - # Skip single architecture - if ($arch.PSObject.Properties.Name.Count -eq 1) { continue } - - $newArch = [PSCustomObject] @{ } - - # TODO: Mulitple architectures - '64bit', '32bit' | ForEach-Object { - if ($arch.$_) { $newArch | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $arch.$_ } - } - - if ($arch.PSObject.Properties.Name[0] -ne '64bit') { - _infoMes $name "Sorting Arch: $mainProp" - $arch = $newArch - } - - if ($mainProp -eq 'autoupdate') { - $manifest.$mainProp.architecture = $newArch - } else { - $manifest.$mainProp = $newArch - } - } - #endregion Architecture properties sort - - $newManifest = [PSCustomObject] @{ } - '##', '_comment', 'version', 'description', 'homepage', 'license', 'notes', 'changelog', 'depends' | ForEach-Object { - if ($manifest.$_) { - $newManifest | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $manifest.$_ - $manifest.PSObject.Properties.Remove($_) - } - } - - # Add remaining properties in same order - $manifest.PSObject.Properties.Name | ForEach-Object { - $newManifest | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $manifest.$_ - } - - $manifest = $newManifest - #endregion Migrations and fixes - - ConvertTo-Manifest -Path $gci.FullName -Manifest $manifest -} - -if ($problems -gt 0) { $exitCode = 10 + $problems } -exit $exitCode +& (Join-Path $PSScriptRoot 'format.ps1') -App $App -Dir $Dir From 1fe2ced3ba2c4c7181fc73ee7f6dcd357feb6edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 14 Feb 2021 21:44:13 +0100 Subject: [PATCH 02/10] test --- bin/format.ps1 | 89 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index b092a2589f..9fa7b35340 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -28,33 +28,21 @@ param( . (Join-Path $PSScriptRoot "..\lib\$_.ps1") } -$Dir = Resolve-Path $Dir -$exitCode = 0 -$problems = 0 - function _infoMes ($name, $mes) { Write-UserMessage -Message "${name}: $mes" -Info } -foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { - $name = $gci.Basename - if ($gci.Extension -notmatch "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)") { - Write-UserMessage "Skipping $($gci.Name)" -Info - continue - } +#region Formatters +$persistBlock = { + $new = @() + $args | ForEach-Object { $new += $_ -replace '/', '\' } - try { - $manifest = ConvertFrom-Manifest -Path $gci.FullName - } catch { - Write-UserMessage -Message "Invalid manifest: $($gci.Name)" -Err - ++$problems - continue - } + return $new +} - #region Migrations and fixes - #region Checkver - $checkver = $manifest.checkver +$checkverBlock = { + $checkver = $args[0] if ($checkver -and ($checkver.GetType() -ne [System.String])) { # Remove not needed url - if ($checkver.url -and ($checkver.url -eq $manifest.homepage)) { + if ($checkver.url -and ($checkver.url -eq $Manifest.homepage)) { _infoMes $name 'Removing checkver.url (same as homepage)' $checkver.PSObject.Properties.Remove('url') } @@ -102,8 +90,59 @@ foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { $checkver = 'github' } - $manifest.checkver = $checkver + return $checkver + } +} +#endregion Formatters + +function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAutoupdate, [Switch] $SkipArchitecture) { + $prop = $Manifest.$Property + # Generic property + if ($prop) { + $Manifest.$Property = $ScriptBlock.Invoke($prop) + } + + # Architecture specific + $archSpec = $Manifest.architecture + if (!$SkipArchitecture -and $archSpec) { + # TODO: Multiple architectures + '64bit', '32bit' | ForEach-Object { + if ($archSpec.$_ -and $archSpec.$_.$Property) { + $archSpec.$_.$Property = $ScriptBlock.Invoke($archSpec.$_.$Property) + } + } + } + + # Autoupdate + if (!$SkipAutoupdate -and $Manifest.autoupdate) { + $Manifest.autoupdate = _adjustProperty -Manifest $Manifest.autoupdate -Property $Property -ScriptBlock $ScriptBlock } + + return $Manifest +} + +$Dir = Resolve-Path $Dir +$exitCode = 0 +$problems = 0 + +foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { + $name = $gci.Basename + if ($gci.Extension -notmatch "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)") { + Write-UserMessage "Skipping $($gci.Name)" -Info + continue + } + + try { + $manifest = ConvertFrom-Manifest -Path $gci.FullName + } catch { + Write-UserMessage -Message "Invalid manifest: $($gci.Name)" -Err + ++$problems + continue + } + + #region Migrations and fixes + #region Checkver + $manifest = _adjustProperty -Manifest $Manifest -Property 'checkver' -ScriptBlock $checkverBlock -SkipAutoupdate -SkipArchitecture #endregion Checkver #region Architecture properties sort @@ -145,8 +184,10 @@ foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { } #endregion Architecture properties sort - #region Backslash replaces (bin, shortcuts, extract_dir, persist, env_add_path, env_set) - #endregion Backslash replaces (bin, shortcuts, extract_dir, persist, env_add_path, env_set) + #region Backslash replaces + $manifest = _adjustProperty -Manifest $manifest -Property 'env_add_path' -ScriptBlock $persistBlock + $manifest = _adjustProperty -Manifest $manifest -Property 'persist' -ScriptBlock $persistBlock + #endregion Backslash replaces $newManifest = [PSCustomObject] @{ } '##', 'version', 'description', 'homepage', 'license', 'notes', 'changelog', 'depends' | ForEach-Object { From a16313a08b276aca6ee59bac645b8da845b5fae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 14 Feb 2021 21:47:42 +0100 Subject: [PATCH 03/10] TODO: Fix always return array --- bin/format.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index 9fa7b35340..913e7837c5 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -39,7 +39,7 @@ $persistBlock = { } $checkverBlock = { - $checkver = $args[0] + $checkver = $args if ($checkver -and ($checkver.GetType() -ne [System.String])) { # Remove not needed url if ($checkver.url -and ($checkver.url -eq $Manifest.homepage)) { @@ -89,9 +89,9 @@ $checkverBlock = { $checkver = 'github' } - - return $checkver } + + return $checkver } #endregion Formatters From c91af450c337ee365e7eabdfb8d72224d9f2bfa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 17 Feb 2021 19:20:04 +0100 Subject: [PATCH 04/10] merge completed --- bin/format.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/format.ps1 b/bin/format.ps1 index 2138fc33c9..7c721e9105 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -28,6 +28,10 @@ param( . (Join-Path $PSScriptRoot "..\lib\$_.ps1") } +$Dir = Resolve-Path $Dir +$exitCode = 0 +$problems = 0 + function _infoMes ($name, $mes) { Write-UserMessage -Message "${name}: $mes" -Info } function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAutoupdate, [Switch] $SkipArchitecture) { From b9902d7469538e18a27528b474a623f750c855f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 17 Feb 2021 19:21:24 +0100 Subject: [PATCH 05/10] ch [ci skip] --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 154cfaed8f..f06ab0d6d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ ### 0.6-pre2 -- **format**: Extract checkver fixes into own function and add generic adjust property function +- **format** + - Always convert forward slashes into backslashes in persist property + - Extract checkver fixes into own function and add generic adjust property function - **schema** - Remove deprecated short properties - Cleanup descriptions From 501c5de79bb51730d33bb6cfa18946eea9c6271f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 17 Feb 2021 19:22:44 +0100 Subject: [PATCH 06/10] naming --- bin/format.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index 7c721e9105..e8d16cd131 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -59,7 +59,7 @@ function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAuto } #region Formatters -$persistBlock = { +$backslashFormatBlock = { $new = @() $args | ForEach-Object { $new += $_ -replace '/', '\' } @@ -148,8 +148,8 @@ foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { $manifest = _adjustProperty -Manifest $manifest -Property 'checkver' -ScriptBlock $checkverFormatBlock -SkipAutoupdate # Backslash format - $manifest = _adjustProperty -Manifest $manifest -Property 'env_add_path' -ScriptBlock $persistBlock - $manifest = _adjustProperty -Manifest $manifest -Property 'persist' -ScriptBlock $persistBlock + $manifest = _adjustProperty -Manifest $manifest -Property 'env_add_path' -ScriptBlock $backslashFormatBlock + $manifest = _adjustProperty -Manifest $manifest -Property 'persist' -ScriptBlock $backslashFormatBlock #region Architecture properties sort # TODO: Extract From b3add4bb59ce58e4d6530b278785158ee5376cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 17 Feb 2021 19:43:48 +0100 Subject: [PATCH 07/10] fix --- bin/format.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index e8d16cd131..22dc12d56c 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -37,7 +37,9 @@ function _infoMes ($name, $mes) { Write-UserMessage -Message "${name}: $mes" -In function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAutoupdate, [Switch] $SkipArchitecture) { $prop = $Manifest.$Property if ($prop) { - $Manifest.$Property = $ScriptBlock.Invoke($prop)[0] + $result = $ScriptBlock.Invoke($prop) + $result = if ($result.Count -eq 1) { $result[0] } else { $result } + $Manifest.$Property = $result } # Architecture specific @@ -45,10 +47,11 @@ function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAuto if (!$SkipArchitecture -and $archSpec) { (Get-NotePropertyEnumerator -Object $archSpec).Name | ForEach-Object { if ($archSpec.$_ -and $archSpec.$_.$Property) { - $Manifest.architecture.$_.$Property = $ScriptBlock.Invoke($archSpec.$_.$Property) + $result = $ScriptBlock.Invoke($archSpec.$_.$Property) + $result = if ($result.Count -eq 1) { $result[0] } else { $result } + $Manifest.architecture.$_.$Property = $result } } - } if (!$SkipAutoupdate -and $Manifest.autoupdate) { From 0dcc3473153f51f1cf5e264bcf708ba30de255f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 17 Feb 2021 19:59:59 +0100 Subject: [PATCH 08/10] fix --- bin/format.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index 22dc12d56c..5651d3e2ab 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -38,7 +38,7 @@ function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAuto $prop = $Manifest.$Property if ($prop) { $result = $ScriptBlock.Invoke($prop) - $result = if ($result.Count -eq 1) { $result[0] } else { $result } + $result = if (($prop.Count -gt 1) -or ($result.Count -gt 1)) { $result } else { $result[0] } $Manifest.$Property = $result } @@ -48,7 +48,7 @@ function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAuto (Get-NotePropertyEnumerator -Object $archSpec).Name | ForEach-Object { if ($archSpec.$_ -and $archSpec.$_.$Property) { $result = $ScriptBlock.Invoke($archSpec.$_.$Property) - $result = if ($result.Count -eq 1) { $result[0] } else { $result } + $result = if (($archSpec.$_.$Property.Count -gt 1) -or ($result.Count -eq 1)) { $result } else { $result[0] } $Manifest.architecture.$_.$Property = $result } } From 6fd2dccda87cc260d2a75aa2cfd1d92dd5a4323f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 17 Feb 2021 20:38:29 +0100 Subject: [PATCH 09/10] TODO: Fix array of one array with 2 items --- bin/format.ps1 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/format.ps1 b/bin/format.ps1 index 5651d3e2ab..34cd6eda29 100644 --- a/bin/format.ps1 +++ b/bin/format.ps1 @@ -62,9 +62,18 @@ function _adjustProperty ($Manifest, $Property, $ScriptBlock, [Switch] $SkipAuto } #region Formatters -$backslashFormatBlock = { +$binPersistBackslashFormatBlock = { $new = @() - $args | ForEach-Object { $new += $_ -replace '/', '\' } + foreach ($_a in $args) { + if ($_a.Count -eq 1) { + # String + $new += $_a -replace '/', '\' + } elseif ($_a.Count -gt 1) { + # Array with 2 or more items + $_a[0] = $_a[0] -replace '/', '\' + $new += , $_a + } + } return $new } @@ -151,8 +160,8 @@ foreach ($gci in Get-ChildItem $Dir "$App.*" -File) { $manifest = _adjustProperty -Manifest $manifest -Property 'checkver' -ScriptBlock $checkverFormatBlock -SkipAutoupdate # Backslash format - $manifest = _adjustProperty -Manifest $manifest -Property 'env_add_path' -ScriptBlock $backslashFormatBlock - $manifest = _adjustProperty -Manifest $manifest -Property 'persist' -ScriptBlock $backslashFormatBlock + $manifest = _adjustProperty -Manifest $manifest -Property 'bin' -ScriptBlock $binPersistBackslashFormatBlock + $manifest = _adjustProperty -Manifest $manifest -Property 'persist' -ScriptBlock $binPersistBackslashFormatBlock #region Architecture properties sort # TODO: Extract From 1f699b26599a8bd8478dfd0024dbf8d367e47211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Fri, 19 Mar 2021 02:44:59 +0100 Subject: [PATCH 10/10] ch [ci skip] --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94176e41e4..142b5072c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [0.6](https://github.com/Ash258/Scoop-Core/milestone/4) +### 0.6-pre3 + +- **format**: Always convert forward slashes into backslashes in persist property + ### 0.6-pre2 - **scoop-search**: Fix search without parameter provided @@ -10,9 +14,7 @@ - **git**: Fix proxy handling - **psmodules**: Add global modules to path only if global manifest is installed - **decompress**: Support `INNOSETUP_USE_INNOEXTRACT` config option and `Expand-InnoArchive -UseInnoextract` -- **format** - - Always convert forward slashes into backslashes in persist property - - Extract checkver fixes into own function and add generic adjust property function +- **format**: Extract checkver fixes into own function and add generic adjust property function - **schema** - Add `disable` property to `checkver` and `autoupdate` - `-Force` will ignore this property