2020-07-05 01:02:57 +02:00
|
|
|
//+build mage
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2020-07-16 01:20:08 +02:00
|
|
|
"net/http"
|
2020-07-05 01:02:57 +02:00
|
|
|
"os"
|
|
|
|
"strings"
|
2020-07-17 05:58:46 +02:00
|
|
|
|
|
|
|
"github.com/magefile/mage/mg"
|
|
|
|
"github.com/magefile/mage/sh"
|
|
|
|
"github.com/shurcooL/vfsgen"
|
2020-07-05 01:02:57 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var Aliases = map[string]interface{}{
|
2020-07-17 05:58:46 +02:00
|
|
|
"s": Backend.Schema,
|
|
|
|
}
|
|
|
|
|
|
|
|
type Frontend mg.Namespace
|
|
|
|
|
|
|
|
func (Frontend) Install() error {
|
|
|
|
return sh.Run("yarn", "install", "--cwd", "frontend")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Frontend) Build() error {
|
|
|
|
return sh.Run("yarn", "build", "--cwd", "frontend")
|
2020-07-05 01:02:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 05:58:46 +02:00
|
|
|
type Backend mg.Namespace
|
|
|
|
|
|
|
|
func (Backend) GenFrontend() error {
|
2020-07-16 01:20:08 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-17 05:58:46 +02:00
|
|
|
func (Backend) Build() error {
|
|
|
|
return sh.Run("go", "build", "-o", "dist/citadel", "cmd/citadel/main.go")
|
|
|
|
}
|
2020-07-05 01:02:57 +02:00
|
|
|
|
2020-07-17 05:58:46 +02:00
|
|
|
func (Backend) Schema() error {
|
2020-07-12 09:06:11 +02:00
|
|
|
files, err := ioutil.ReadDir("internal/graph/schema/")
|
2020-07-05 01:02:57 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
var schema strings.Builder
|
|
|
|
for _, file := range files {
|
2020-07-12 09:06:11 +02:00
|
|
|
filename := "internal/graph/schema/" + file.Name()
|
2020-07-05 01:02:57 +02:00
|
|
|
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))
|
|
|
|
}
|
2020-07-12 09:06:11 +02:00
|
|
|
err = ioutil.WriteFile("internal/graph/schema.graphqls", []byte(schema.String()), os.FileMode(0755))
|
2020-07-05 01:02:57 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return sh.Run("gqlgen")
|
|
|
|
}
|
2020-07-17 05:58:46 +02:00
|
|
|
|
|
|
|
func Build() {
|
|
|
|
mg.SerialDeps(Frontend.Install, Frontend.Build, Backend.GenFrontend, Backend.Build)
|
|
|
|
}
|