提交 428b30f3 编写于 作者: yanghye's avatar yanghye

energy command-line tools: build linux

上级 8fe11f2d
......@@ -13,8 +13,32 @@
package build
import "github.com/energye/energy/v2/cmd/internal/command"
import (
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/project"
"github.com/energye/energy/v2/cmd/internal/term"
toolsCommand "github.com/energye/golcl/tools/command"
)
func build(c *command.Config) error {
// 读取项目配置文件 energy.json 在main函数目录
if proj, err := project.NewProject(c.Build.Path); err != nil {
return err
} else {
// go build
cmd := toolsCommand.NewCMD()
cmd.Dir = proj.ProjectPath
cmd.IsPrint = false
term.Section.Println("Building", proj.OutputFilename)
var args = []string{"build", "-ldflags", "-s -w", "-o", proj.OutputFilename}
cmd.Command("go", args...)
cmd.Command("strip", proj.OutputFilename)
// upx
cmd.Close()
if err == nil {
term.Section.Println("Build Successfully")
}
}
return nil
}
......@@ -13,8 +13,42 @@
package build
import "github.com/energye/energy/v2/cmd/internal/command"
import (
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/project"
"github.com/energye/energy/v2/cmd/internal/term"
"github.com/energye/energy/v2/cmd/internal/tools"
toolsCommand "github.com/energye/golcl/tools/command"
"strings"
)
func build(c *command.Config) error {
// 读取项目配置文件 energy.json 在main函数目录
if proj, err := project.NewProject(c.Build.Path); err != nil {
return err
} else {
// go build
cmd := toolsCommand.NewCMD()
cmd.Dir = proj.ProjectPath
cmd.IsPrint = false
term.Section.Println("Building", proj.OutputFilename)
var args = []string{"build", "-ldflags", "-s -w", "-o", proj.OutputFilename}
cmd.Command("go", args...)
cmd.Command("strip", proj.OutputFilename)
// upx
if c.Build.Upx && tools.CommandExists("upx") {
term.Section.Println("Upx compression")
args = []string{"--best", "--no-color", "--no-progress", proj.OutputFilename}
if c.Build.UpxFlag != "" {
args = strings.Split(c.Build.UpxFlag, " ")
args = append(args, proj.OutputFilename)
}
cmd.Command("upx", args...)
}
cmd.Close()
if err == nil {
term.Section.Println("Build Successfully")
}
}
return nil
}
......@@ -3,11 +3,14 @@ module github.com/energye/energy/v2
go 1.18
require (
atomicgo.dev/cursor v0.2.0
atomicgo.dev/keyboard v0.2.9
github.com/energye/golcl v1.0.4
github.com/energye/liblclbinres v1.0.3
github.com/godbus/dbus/v5 v5.1.0
github.com/jessevdk/go-flags v1.5.0
github.com/json-iterator/go v1.1.12
github.com/lithammer/fuzzysearch v1.1.8
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pterm/pterm v0.12.66
github.com/tevino/abool v0.0.0-20220530134649-2bfc934cb23c
......@@ -16,12 +19,9 @@ require (
)
require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册