mirror of
https://gitee.com/energye/energy.git
synced 2024-12-04 20:58:21 +08:00
energy-command-line, energy init . 初始化应用
This commit is contained in:
parent
8dfec522c3
commit
0ebc5db723
54
cmd/internal/initialize/assets/README.md
Normal file
54
cmd/internal/initialize/assets/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# {{.}} Project
|
||||
|
||||
## 目录说明 - Directory description
|
||||
> resources
|
||||
>> cn: 资源存放目录, 可自定义目录名
|
||||
>>
|
||||
>> en: Resource storage directory, customizable directory name
|
||||
|
||||
## 文件说明 - File description
|
||||
> energy.json
|
||||
>> cn: 项目配置文件, 用于构建和生成安装程序, 文件名不可更改.
|
||||
>>
|
||||
>> en: project configuration file, which is used to build and generate the installer, has an unchangeable file name.
|
||||
>
|
||||
> go.mod
|
||||
>> cn: go模块依赖管理, 文件名不可更改.
|
||||
>>
|
||||
>> en: go module dependency management, has an unchangeable file name.
|
||||
>
|
||||
> main.go
|
||||
>> cn: go应用启用入口文件
|
||||
>>
|
||||
>> en: go application enables the entry file
|
||||
>
|
||||
> go.sum No need to change
|
||||
|
||||
### cn: 以上可以根据实际情况变更
|
||||
### en: The above can be changed according to the actual situation
|
||||
|
||||
## 运行应用 - Run Application
|
||||
> Windows, Linux: `go run main.go`
|
||||
>
|
||||
> MacOS: `go run main.go env=dev`
|
||||
|
||||
## 构建应用 - Building Applications
|
||||
> Use Go:
|
||||
>> Windows: `go build -ldflags "-H windowsgui -s -w"`
|
||||
>>
|
||||
>> Linux: `go build -ldflags "-s -w"`
|
||||
>>
|
||||
>> MacOS: `go build -ldflags "-s -w"`
|
||||
>
|
||||
> Use Energy
|
||||
>> `energy build .`
|
||||
>
|
||||
|
||||
## 制作安装包 - Making installation packages
|
||||
> 1. 构建应用 - Building Applications
|
||||
>> `energy build .`
|
||||
>
|
||||
> 2. 执行制作安装包命令 - Run the create installation package command
|
||||
>> `energy package .`
|
||||
>>
|
||||
>> [Reference link]()
|
10
cmd/internal/initialize/assets/index.html
Normal file
10
cmd/internal/initialize/assets/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Go Energy</title>
|
||||
</head>
|
||||
<body>
|
||||
index.html
|
||||
</body>
|
||||
</html>
|
@ -34,9 +34,25 @@ func InitEnergyProject(c *command.Config) error {
|
||||
if err := generaProject(c); err != nil {
|
||||
return err
|
||||
}
|
||||
generaReadme()
|
||||
println("Successfully initialized the energy application project", c.Init.Name)
|
||||
println()
|
||||
println("Run Application: go run main.go")
|
||||
println(`Building Applications:
|
||||
Use GO: go build -ldflags "-s -w"
|
||||
Use Energy: energy build .
|
||||
`)
|
||||
println(`website:
|
||||
https://github.com/energye/energy
|
||||
https://energy.yanghy.cn
|
||||
`)
|
||||
return nil
|
||||
}
|
||||
|
||||
func generaReadme() {
|
||||
|
||||
}
|
||||
|
||||
func generaProject(c *command.Config) error {
|
||||
projectPath := filepath.Join(c.Wd, c.Init.Name)
|
||||
println("Create Project:", c.Init.Name)
|
||||
@ -48,7 +64,7 @@ func generaProject(c *command.Config) error {
|
||||
if strings.ToLower(s) != "y" {
|
||||
return errors.New("Failed to initialize project " + c.Init.Name)
|
||||
} else {
|
||||
var deleteFiles = []string{"energy.json", "resources", "main.go", "go.mod", "go.sum"}
|
||||
var deleteFiles = []string{"energy.json", "resources", "main.go", "go.mod", "go.sum", "resources/index.html"}
|
||||
for _, f := range deleteFiles {
|
||||
path := filepath.Join(projectPath, f)
|
||||
if info, err := os.Lstat(path); err == nil {
|
||||
@ -111,6 +127,20 @@ func generaProject(c *command.Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 resources/index.html
|
||||
if err := os.Mkdir(filepath.Join(projectPath, "resources"), fs.ModePerm); err != nil {
|
||||
return err
|
||||
} else {
|
||||
if indexText, err := assets.ReadFile("assets/index.html"); err != nil {
|
||||
return err
|
||||
} else {
|
||||
path := filepath.Join(projectPath, "resources", "index.html")
|
||||
if err = ioutil.WriteFile(path, indexText, 0666); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cmd
|
||||
println("cmd run")
|
||||
cmd := toolsCommand.NewCMD()
|
||||
@ -118,17 +148,20 @@ func generaProject(c *command.Config) error {
|
||||
cmd.MessageCallback = func(bytes []byte, err error) {
|
||||
fmt.Println("CMD:", bytes, " error:", err)
|
||||
}
|
||||
// cmd go env -w GO111MODULE=on
|
||||
println("Enable Go mod management")
|
||||
cmd.Command("go", []string{"env", "-w", "GO111MODULE=on"}...)
|
||||
if c.Init.IGo {
|
||||
// cmd go env -w GO111MODULE=on
|
||||
println("Enable Go mod management")
|
||||
cmd.Command("go", []string{"env", "-w", "GO111MODULE=on"}...)
|
||||
|
||||
// cmd go env -w GOPROXY=https://goproxy.io,direct
|
||||
println("Configure mod agent")
|
||||
cmd.Command("go", []string{"env", "-w", "GOPROXY=https://goproxy.io,direct"}...)
|
||||
// cmd go env -w GOPROXY=https://goproxy.io,direct
|
||||
println("Configure mod agent")
|
||||
cmd.Command("go", []string{"env", "-w", "GOPROXY=https://goproxy.io,direct"}...)
|
||||
|
||||
// cmd go mod tidy
|
||||
println("Update Energy dependencies, version:")
|
||||
cmd.Command("go", []string{"mod", "tidy"}...)
|
||||
}
|
||||
|
||||
// cmd go mod tidy
|
||||
println("Update Energy dependencies, version:")
|
||||
cmd.Command("go", []string{"mod", "tidy"}...)
|
||||
cmd.Close()
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user