Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. function Add-Version {
  2. [CmdletBinding()]param (
  3. [System.Version]$current,
  4. [System.Version]$increment
  5. )
  6. if ($current) {
  7. [System.Version]::new(
  8. $current.Major + $increment.Major,
  9. $current.Minor + $increment.Minor,
  10. $current.Build + $increment.Build,
  11. $current.Revision + $increment.Revision
  12. )
  13. } else {
  14. [System.Version]::new('1.0.0.0')
  15. }
  16.  
  17. }
  18.  
  19. function Set-Json {
  20. [CmdletBinding(SupportsShouldProcess=$true)]param (
  21. $json,
  22. $jsonpath,
  23. $value
  24. )
  25. if ($PScmdlet.ShouldProcess($jsonpath)) {
  26. #TODO: update json with value
  27. }
  28. }
  29.  
  30. function Copy-Module {
  31. [CmdletBinding(SupportsShouldProcess=$true)]param (
  32. $ComputerName,
  33. $ModuleName,
  34. $OutputDirectory,
  35. $BinarySourceDirectory,
  36. [switch]$Force
  37. )
  38. if (![string]::IsNullOrEmpty($ModuleName)) {
  39. if (![string]::IsNullOrEmpty($OutputDirectory)) {
  40. $targetDir = "$OutputDirectory\$ModuleName"
  41. } else {
  42. $targetDir = "\\$ComputerName\c$\Program Files\WindowsPowerShell\Modules\$ModuleName"
  43. }
  44. if ($PScmdlet.ShouldProcess($targetDir)) {
  45. remove-item $targetDir -Force:$Force -Recurse -ErrorAction SilentlyContinue
  46. mkdir $targetDir -Force:$Force -ErrorAction SilentlyContinue
  47. copy-item -Path "$moduleName.psm1" $targetDir -Force:$Force
  48. copy-item -Path "$moduleName.psd1" $targetDir -Force:$Force
  49. if ($BinarySourceDirectory) {
  50. copy-item ".\$BinarySourceDirectory" -Exclude 'System.*','Microsoft.*' -Destination $targetDir -Recurse -Force:$Force
  51. }
  52. }
  53. }
  54. }
  55.  
  56. function Install-Prequisites {
  57. [CmdletBinding(SupportsShouldProcess=$true)]param (
  58. )
  59. $Args | % {
  60. invoke-expression $_
  61. }
  62. }
  63.  
  64. function Publish-Module2 {
  65. [CmdletBinding(SupportsShouldProcess=$true)]param (
  66. $ModuleName,
  67. $BuildTargets,
  68. $BinarySourceDirectory,
  69. $OutputDirectory,
  70. [System.Version]$VersionIncrement = '0.0.0.1'
  71. )
  72. Install-Prequisites
  73. if ($VersionIncrement) {
  74. $currentVersion = Select-Json 'build.json' 'New-ModuleManifest.ModuleVersion'
  75. $currentVersion = Add-Version $currentVersion $VersionIncrement
  76. Set-Json 'build.json' 'New-ModuleManifest.ModuleVersion' $currentVersion
  77. }
  78. New-ModuleManifest
  79. $BuildTargets | % {
  80. Copy-Module -ModuleName $ModuleName -ComputerName $_ -BinarySourceDirectory $BinarySourceDirectory -Force
  81. }
  82. if (![string]::IsNullOrEmpty($OutputDirectory)) {
  83. Copy-Module -ModuleName $ModuleName -OutputDirectory $OutputDirectory -BinarySourceDirectory $BinarySourceDirectory -Force
  84. }
  85. }
  86.  
  87. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement