-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathupdate-modules.ps1
75 lines (63 loc) · 2.89 KB
/
update-modules.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
# [azure.datafactory.tools - ver.0.97.0](https://www.powershellgallery.com/packages/azure.datafactory.tools/0.97.0)
# [Az.DataFactory - ver.1.16.6](https://www.powershellgallery.com/packages/Az.DataFactory/1.16.6)
# [Az.Accounts - ver.2.5.3](https://www.powershellgallery.com/packages/Az.Accounts/2.5.3)
# [Az.Resources - ver.4.3.1](https://www.powershellgallery.com/packages/Az.Resources/4.3.1)
$ErrorActionPreference = 'Stop'
$target = 'd:\modules'
Remove-Item -Path "$target\*" -Force
function Download-Module {
param ([String] $m, [String]$target, $reqVer)
update-module $m -Force -RequiredVersion $reqVer
$list = get-module $m -ListAvailable
$mod = $list[0]
$folder = Split-Path $mod.Path -Parent
mkdir "$target`\$m"
Copy-Item -Path "$folder\*" -Destination "$target`\$m" -Recurse
$mod
}
function Update-ModuleInPlace {
param ([String] $m, [String[]]$tasks)
$targetPath = (.\Get-RootPath.ps1)
$src = Join-Path $target $m
foreach ($t in $tasks) {
if (!$t.EndsWith('V1') -and !$t.EndsWith('V2') -and !$t.EndsWith('V1*') -and !$t.EndsWith('V2*')) { Write-Error "Task must ends with V1/2[*]"}
$short = $t.EndsWith('*')
$tv = $t.Replace('*', '')
$t = $tv.Substring(0, $tv.Length - 2)
$dst = "$targetPath\$t\$tv\ps_modules"
Write-Host "Module: $src"
Write-Host "- copy to: $dst ..."
Copy-Item -Path $src -Destination $dst -Recurse -Force
if ($short) {
$file = "$dst\$m\$m.psm1"
Write-Host "- modifying file: $file ..."
$lines = Get-Content -Path $file -Encoding utf8
$sb = [System.Text.StringBuilder]::new()
$commentActive = $false
foreach ($line in $lines) {
if ($line.StartsWith('$moduleName = ')) { $commentActive = $true }
if ($commentActive) { $line = "# $line" }
$sb.AppendLine($line) | Out-Null
}
$sb.ToString() | Set-Content -Path $file
}
}
}
# Downloading modules
$m = 'azure.datafactory.tools'; Download-Module -m $m -target $target
$m = 'Az.DataFactory'; Download-Module -m $m -target $target #-reqVer '1.16.13'
$m = 'Az.Accounts'; Download-Module -m $m -target $target #-reqVer '2.12.1'
$m = 'Az.Resources'; Download-Module -m $m -target $target #-reqVer '6.5.3'
# Updating modules in 'azure.datafactory.devops'
$m = 'azure.datafactory.tools';
$tasks = @('buildDataFactoryTaskV1*', 'deployAdfFromArmTaskV1*', 'deployDataFactoryTaskV2', 'testLinkedServiceTaskV2*')
Update-ModuleInPlace $m $tasks
$m = 'Az.DataFactory';
$tasks = @('deployDataFactoryTaskV2')
Update-ModuleInPlace $m $tasks
# $m = 'Az.Accounts';
# $tasks = @('deployDataFactoryTaskV1', 'testLinkedServiceTaskV1')
# Update-ModuleInPlace $m $tasks
# $m = 'Az.Resources';
# $tasks = @('deployDataFactoryTaskV1', 'testLinkedServiceTaskV1')
# Update-ModuleInPlace $m $tasks