Home Manual Reference Source Test
import {WatchTask} from 'atscm/src/tasks/watch.js'
public class | source

WatchTask

The task executed when running atscm watch.

Test:

Constructor Summary

Public Constructor
public

Creates a new watch task instance.

Member Summary

Public Members
public

The Browsersync instance used.

public get

The directory to watch.

Private Members
private
private

Timestamp of the last pull

private

The NodeId of the last push.

private

If the task is currently pulling.

private

If the task is currently pushing.

Method Summary

Public Methods
public

Handles a file change.

public

Handles an atvise server change.

public
public

printTaskError(contextMessage: string, err: Error)

Prints an error that happened while handling a change.

public

run(options: Object): Promise<{serverwatcher: Watcher, fileWatcher: sane~Watcher}, Error>

Starts the file and server watchers, initializes Browsersync and registers change event handlers.

public

Starts a file watcher for the directory WatchTask#directoryToWatch.

public

Starts a watcher that watches the atvise server for changes.

Private Methods
private

Waits for a watcher (which can actually be any kind of events~Emitter) to emit a "ready" event.

Public Constructors

public constructor() source

Creates a new watch task instance. Also creates a new Browsersync instance.

Test:

Public Members

public browserSyncInstance: events~Emitter source

The Browsersync instance used.

public get directoryToWatch: string source

The directory to watch.

Private Members

private _handlingChange: boolean source

private _lastPull: number source

Timestamp of the last pull

private _lastPushed: NodeId source

The NodeId of the last push.

private _pulling: boolean source

If the task is currently pulling.

private _pushing: boolean source

If the task is currently pushing.

Public Methods

public handleFileChange(path: string, root: string): Promise<boolean> source

Handles a file change.

Params:

NameTypeAttributeDescription
path string

The path of the file that changed.

root string

The root of the file that changed.

Return:

Promise<boolean>

Resolved with true if the change triggered a push operation, with false otherwise.

Test:

public handleServerChange(readResult: ReadStream.ReadResult): Promise<boolean> source

Handles an atvise server change.

Params:

NameTypeAttributeDescription
readResult ReadStream.ReadResult

The read result of the modification.

Return:

Promise<boolean>

Resolved with true if the change triggered a pull operation, with false otherwise.

Test:

public initBrowserSync(options: Object) source

Initializes WatchTask#browserSyncInstance.

Params:

NameTypeAttributeDescription
options Object

The options to pass to browsersync.

Test:

See:

public printTaskError(contextMessage: string, err: Error) source

Prints an error that happened while handling a change.

Params:

NameTypeAttributeDescription
contextMessage string

Describes the currently run action.

err Error

The error that occured.

public run(options: Object): Promise<{serverwatcher: Watcher, fileWatcher: sane~Watcher}, Error> source

Starts the file and server watchers, initializes Browsersync and registers change event handlers.

Params:

NameTypeAttributeDescription
options Object
  • optional

The options to pass to browsersync.

options.open boolean
  • optional
  • default: true

If the browser should be opened once browsersync is up.

Return:

Promise<{serverwatcher: Watcher, fileWatcher: sane~Watcher}, Error>

Fulfilled once all watchers are set up and Browsersync was initialized.

Test:

public startFileWatcher(): Promise<sane~Watcher, Error> source

Starts a file watcher for the directory WatchTask#directoryToWatch.

Return:

Promise<sane~Watcher, Error>

Fulfilled with the file watcher once it is ready or rejected with the error that occurred while starting the watcher.

Test:

public startServerWatcher(): Promise<Watcher, Error> source

Starts a watcher that watches the atvise server for changes.

Return:

Promise<Watcher, Error>

Fulfilled with the server watcher once it is ready or rejected with the error that occurred while starting the watcher.

Test:

Private Methods

private _waitForWatcher(watcher: events~Emitter): Promise<events~Emitter, Error> source

Waits for a watcher (which can actually be any kind of events~Emitter) to emit a "ready" event.

Params:

NameTypeAttributeDescription
watcher events~Emitter

The watcher to wait for.

Return:

Promise<events~Emitter, Error>

Fulfilled with the set up watcher or rejected with the watcher error that occurred while waiting for it to get ready.

Test: