-
Notifications
You must be signed in to change notification settings - Fork 14
/
api.w
60 lines (46 loc) · 1.55 KB
/
api.w
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
bring cloud;
bring fs;
bring "./utils.w" as utils;
pub struct AppProps {
// The path to the React app root folder - can be absolute or relative to the wing folder.
projectPath: str;
// A port to start a local build of the React app on.
localPort: num?;
// The path to the React app build folder - relative to the `projectPath`.
buildDir: str?;
// A command for starting React app locally.
startCommand: str?;
// A command for building the React app.
buildCommand: str?;
// In sim, if `true` - will use the start command, and if `false` - the build command.
useBuildCommand: bool?;
// The website's custom domain object.
domain: cloud.Domain?;
}
pub interface IApp {
getUrl(): str;
addEnvironment(key: str, value: str): void;
}
pub class AppBase {
protected props: AppProps;
protected path: str;
protected env: MutMap<str>;
protected startCommand: str;
protected buildCommand: str;
protected buildDir: str;
new(props: AppProps) {
this.path = fs.absolute(nodeof(this).app.entrypointDir, props.projectPath);
if !fs.exists(this.path) {
throw "{this.path} not exists";
}
this.props = props;
this.env = {};
this.buildDir = fs.join(this.path, this.props.buildDir ?? "./build");
this.startCommand = this.props.startCommand ?? "npm run start";
this.buildCommand = this.props.buildCommand ?? "npm run build";
}
// Adding a key-value pair that can be accessible later via the `window.wingEnv` object in the react code.
pub addEnvironment(key: str, value: str) {
this.env.set(key, value);
}
}