forked from IdeaBlade/Breeze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageNuget.ps1
80 lines (68 loc) · 2.79 KB
/
PackageNuget.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function pauseAndThrow($msg="") {
if ($msg -ne "") {
Write-Host $msg
}
Write-Host "Press any key to continue ..."
cmd /c pause | out-null
throw $msg
}
function checkIfCurrent([string] $filePath, [int] $minutesOld) {
$now = [datetime]::Now
$lastWrite = $now.AddMinutes(-1*$minutesOld)
$oldFiles = get-childItem $filePath | Where {$_.LastWriteTime -lt "$lastWrite"}
if ($oldFiles -ne $null) {
$oldFiles | foreach-object {
$fileName = $_.fullName
write-host "The $fileName file is too old"
}
pauseAndThrow("")
}
}
function getBreezeVersion($srcDir) {
$versionFile = "$srcDir\Breeze.Client\Scripts\IBlade\_head.jsfrag"
$text = get-content $versionFile
$versionNum = (Select-String '\s+version:\s*"(?<version>\d.\d\d*.?\d*)"' $versionFile).Matches[0].Groups[1].Value
return $versionNum
}
function packageNuget($srcDir, $folderName, $versionNum, $isBase) {
Write-Host "Packaging nuget - $folderName ..."
$destDir = "$srcDir\Nuget.builds\$folderName"
$nuspecFile = "$destDir\Default.nuspec"
if (!(test-path $nuspecFile)) {
pauseAndThrow "Unable to locate $nuspecFile"
}
$outputFile = "$destDir\$folderName.nuspec"
# remove old nupkg files
gci $destDir *.nupkg -force | foreach ($_) { remove-item $_.fullname -Force }
if ($isBase) {
copy-item $srcDir\Breeze.Client\Scripts\breeze*.js $destDir\content\Scripts
copy-item $srcDir\Breeze.Client\Scripts\ThirdParty\q.js $destDir\content\Scripts
copy-item $srcDir\Breeze.Client\Scripts\ThirdParty\q.min.js $destDir\content\Scripts
copy-item $srcDir\Breeze.WebApi\Breeze.WebApi.dll $destDir\lib\
copy-item $srcDir\ThirdParty\Irony.dll $destDir\lib
}
$input = get-content $nuspecFile
$search1 = '{{version}}'
$replace1 = $versionNum
$search2 = '{{id}}'
$replace2 = $folderName
$output = $input |
Foreach-Object {$_ -replace $search1, $replace1 } |
Foreach-Object {$_ -replace $search2, $replace2 }
$output | Set-Content $outputFile
cd "$destDir"
$expr = "nuget pack $folderName.nuspec"
invoke-expression $expr
}
#----------------------------------------------------------------------
# srcDir is the location of this script file
$srcDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
# Check that all files have been updated within the last 5 minutes
$minutes = 30
checkIfCurrent $srcDir\Breeze.webApi\Breeze.webApi.dll $minutes
checkIfCurrent $srcDir\Breeze.Client\Scripts\breeze*.js $minutes
$versionNum = getBreezeVersion $srcDir
packageNuget $srcDir 'Breeze.WebApi' $versionNum $true
packageNuget $srcDir 'Breeze.WebApiSample' $versionNum $false
Write-Host "Press any key to continue ..."
cmd /c pause | out-null