Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch command? #18

Closed
deevus opened this issue Jan 30, 2016 · 5 comments
Closed

Watch command? #18

deevus opened this issue Jan 30, 2016 · 5 comments

Comments

@deevus
Copy link

deevus commented Jan 30, 2016

I'm hoping to replace gulp and I think the only thing missing that I need is a "watch" command. I want to be able to give a list of files to watch, and a command to run with the intention of running webpack when scripts are updated.

Thoughts?

@nightroman
Copy link
Owner

I am not familiar with gulp and its watch command. I will google but it would be useful if you describe some specs it terms of Invoke-Build.

@nightroman
Copy link
Owner

A naive approach from the top of my head. A working example of FileSystemWatcher in PowerShell
is here. We configure it for required files and events and start it in a console which is kept running.
From the appropriate event handler we call Invoke-Build with specified tasks and parameters, as usual.

@nightroman
Copy link
Owner

Just to be clear, the above does not need anything extra in Invoke-Build. It
is just a PowerShell script which uses Invoke-Build as it is.

It is too simple and needs some work, depending on scenarios. For example, one
may want to wait for multiple changes to complete before triggering a build.
Or maybe it is fine that it is called for each event but the file system may
send multiple events for the same file (from the remarks from the link).

So a properly designed script is needed. But it is still not directly related
to Invoked-Build. If you are thinking of some sort of integration then some
specs are definitely needed. I do not have any practical use cases on my own.

@nightroman
Copy link
Owner

The script uses the Action parameter. Yet another approach is possible and
may be simpler because processing is done not by PowerShell jobs. We just
subscribe to events without actions

Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated
Register-ObjectEvent $fsw Deleted -SourceIdentifier FileDeleted
Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged

Then in the main script we use Wait-Event or check for events periodically by
Get-Event, process them and remove by Remove-Event. Then repeat
waiting for events.

@nightroman
Copy link
Owner

I created the tool Watch-Directory.ps1. It is designed for any command processing changes specified as a parameter, normally a script block. In your case this command may call Invoke-Build. The tool is not final and not fully tested but it seems to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants