-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (52 loc) · 1.11 KB
/
main.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
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"github.com/superp00t/etc/yo"
)
func osExt() string {
if os.Getenv("GOOS") == "windows" {
return ".exe"
}
if os.Getenv("GOOS") == "" && runtime.GOOS == "windows" {
return ".exe"
}
return ""
}
func getBuildOutput() string {
s := os.Args[1]
if strings.Contains(s, "/") {
spl := strings.Split(s, "/")
return spl[len(spl)-1] + osExt()
}
fl := strings.Split(s, ".")
return fl[0] + osExt()
}
func main() {
if len(os.Args) < 2 {
fmt.Println("nui-build <package or file>")
os.Exit(1)
}
args := []string{"build"}
flags := `-H=windowsgui -s -w`
args = append(args, "-ldflags", flags)
args = append(args, "-o", getBuildOutput(), os.Args[1])
yo.Spew(args)
c := exec.Command("go", args...)
c.Env = os.Environ()
c.Stdout = os.Stdout
c.Stdin = os.Stdin
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
yo.Fatal(err)
}
c = exec.Command("upx", getBuildOutput())
c.Env = os.Environ()
c.Stdout = os.Stdout
c.Stdin = os.Stdin
c.Stderr = os.Stderr
c.Run()
}