-
Notifications
You must be signed in to change notification settings - Fork 45
/
watcher.js
69 lines (62 loc) · 1.48 KB
/
watcher.js
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
/** The component that watches the local synchronized folder.
*
* There are currently 2 implementations:
*
* - {@link module:core/local/atom/watcher|atom}
* - {@link module:core/local/chokidar/watcher|chokidar}
*
* @module core/local/watcher
* @see module:core/config~watcherType
* @flow
*/
const { AtomWatcher } = require('./atom/watcher')
const ChokidarWatcher = require('./chokidar/watcher')
/*::
import type { Config } from '../config'
import type { AtomEventsDispatcher } from './atom/dispatch'
import type { Pouch } from '../pouch'
import type Prep from '../prep'
import type EventEmitter from 'events'
import type { Ignore } from '../ignore'
import type { ChokidarEvent } from './chokidar/event'
import type { Checksumer } from './checksumer'
export interface Watcher {
checksumer: Checksumer,
running: Promise<*>,
start (): Promise<*>,
stop (force: ?bool): Promise<*>,
}
export type LocalWatcherOptions = {
config: Config,
events: EventEmitter,
ignore: Ignore,
onAtomEvents?: AtomEventsDispatcher,
pouch: Pouch,
prep: Prep
}
*/
function build(
{
config,
prep,
pouch,
events,
ignore,
onAtomEvents
} /*: LocalWatcherOptions */
) /*: Watcher */ {
const { syncPath, watcherType } = config
if (watcherType === 'atom') {
return new AtomWatcher({
config,
prep,
pouch,
events,
ignore,
onAtomEvents
})
} else {
return new ChokidarWatcher(syncPath, prep, pouch, events)
}
}
module.exports = { build }