-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(scoop-import): Import a Scoop installation from JSON #5014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc4cfbd
feat(scoop-export): Export Scoop installation in JSON
rashil2000 db765bc
optimize
rashil2000 1c46f14
yesss done
rashil2000 4686900
complete
rashil2000 29ccbbe
Update CHANGELOG.md
rashil2000 5aceaf9
Add suggestions from code review
rashil2000 86ac7bc
fix CI
rashil2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,23 @@ | ||
| # Usage: scoop export > filename | ||
| # Summary: Exports (an importable) list of installed apps | ||
| # Help: Lists all installed apps. | ||
| # Usage: scoop export > scoopfile.json | ||
| # Summary: Exports installed apps, buckets (and optionally configs) in JSON format | ||
| # Options: | ||
| # -c, --config Export the Scoop configuration file too | ||
|
|
||
| . "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' | ||
| . "$PSScriptRoot\..\lib\manifest.ps1" # 'default_architecture' 'Select-CurrentVersion' (indirectly) | ||
| . "$PSScriptRoot\..\lib\json.ps1" # 'ConvertToPrettyJson' | ||
|
|
||
| $def_arch = default_architecture | ||
| $export = @{} | ||
|
|
||
| $local = installed_apps $false | ForEach-Object { @{ name = $_; global = $false } } | ||
| $global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true } } | ||
|
|
||
| $apps = @($local) + @($global) | ||
| $count = 0 | ||
|
|
||
| # json | ||
| # echo "{[" | ||
|
|
||
| if($apps) { | ||
| $apps | Sort-Object { $_.name } | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object { | ||
| $app = $_.name | ||
| $global = $_.global | ||
| $ver = Select-CurrentVersion -AppName $app -Global:$global | ||
| $global_display = $null; if($global) { $global_display = ' *global*'} | ||
|
|
||
| $install_info = install_info $app $ver $global | ||
| $bucket = '' | ||
| if ($install_info.bucket) { | ||
| $bucket = ' [' + $install_info.bucket + ']' | ||
| } elseif ($install_info.url) { | ||
| $bucket = ' [' + $install_info.url + ']' | ||
| } | ||
| if ($install_info.architecture -and $def_arch -ne $install_info.architecture) { | ||
| $arch = ' {' + $install_info.architecture + '}' | ||
| } else { | ||
| $arch = '' | ||
| } | ||
|
|
||
| # json | ||
| # $val = "{ 'name': '$app', 'version': '$ver', 'global': $($global.toString().tolower()) }" | ||
| # if($count -gt 0) { | ||
| # " ," + $val | ||
| # } else { | ||
| # " " + $val | ||
| # } | ||
|
|
||
| # "$app (v:$ver) global:$($global.toString().tolower())" | ||
| "$app (v:$ver)$global_display$bucket$arch" | ||
|
|
||
| $count++ | ||
| if ($args[0] -eq '-c' -or $args[0] -eq '--config') { | ||
| $export.config = $scoopConfig | ||
| # Remove machine-specific properties | ||
| foreach ($prop in 'lastUpdate', 'rootPath', 'globalPath', 'cachePath') { | ||
| $export.config.PSObject.Properties.Remove($prop) | ||
| } | ||
| } | ||
|
|
||
| # json | ||
| # echo "]}" | ||
| $export.buckets = list_buckets | ||
| $export.apps = @(& "$PSScriptRoot\scoop-list.ps1" 6>$null) | ||
|
|
||
| $export | ConvertToPrettyJSON | ||
|
|
||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Usage: scoop import <path/url to scoopfile.json> | ||
| # Summary: Imports apps, buckets and configs from a Scoopfile in JSON format | ||
|
|
||
| param([Parameter(Mandatory)][String]$scoopfile) | ||
|
|
||
| . "$PSScriptRoot\..\lib\manifest.ps1" | ||
|
|
||
| $import = $null | ||
| $bucket_names = @() | ||
| $def_arch = default_architecture | ||
|
|
||
| if (Test-Path $scoopfile) { | ||
| $import = parse_json $scoopfile | ||
| } elseif ($scoopfile -match '^(ht|f)tps?://|\\\\') { | ||
| $import = url_manifest $scoopfile | ||
| } | ||
|
|
||
| if (!$import) { abort 'Input file not a valid JSON.' } | ||
|
|
||
| $import.config.PSObject.Properties | ForEach-Object { | ||
| set_config $_.Name $_.Value | Out-Null | ||
| Write-Host "'$($_.Name)' has been set to '$($_.Value)'" | ||
| } | ||
|
|
||
| $import.buckets | ForEach-Object { | ||
| add_bucket $_.Name $_.Source | Out-Null | ||
| $bucket_names += $_.Name | ||
| } | ||
|
|
||
| $import.apps | ForEach-Object { | ||
| $info = $_.Info -Split ', ' | ||
| $global = if ('Global install' -in $info) { | ||
| ' --global' | ||
| } else { | ||
| '' | ||
| } | ||
| $arch = if ('64bit' -in $info -and '32bit' -eq $def_arch) { | ||
| ' --arch 64bit' | ||
| } elseif ('32bit' -in $info -and '64bit' -eq $def_arch) { | ||
| ' --arch 32bit' | ||
| } else { | ||
| '' | ||
| } | ||
|
|
||
| $app = if ($_.Source -in $bucket_names) { | ||
| "$($_.Source)/$($_.Name)" | ||
| } elseif ($_.Source -eq '<auto-generated>') { | ||
| "$($_.Name)@$($_.Version)" | ||
| } else { | ||
| $_.Source | ||
| } | ||
|
|
||
| & "$PSScriptRoot\scoop-install.ps1" $app$global$arch | ||
|
|
||
| if ('Held package' -in $info) { | ||
| & "$PSScriptRoot\scoop-hold.ps1" $($_.Name)$global | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.