This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
167 lines (148 loc) · 3.84 KB
/
types.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { WalkOptions } from "./std.ts";
import Controller from "./router/controller.ts";
import { ComponentType, Context } from "./deps.ts";
import Module from "./modules/module.ts";
// TODO: Document types
type HTTPMethod =
| "DELETE"
| "GET"
| "HEAD"
| "OPTIONS"
| "PATCH"
| "POST"
| "PUT";
export type Middleware = Array<
(ctx: Context, next: () => Promise<void>) => Promise<void>
>;
export interface WebRoute {
page: string;
ssg?: boolean;
path: string;
controller?: string;
method?: string;
}
export interface WebRoutes {
middleware: Middleware;
routes: WebRoute[];
}
export interface APIRoute {
method: string;
controller: string;
httpMethod: HTTPMethod;
path: string;
}
export interface APIRoutes {
middleware: Middleware;
routes: APIRoute[];
}
export interface WebModule {
page: ComponentType<any>;
controller: new () => Controller;
}
export type APIModules = Record<string, new () => Controller>;
export type WebModules = Record<string, WebModule>;
export type Routes = {
api: APIRoutes;
web: WebRoutes;
};
export interface Modules {
[key: string]: {
module: string;
html?: string;
};
}
/**
* The options for **SSR**.
*/
export interface SSROptions {
/** The fallback html **dynamic routes** (default is '**_fallback.html**'). */
fallback?: string;
/** A list of RegExp for paths to use **SSR**. */
include?: RegExp[];
/** A list of RegExp for paths to skip **SSR**. */
exclude?: RegExp[];
/** A list of paths for **dynamic routes** in **SSR**. */
staticPaths?: string[];
}
export interface CompilerOptions {
buildDir?: string;
rootDir?: string;
reactLocalPath?: string;
reactDOMLocalPath?: string;
isBuilding?: boolean;
reload?: boolean;
}
/**
* A compiler plugin for **Tails.js** application. The transform
* methods are invoked just before transpile & just after transpiling.
*/
export interface CompilerPlugin {
/** `name` gives the plugin a name. */
name?: string;
/** `test` matches the import url. */
test: RegExp;
/** `acceptHMR` accepts the HMR. */
acceptHMR?: boolean;
/**
* Merged with default `walkOptions` when transpiling. Used
* to include files such as css when walking the user's
* application is being transpiled.
* Note: Make sure to transfrom the source content
* before transpiling occurs (preTransform).
*/
walkOptions?: WalkOptions;
/**
* `resolve` transforms the filename & import url. This is invoked
* before transpiling to ensure unsupported imports,
* such as css imports, are not transpiled.
*/
resolve?(url: string, opts: CompilerOptions): Promise<string> | string;
/**
* Handles transforming the source content before transpiling.
*/
transform?(
{ pathname, content }: { pathname: string; content: string },
opts: CompilerOptions,
): Promise<string>;
}
export interface TranspiledModules {
modules: Record<string, Deno.TranspileOnlyResult>;
plugins: Record<string, string>;
}
export interface ManifestModule {
modulePath: string;
htmlPath?: string;
}
export interface Manifest {
modules: {
[key: string]: ManifestModule;
};
reactLocalPaths: {
reactPath: string;
reactDomPath: string;
reactDomServerPath: string;
};
}
/**
* TODO: Remove?
* A plugin for **Tails.js** application.
*/
export interface Plugin {
/** `name` gives the plugin a name. */
name?: string;
/** `test` matches the import url. */
test: RegExp;
/** `acceptHMR` accepts the HMR. */
acceptHMR?: boolean;
/** `resolve` resolves the import url, if the `external` returned the compilation will skip the import url. */
resolve?(url: string): { url: string; external?: boolean };
/** `transform` transforms the source content. */
transform?(
content: Uint8Array,
url: string,
): Promise<{
code: string;
map?: string;
loader?: "js" | "ts" | "css" | "markdown";
}>;
}