Skip to content

Instantly share code, notes, and snippets.

@sayedihashimi
Created September 2, 2015 08:00
Show Gist options
  • Select an option

  • Save sayedihashimi/f10833014ddd4c766299 to your computer and use it in GitHub Desktop.

Select an option

Save sayedihashimi/f10833014ddd4c766299 to your computer and use it in GitHub Desktop.
function Get-ScriptDirectory{
split-path (((Get-Variable MyInvocation -Scope 1).Value).MyCommand.Path)
}
$scriptDir = ((Get-ScriptDirectory) + "\")
Add-Type -Path (Join-Path $scriptDir 'bin\Geoffry.Watch.dll')
$watcherdef = New-Object -TypeName 'Geoffry.Watch.WatchDefinition'
$watcherdef.GlobbingPattern = '**/*.css'
$watcherdef.RootDirectory = (Join-Path $scriptDir 'src\css')
'Using pattern [{0}] to watch folder [{1}]' -f ($watcherdef.GlobbingPattern), ($watcherdef.RootDirectory) | Write-Host
$timeout = [System.TimeSpan]::FromMilliseconds(500)
$watchertype = [Geoffry.Watch.Watcher]
Register-ObjectEvent -InputObject $watchertype -EventName Changed -Action { Write-Host 'changed';('changed {0}' -f [DateTime]::Now.ToLongTimeString())|Out-File M:\temp\foo-test.txt -Append }
[Geoffry.Watch.WatchDefinition[]]$watchlist = @($watcherdef)
$global:token = [Geoffry.Watch.Watcher]::Subscribe($timeout, $watchlist)
#[Geoffry.Watch.Watcher]::Cancel($token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment