This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
generated from fallion/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mage.go
134 lines (91 loc) · 2.3 KB
/
mage.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//+build mage
package main
import (
"fmt"
"os"
"github.com/aevea/magefiles"
"github.com/go-git/go-git/v5"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
func Install() error {
dependencies := []string{
"github.com/aevea/oto-tools",
"github.com/pacedotdev/oto",
}
return magefiles.Install(dependencies)
}
func Test() error {
return magefiles.Test()
}
func GoModTidy() error {
return magefiles.GoModTidy()
}
type Build mg.Namespace
func (Build) Server() error {
var args []string
args = append(args, "-template", "./templates/oto/server.go.plush")
args = append(args, "-out", "./api/generated/oto.gen.go")
args = append(args, "-ignore", "Ignorer")
args = append(args, "-pkg", "generated")
args = append(args, "./api/definitions")
return sh.RunV("oto", args...)
}
func (Build) Client() error {
var args []string
args = append(args, "-template", "./templates/oto/client.js.plush")
args = append(args, "-out", "./webapp/src/services/client.js")
args = append(args, "-ignore", "Ignorer")
args = append(args, "./api/definitions")
return sh.RunV("oto", args...)
}
type WebApp mg.Namespace
func (WebApp) Dev() error {
return sh.RunV("npm", "run", "--prefix", "./webapp", "dev")
}
func (WebApp) Install() error {
return sh.RunV("npm", "install", "--prefix", "./webapp")
}
func PublishClient() error {
err := sh.RunV("oto-tools", "generate",
"--package-name", "@aevea/knit",
"--oto-template", "./templates/oto/client.js.plush",
"--oto-definitions", "./api/definitions")
if err != nil {
return err
}
token := os.Getenv("GITHUB_TOKEN")
return sh.RunV("oto-tools", "publish-npm", "--token", token, "--registry", "github", "--owner", "aevea")
}
// VerifyGeneration makes sure that all files are generated and merged before merging to master.
func VerifyGeneration() error {
err := Install()
if err != nil {
return err
}
build := Build{}
err = build.Server()
if err != nil {
return err
}
err = build.Client()
if err != nil {
return err
}
gitRepo, err := git.PlainOpen(".")
if err != nil {
return err
}
worktree, err := gitRepo.Worktree()
if err != nil {
return err
}
status, err := worktree.Status()
if err != nil {
return err
}
if !status.IsClean() {
return fmt.Errorf("git status is not clean: \n%s", status.String())
}
return nil
}