Skip to content
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

add support for custom repositories #440

Closed
jhainau opened this issue Dec 23, 2019 · 1 comment · Fixed by #443
Closed

add support for custom repositories #440

jhainau opened this issue Dec 23, 2019 · 1 comment · Fixed by #443
Assignees
Milestone

Comments

@jhainau
Copy link
Contributor

jhainau commented Dec 23, 2019

Describe the Change

Setup;PS1 - add support for custom repositories that have already been registered using the 'Register-PSRepository' command

`function Install-PodeLocalModules
{
param (
[Parameter()]
$Modules = $null
)

	if ($null -eq $Modules) {
		return
	}

	$psModules = './ps_modules'

	# download modules to ps_modules
	$Modules.psobject.properties.name | ForEach-Object {
		$_name = $_
		$_version = $Modules.$_name.version
		$_repository = if ([string]::IsNullOrEmpty("$($Modules.$_name.$_repository)")) { 
			'psgallery' 
		} else {
			[string]"$($Modules.$_name.$_repository)" 
			}

		try {
			# if version is latest, retrieve current
			if ($_version -ieq 'latest') {
				$_version = [string]((Find-Module -Repository $_repository -Name $_name -ErrorAction Ignore).Version)
			}

			Write-Host "=> Downloading $($_name)@$($_version) from $($_repository)... " -NoNewline -ForegroundColor Cyan

			# if the current version exists, do nothing
			if (!(Test-Path (Join-Path $psModules "$($_name)/$($_version)"))) {
				# remove other versions
				if (Test-Path (Join-Path $psModules "$($_name)")) {
					Remove-Item -Path (Join-Path $psModules "$($_name)") -Force -Recurse | Out-Null
				}

				# download the module
				Save-Module -Repository $_repository -Name $_name -RequiredVersion $_version -Path $psModules -Force -ErrorAction Stop | Out-Null
			}

			Write-Host 'Success' -ForegroundColor Green
		}
		catch {
			Write-Host 'Failed' -ForegroundColor Red
			throw "Module or version not found: $($_name)@$($_version) in Repository '$($_repository)'"
		}
	}
}`

Related Issues

https://badgerati.github.io/Pode/Getting-Started/LocalModules/ states that only the default PSGallery is supported, but custom repositories can easily be supported by adding the repository name to the 'ps_modules' file and to the setup.ps1 file

Additional Details

Modified ps_modules file content example:
{ "modules": { "eps": {"version": "0.5.0", "repository": "psgallery" } }, "devModules": { "pester": {"version": "latest", "repository": "psgallery" } } }

@Badgerati
Copy link
Owner

Yes, originally this was only meant to just be basic support - but adding in custom repositories is all right.

Looking at the change it does require the ps_modules section in the package.json file to change 🤔 so the function will need to support the old and new (something like: if $Modules.$_name.version is null then assume original format and default to PSGallery)

@Badgerati Badgerati self-assigned this Dec 24, 2019
@Badgerati Badgerati added this to the 1.3.0 milestone Dec 24, 2019
Badgerati added a commit that referenced this issue Dec 24, 2019
Badgerati added a commit that referenced this issue Dec 26, 2019
#440: Adds support for custom repos in package.json
@Badgerati Badgerati mentioned this issue Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants