Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Add-Version {
- [CmdletBinding()]param (
- [System.Version]$current,
- [System.Version]$increment
- )
- if ($current) {
- [System.Version]::new(
- $current.Major + $increment.Major,
- $current.Minor + $increment.Minor,
- $current.Build + $increment.Build,
- $current.Revision + $increment.Revision
- )
- } else {
- [System.Version]::new('1.0.0.0')
- }
- }
- function Set-Json {
- [CmdletBinding(SupportsShouldProcess=$true)]param (
- $json,
- $jsonpath,
- $value
- )
- if ($PScmdlet.ShouldProcess($jsonpath)) {
- #TODO: update json with value
- }
- }
- function Copy-Module {
- [CmdletBinding(SupportsShouldProcess=$true)]param (
- $ComputerName,
- $ModuleName,
- $OutputDirectory,
- $BinarySourceDirectory,
- [switch]$Force
- )
- if (![string]::IsNullOrEmpty($ModuleName)) {
- if (![string]::IsNullOrEmpty($OutputDirectory)) {
- $targetDir = "$OutputDirectory\$ModuleName"
- } else {
- $targetDir = "\\$ComputerName\c$\Program Files\WindowsPowerShell\Modules\$ModuleName"
- }
- if ($PScmdlet.ShouldProcess($targetDir)) {
- remove-item $targetDir -Force:$Force -Recurse -ErrorAction SilentlyContinue
- mkdir $targetDir -Force:$Force -ErrorAction SilentlyContinue
- copy-item -Path "$moduleName.psm1" $targetDir -Force:$Force
- copy-item -Path "$moduleName.psd1" $targetDir -Force:$Force
- if ($BinarySourceDirectory) {
- copy-item ".\$BinarySourceDirectory" -Exclude 'System.*','Microsoft.*' -Destination $targetDir -Recurse -Force:$Force
- }
- }
- }
- }
- function Install-Prequisites {
- [CmdletBinding(SupportsShouldProcess=$true)]param (
- )
- $Args | % {
- invoke-expression $_
- }
- }
- function Publish-Module2 {
- [CmdletBinding(SupportsShouldProcess=$true)]param (
- $ModuleName,
- $BuildTargets,
- $BinarySourceDirectory,
- $OutputDirectory,
- [System.Version]$VersionIncrement = '0.0.0.1'
- )
- Install-Prequisites
- if ($VersionIncrement) {
- $currentVersion = Select-Json 'build.json' 'New-ModuleManifest.ModuleVersion'
- $currentVersion = Add-Version $currentVersion $VersionIncrement
- Set-Json 'build.json' 'New-ModuleManifest.ModuleVersion' $currentVersion
- }
- New-ModuleManifest
- $BuildTargets | % {
- Copy-Module -ModuleName $ModuleName -ComputerName $_ -BinarySourceDirectory $BinarySourceDirectory -Force
- }
- if (![string]::IsNullOrEmpty($OutputDirectory)) {
- Copy-Module -ModuleName $ModuleName -OutputDirectory $OutputDirectory -BinarySourceDirectory $BinarySourceDirectory -Force
- }
- }
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement