forked from JordanKnott/taskcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
94 lines (78 loc) · 1.94 KB
/
magefile.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
//+build mage
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/shurcooL/vfsgen"
)
var Aliases = map[string]interface{}{
"s": Backend.Schema,
"up": Docker.Up,
}
type Frontend mg.Namespace
func (Frontend) Install() error {
return sh.RunV("yarn", "--cwd", "frontend", "install")
}
func (Frontend) Build() error {
return sh.RunV("yarn", "--cwd", "frontend", "build")
}
type Backend mg.Namespace
func (Backend) GenFrontend() error {
var fs http.FileSystem = http.Dir("frontend/build")
err := vfsgen.Generate(fs, vfsgen.Options{
Filename: "internal/frontend/frontend_generated.go",
PackageName: "frontend",
VariableName: "Frontend",
})
if err != nil {
panic(err)
}
return nil
}
func (Backend) Build() error {
fmt.Println("compiling binary dist/citadel")
return sh.Run("go", "build", "-o", "dist/citadel", "cmd/citadel/main.go")
}
func (Backend) Schema() error {
files, err := ioutil.ReadDir("internal/graph/schema/")
if err != nil {
panic(err)
}
var schema strings.Builder
for _, file := range files {
filename := "internal/graph/schema/" + file.Name()
fmt.Println(filename)
f, err := os.Open(filename)
if err != nil {
panic(err)
}
content, err := ioutil.ReadAll(f)
if err != nil {
panic(err)
}
fmt.Fprintln(&schema, string(content))
}
err = ioutil.WriteFile("internal/graph/schema.graphqls", []byte(schema.String()), os.FileMode(0755))
if err != nil {
panic(err)
}
return sh.Run("gqlgen")
}
func Install() {
mg.SerialDeps(Frontend.Install)
}
func Build() {
mg.SerialDeps(Frontend.Build, Backend.GenFrontend, Backend.Build)
}
type Docker mg.Namespace
func (Docker) Up() error {
return sh.RunV("docker-compose", "-p", "citadel", "up", "-d")
}
func (Docker) Migrate() error {
return sh.RunV("docker-compose", "-p", "citadel", "-f", "docker-compose.yml", "-f", "docker-compose.migrate.yml", "run", "--rm", "migrate")
}