/
index.js
59 lines (49 loc) · 1.23 KB
/
index.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
// @flow
export type Path = string
export type Code = string
export type EventType = 'add' | 'change' | 'unlink'
export type Only = EventType[]
export type AnymatchPath = RegExp | string | (RegExp | string)[]
export type HandlerOpts = {
eventPath: Path,
filename: Path,
// eslint-disable-next-line no-use-before-define
plugin?: Plugin,
}
type Meta = {
handlerName: string,
pluginName?: string,
}
export type Handler = (
code: Code,
opts: HandlerOpts
) => { code: Code, meta: Meta }
export type Plugin = {|
test: RegExp | string | string[],
plugin?: *,
handler?: Handler,
only?: Only,
input?: Path,
output?: Path,
|}
export type Template = {|
test: RegExp | string | string[],
input: Path,
output?: Path,
|}
export type AfterHook = (code: Code, path: Path) => Code
/**
* @see https://github.com/paulmillr/chokidar
* @see https://github.com/es128/anymatch
*/
export type Config = {
watch: Path, // file, dir, glob, or array
plugins?: Plugin[],
templatesDir?: string,
templates?: Template[],
afterHooks?: AfterHook[],
prettier: boolean,
handlerMapper?: { [extensions: string]: Handler },
ignored?: AnymatchPath, // file, dir, glob, regexp, or array
}
export type HandlerType = 'S2S' | 'TEMPLATE'