This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (74 loc) · 1.67 KB
/
main.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
package main
import (
"flag"
"fmt"
"github.com/exherb/Dashing"
"io"
"net/http"
"os"
"path/filepath"
)
func downloadUrlsToDir(urls []string, dirpath string) error {
if _, err := os.Stat(dirpath); os.IsNotExist(err) {
os.Mkdir(dirpath, os.ModePerm)
}
for _, url := range urls {
filename := filepath.Base(url)
toFilepath := filepath.Join(dirpath, filename)
if _, err := os.Stat(toFilepath); !os.IsNotExist(err) {
continue
}
fmt.Printf("\tdownloading %s ...\n", url)
toFile, err := os.Create(toFilepath)
if err != nil {
return err
}
defer toFile.Close()
response, err := http.Get(url)
if err != nil {
return err
}
defer response.Body.Close()
if _, err := io.Copy(toFile, response.Body); err != nil {
return err
}
}
return nil
}
func restoreAssets(dirpath string, resource string) {
resourcePath := filepath.Join(dirpath, resource)
if _, err := os.Stat(resourcePath); os.IsNotExist(err) {
dashing.RestoreAssets(dirpath, resource)
}
}
func prepareDependencies(dirpath string) {
restoreAssets(dirpath, "dashboards")
restoreAssets(dirpath, "jobs")
restoreAssets(dirpath, "src")
restoreAssets(dirpath, "public")
restoreAssets(dirpath, "config.json")
restoreAssets(dirpath, "package.json")
restoreAssets(dirpath, "webpack.config.js")
restoreAssets(dirpath, "server.go")
}
func build(dirpath string) error {
prepareDependencies(dirpath)
return nil
}
func main() {
flag.Parse()
action := flag.Arg(0)
dirpath := flag.Arg(1)
dirpath, _ = filepath.Abs(dirpath)
fmt.Printf("%s ...\n", action)
var err error
switch action {
case "new":
err = build(dirpath)
}
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("done.\n")
}
}