-
Notifications
You must be signed in to change notification settings - Fork 44
/
New-Package.ps1
66 lines (55 loc) · 2.46 KB
/
New-Package.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
param($Name, $Type)
<#
.SYNOPSIS
Create a new package from the template
.DESCRIPTION
This function creates a new package by using the directory _template which contains desired package basic settings.
#>
function New-Package{
[CmdletBinding()]
param(
#Package name
[string] $Name,
#Type of the package
[ValidateSet('Portable', 'Installer', 'EPortable', 'EInstaller')]
[string] $Type,
#Github repository in the form username/repository
[string] $GithubRepository
)
if ($Name -eq $null) { throw "Name can't be empty" }
if (Test-Path $Name) { throw "Package with that name already exists" }
if (!(Test-Path _template)) { throw "Template for the packages not found" }
cp _template $Name -Recurse
$nuspec = gc "$Name\template.nuspec"
rm "$Name\template.nuspec"
Write-Verbose 'Fixing nuspec'
$nuspec = $nuspec -replace '<id>.+', "<id>$Name</id>"
$nuspec = $nuspec -replace '<iconUrl>.+', "<iconUrl>https://cdn.rawgit.com/$GithubRepository/master/$Name/icon.png</iconUrl>"
$nuspec = $nuspec -replace '<packageSourceUrl>.+', "<packageSourceUrl>https://github.com/$GithubRepository/tree/master/$Name</packageSourceUrl>"
$nuspec | Out-File -Encoding UTF8 "$Name\$Name.nuspec"
switch ($Type)
{
'Installer' {
Write-Verbose 'Using installer template'
mv "$Name\tools\chocolateyInstallExe.ps1" "$Name\tools\chocolateyInstall.ps1"
}
'Portable' {
Write-Verbose 'Using portable template'
mv "$Name\tools\chocolateyInstallZip.ps1" "$Name\tools\chocolateyInstall.ps1"
}
'EInstaller' {
Write-Verbose 'Using embedded installer template'
mv "$Name\tools\chocolateyInstallEmbeddedExe.ps1" "$Name\tools\chocolateyInstall.ps1"
}
'EPortable' {
Write-Verbose 'Using embedded portable template'
mv "$Name\tools\chocolateyInstallEmbeddedZip.ps1" "$Name\tools\chocolateyInstall.ps1"
}
default { throw 'No template given' }
}
rm "$Name\tools\*.ps1" -Exclude chocolateyInstall.ps1, chocolateyUninstall.ps1
Write-Verbose 'Fixing chocolateyInstall.ps1'
$installer = gc "$Name\tools\chocolateyInstall.ps1"
$installer -replace "(^[$]packageName\s*=\s*)('.*')", "`$1'$($Name)'" | Set-Content "$Name\tools\chocolateyInstall.ps1"
}
New-Package $Name $Type -GithubRepository majkinetor/chocolatey -Verbose