New-Package.ps1 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. param($Name, $Type)
  2. <#
  3. .SYNOPSIS
  4. Create a new package from the template
  5. .DESCRIPTION
  6. This function creates a new package by using the directory _template which contains desired package basic settings.
  7. #>
  8. function New-Package{
  9. [CmdletBinding()]
  10. param(
  11. #Package name
  12. [string] $Name,
  13. #Type of the package
  14. [ValidateSet('Portable', 'Installer')]
  15. [string] $Type='Installer',
  16. #Github repository in the form username/repository
  17. [string] $GithubRepository
  18. )
  19. if ($Name -eq $null) { throw "Name can't be empty" }
  20. if (Test-Path $Name) { throw "Package with that name already exists" }
  21. if (!(Test-Path _template)) { throw "Template for the packages not found" }
  22. cp _template $Name -Recurse
  23. $nuspec = gc "$Name\template.nuspec"
  24. rm "$Name\template.nuspec"
  25. Write-Verbose 'Fixing nuspec'
  26. $nuspec = $nuspec -replace '<id>.+', "<id>$Name</id>"
  27. $nuspec = $nuspec -replace '<iconUrl>.+', "<iconUrl>https://cdn.rawgit.com/$GithubRepository/master/$Name/icon.png</iconUrl>"
  28. $nuspec = $nuspec -replace '<packageSourceUrl>.+', "<packageSourceUrl>https://github.com/$GithubRepository/tree/master/$Name</packageSourceUrl>"
  29. $nuspec | Out-File -Encoding UTF8 "$Name\$Name.nuspec"
  30. switch ($Type)
  31. {
  32. 'Installer' {
  33. Write-Verbose 'Using installer template'
  34. rm "$Name\tools\chocolateyInstallZip.ps1"
  35. mv "$Name\tools\chocolateyInstallExe.ps1" "$Name\tools\chocolateyInstall.ps1"
  36. }
  37. 'Portable' {
  38. Write-Verbose 'Using portable template'
  39. rm "$Name\tools\chocolateyInstallExe.ps1"
  40. mv "$Name\tools\chocolateyInstallZip.ps1" "$Name\tools\chocolateyInstall.ps1"
  41. }
  42. }
  43. Write-Verbose 'Fixing chocolateyInstall.ps1'
  44. $installer = gc "$Name\tools\chocolateyInstall.ps1"
  45. $installer -replace "(^[$]packageName\s*=\s*)('.*')", "`$1'$($Name)'" | sc "$Name\tools\chocolateyInstall.ps1"
  46. }
  47. New-Package $Name $Type -GithubRepository majkinetor/chocolatey -Verbose