-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmagefile.go
More file actions
134 lines (111 loc) · 2.82 KB
/
magefile.go
File metadata and controls
134 lines (111 loc) · 2.82 KB
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
//go:build mage
// +build mage
package main
import (
"flag"
"os"
"github.com/openimsdk/gomake/mageutil"
)
var Default = Build
var Aliases = map[string]any{
"buildcc": BuildWithCustomConfig,
"startcc": StartWithCustomConfig,
}
var (
customRootDir = "."
// customSrcDir = "work_cmd"
customSrcDir = "cmd"
customOutputDir = "_output"
customConfigDir = "config"
customToolsDir = "tools"
customExportProjectName = "gomake"
customExportBuildOpt *mageutil.BuildOptions
)
// Build support specifical binary build.
//
// Example: `mage build openim-api openim-rpc-user seq`
func Build() {
flag.Parse()
bin := flag.Args()
if len(bin) != 0 {
bin = bin[1:]
}
mageutil.WithSpinner("Building binaries...", func() {
mageutil.Build(bin, nil, nil)
})
}
func BuildWithCustomConfig() {
flag.Parse()
bin := flag.Args()
if len(bin) != 0 {
bin = bin[1:]
}
config := &mageutil.PathOptions{
RootDir: &customRootDir, // default is "."(current directory)
OutputDir: &customOutputDir, // default is "_output"
SrcDir: &customSrcDir, // default is "cmd"
ToolsDir: &customToolsDir, // default is "tools"
}
mageutil.WithSpinner("Building binaries with custom config...", func() {
mageutil.Build(bin, config, nil)
})
}
func Start() {
mageutil.InitForSSC()
err := setMaxOpenFiles()
if err != nil {
mageutil.PrintRed("setMaxOpenFiles failed " + err.Error())
os.Exit(1)
}
flag.Parse()
bin := flag.Args()
if len(bin) != 0 {
bin = bin[1:]
}
mageutil.WithSpinner("Starting tools and services...", func() {
mageutil.StartToolsAndServices(bin, nil)
})
}
func StartWithCustomConfig() {
mageutil.InitForSSC()
err := setMaxOpenFiles()
if err != nil {
mageutil.PrintRed("setMaxOpenFiles failed " + err.Error())
os.Exit(1)
}
flag.Parse()
bin := flag.Args()
if len(bin) != 0 {
bin = bin[1:]
}
config := &mageutil.PathOptions{
RootDir: &customRootDir, // default is "."(current directory)
OutputDir: &customOutputDir, // default is "_output"
ConfigDir: &customConfigDir, // default is "config"
}
mageutil.WithSpinner("Starting tools and services with custom config...", func() {
mageutil.StartToolsAndServices(bin, config)
})
}
func Stop() {
mageutil.WithSpinner("Checking service status...", mageutil.StopAndCheckBinaries)
}
func Check() {
mageutil.WithSpinner("Checking service status...", mageutil.CheckAndReportBinariesStatus)
}
func Protocol() {
mageutil.WithSpinnerE("Generating protocol artifacts...", mageutil.Protocol)
}
func Export() {
exportOpt := &mageutil.ExportOptions{
ProjectName: &customExportProjectName,
BuildOpt: customExportBuildOpt,
}
err := mageutil.WithSpinnerE("Exporting launcher archive...", func() error {
return mageutil.ExportMageLauncherArchived(nil, exportOpt)
})
if err != nil {
mageutil.PrintRed("export failed " + err.Error())
os.Exit(1)
}
}