-
Notifications
You must be signed in to change notification settings - Fork 20
/
options.ts
59 lines (52 loc) · 1.47 KB
/
options.ts
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
/**
* SSR 的输入参数
*
* SanProject#compileToSource() 和 compileToRenderer() 的输入参数为 CompileInput
* 这里定义了 CompileInput 相关的类型,以及对应的 Type Guards。
*/
import { ComponentConstructor } from 'san'
/**
* 文件尚未存在,但其内容已经在内存里的情况。比如 Webpack 编译时。
*/
export interface FileDescriptor {
/**
* 文件路径
*/
filePath: string
/**
* 文件内容
*/
fileContent: string
}
/**
* .san 文件描述
*
* - 单独给 script 文件内容、template 文件内容的情况。
* - 一个 script 内只有一个组件。
*/
export interface SanFileDescriptor {
/**
* 文件路径
*/
filePath: string
/**
* 脚本内容
*/
scriptContent: string
/**
* 模板内容
*/
templateContent: string
}
export type ComponentClass = ComponentConstructor<{}, any>
export type FilePath = string
export type CompileInput = SanFileDescriptor | FileDescriptor | FilePath | ComponentClass
export function isFileDescriptor (input: CompileInput): input is FileDescriptor {
return typeof input['filePath'] === 'string' && typeof input['fileContent'] === 'string'
}
export function isComponentClass (input: CompileInput): input is ComponentClass {
return typeof input === 'function'
}
export function isSanFileDescriptor (input: CompileInput): input is SanFileDescriptor {
return typeof input['templateContent'] === 'string'
}