-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
118 lines (99 loc) · 2.47 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
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
package pipedream
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"strings"
"time"
"github.com/BurntSushi/toml"
)
const (
typeJS = "js"
typeCSS = "css"
typeImg = "img"
typeAudio = "audio"
typeVideos = "videos"
typeFonts = "fonts"
)
// Pipedream is the config for pipedream
type Pipedream struct {
In string `toml:"in"`
Out string `toml:"out"`
CDNURL string `toml:"cdn_url"`
NoCompile bool `toml:"no_compile"`
NoMinify bool `toml:"no_minify"`
NoHash bool `toml:"no_hash"`
NoCompress bool `toml:"no_compress"`
Executables
Manifest Manifest `toml:"-"`
}
// Executables are the compilers and minifiers used by the various file types
type Executables struct {
JS Exes `toml:"js"`
CSS Exes `toml:"css"`
Img Exes `toml:"img"`
Audio Exes `toml:"audio"`
Videos Exes `toml:"videos"`
Fonts Exes `toml:"fonts"`
}
// Exes holds the compilers and minifiers for each file type
type Exes struct {
Compilers map[string]Command `toml:"compilers"`
Minifier Command `toml:"minifier"`
}
// Command is an executable that can be run to consume input and produce output
// files.
type Command struct {
Cmd string `toml:"cmd"`
Args []string `toml:"args"`
Stdout bool `toml:"stdout"`
Stdin bool `toml:"stdin"`
}
// Manifest for compiled assets
type Manifest struct {
Files map[string]FileInfo `json:"files"`
Assets map[string]string `json:"assets"`
}
// FileInfo keeps various properties about a file
type FileInfo struct {
Digest string `json:"digest"`
MTime time.Time `json:"mtime"`
Size uint64 `json:"size"`
}
// New loads a configuration
func New(file string) (Pipedream, error) {
var pipedream Pipedream
_, err := toml.DecodeFile(file, &pipedream)
pipedream.CDNURL = strings.TrimRight(pipedream.CDNURL, "/")
return pipedream, err
}
// LoadManifest loads the manifest in p.OutPath/assets/manifest.json
func (p *Pipedream) LoadManifest() error {
b, err := ioutil.ReadFile(filepath.Join(p.Out, "assets", "manifest.json"))
if err != nil {
return err
}
if err = json.Unmarshal(b, &p.Manifest); err != nil {
return err
}
return nil
}
// exes returns the exe for typ
func (p *Pipedream) exes(typ string) (exes Exes, ok bool) {
switch typ {
case typeJS:
return p.JS, true
case typeCSS:
return p.CSS, true
case typeImg:
return p.Img, true
case typeAudio:
return p.Audio, true
case typeVideos:
return p.Videos, true
case typeFonts:
return p.Fonts, true
default:
return exes, false
}
}