-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmagefile.go
95 lines (74 loc) · 2.12 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
95
//go:build mage
// +build mage
package main
import (
"time"
_ "github.com/joho/godotenv/autoload" // Load .env file automatically
"github.com/fatih/color"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// mg contains helpful utility functions, like Deps
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
// Run runs the application with environment variables
func Run() error {
// clean up go build cache
color.Yellow("Cleaning up go build cache...")
sh.RunV("go", "clean", "-cache")
// run the application
color.Cyan("Starting the application...")
return sh.RunV("go", "run", "./cmd/app/")
}
// MigrateUp runs the database migrations up
func MigrateUp() error {
color.Cyan("Running database migrations...")
return sh.RunV("go", "run", "./cmd/migrate/main.go")
}
// Up runs the application and the database migrations up
func Up() error {
color.Cyan("Starting the database...")
if err := sh.RunV("docker-compose", "up", "-d"); err != nil {
return err
}
color.Yellow("Waiting for the database to start...")
time.Sleep(5 * time.Second)
if err := MigrateUp(); err != nil {
return err
}
return Run()
}
// Down stops the application and the database
func Down() error {
color.Yellow("Stopping the database and removing all data...")
return sh.RunV("docker-compose", "down", "--volumes", "--rmi=local")
}
// Build builds the CLI application
func Build() error {
color.Cyan("Building the CLI application...")
return sh.RunV("go", "build", "-o", "./bin/cli", "./cmd/cli/")
}
// Client namespace
type Client mg.Namespace
// Create a new client
func (Client) Create(userID, domain, isPublic string) error {
color.Cyan("Creating a new client...")
return sh.RunV(
"go", "run", "./cmd/cli/", "new-client",
"--user_id="+userID,
"--domain="+domain,
"--public="+isPublic,
)
}
// User namespace
type User mg.Namespace
// Create a new user
func (User) Create(email, password string) error {
color.Cyan("Creating a new user...")
return sh.RunV(
"go", "run", "./cmd/cli/", "new-user",
"--email="+email,
"--password="+password,
)
}