-
Notifications
You must be signed in to change notification settings - Fork 303
/
web.go
104 lines (82 loc) · 2.28 KB
/
web.go
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
package model
import (
"flag"
"fmt"
"net/url"
"github.com/spf13/pflag"
)
// Web version of the form vA.B.C, where A, B, and C are integers
// Used for fetching web assets
type WebVersion string
// Web version of the form aaaaaaa where a is a hex letter
// Used for fetching web assets
type WebSHA string
// Mode for developing Tilt web UX.
//
// Currently controls whether we use production asset bundles (JS/CSS)
// or local hot-reloaded asset bundles.
type WebMode string
const (
// By default, we serve the js locally in dev builds and from prod in released
// builds.
DefaultWebMode WebMode = "default"
// Local webpack server
LocalWebMode WebMode = "local"
// Generic prod build; uses embedded if available otherwise cloud
ProdWebMode WebMode = "prod"
// Production build embedded assets
EmbeddedWebMode WebMode = "embedded"
// Production build assets from cloud bucket
CloudWebMode WebMode = "cloud"
// Precompiled with `make build-js`. This is an experimental mode
// we're playing around with to avoid the cost of webpack startup.
PrecompiledWebMode WebMode = "precompiled"
)
func (m *WebMode) String() string {
return string(*m)
}
func (m *WebMode) Set(v string) error {
switch v {
case string(DefaultWebMode):
*m = DefaultWebMode
case string(PrecompiledWebMode):
*m = PrecompiledWebMode
case string(LocalWebMode):
*m = LocalWebMode
case string(ProdWebMode):
*m = ProdWebMode
case string(EmbeddedWebMode):
*m = EmbeddedWebMode
case string(CloudWebMode):
*m = CloudWebMode
default:
return UnrecognizedWebModeError(v)
}
return nil
}
func (m *WebMode) Type() string {
return "WebMode"
}
func (m WebMode) IsProd() bool {
return m == ProdWebMode || m == EmbeddedWebMode || m == CloudWebMode
}
func UnrecognizedWebModeError(v string) error {
return fmt.Errorf("Unrecognized web mode: %s. Allowed values: %s", v, []WebMode{
DefaultWebMode, LocalWebMode, ProdWebMode, EmbeddedWebMode, CloudWebMode, PrecompiledWebMode,
})
}
var emptyWebMode = WebMode("")
var _ flag.Value = &emptyWebMode
var _ pflag.Value = &emptyWebMode
const DefaultWebPort = 10350
type WebHost string
type WebPort int
type WebDevPort int
type WebURL url.URL
func (u WebURL) String() string {
url := (*url.URL)(&u)
return url.String()
}
func (u WebURL) Empty() bool {
return WebURL{} == u
}