forked from shaoshing/train
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
63 lines (54 loc) · 1.38 KB
/
config.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
package train
import (
"fmt"
"os"
)
type config struct {
// The folder that contains JavaScript and StyleSheet files. It will use "assets" by default.
AssetsPath string
// Path to output assets compiled
PublicPath string
AssetsUrl string
// Show verbose logs. For example, SASS warnings.
Verbose bool
// Whether to serve bundled assets in development mode. This option is ignored
// when in production mode, that is, the ./public/assets folder exists.
BundleAssets bool
// When set to DEVELOPMENT_MODE, assets are read from ./assets
// When set to PRODUCTION_MODE, assets are read from ./public/assets
// It is set to PRODUCTION_MODE automatically if the ./public/assets exist.
Mode string
SASS sassConfig
}
const (
DEVELOPMENT_MODE = "development"
PRODUCTION_MODE = "production"
VERSION = "0.1.1"
)
type sassConfig struct {
DebugInfo bool
LineNumbers bool
}
var Config = config{
AssetsPath: "assets",
AssetsUrl: "/assets/",
PublicPath: "public",
Mode: DEVELOPMENT_MODE,
}
func init() {
if HasPublicAssets() {
Config.Mode = PRODUCTION_MODE
}
if IsInProduction() {
if err := LoadManifestInfo(); err != nil {
fmt.Println("== Could not load manifest from public/assets/")
}
}
}
func IsInProduction() bool {
return Config.Mode == PRODUCTION_MODE
}
func HasPublicAssets() bool {
_, err := os.Stat("public" + Config.AssetsUrl)
return err == nil
}