-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.ps1
52 lines (40 loc) · 1.41 KB
/
dev.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
Function Build {
Clear-Host
az deployment sub create `
--location 'west europe' `
--template-file '.\example\containerApps\environment.bicep' `
--parameters '.\example\containerApps\params\environment.dev.bicepparam' `
--what-if
Write-Host 'Done' -ForegroundColor green
}
Function Watch {
$global:FileChanged = $false
$folder = "$pwd"
$filter = "*.bicep"
Write-Host $folder
$watcher = New-Object System.IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true
EnableRaisingEvents = $true
}
$action = {
$global:FileChanged = $true
}
Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
Register-ObjectEvent $watcher "Deleted" -Action $action
Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true){
while ($global:FileChanged -eq $false){
# We need this to block the IO thread until there is something to run
# so the script doesn't finish. If we call the action directly from
# the event it won't be able to write to the console
Start-Sleep -Milliseconds 100
}
# a file has changed, run our stuff on the I/O thread so we can see the output
Build
# reset and go again
$global:FileChanged = $false
}
}
Build
Watch