diff --git a/cmd/internal/initialize/assets/README.md b/cmd/internal/initialize/assets/README.md index c0bc7a73..ed5d04d4 100644 --- a/cmd/internal/initialize/assets/README.md +++ b/cmd/internal/initialize/assets/README.md @@ -1,4 +1,4 @@ -# {{.}} Project +# {{.Name}} Project ## 目录说明 - Directory description > resources diff --git a/cmd/internal/initialize/initialize.go b/cmd/internal/initialize/initialize.go index a4329f99..5acc7d0e 100644 --- a/cmd/internal/initialize/initialize.go +++ b/cmd/internal/initialize/initialize.go @@ -34,25 +34,21 @@ 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: + 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: + 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) @@ -64,7 +60,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", "resources/index.html"} + var deleteFiles = []string{"energy.json", "resources", "main.go", "go.mod", "go.sum", "resources/index.html", "README.md"} for _, f := range deleteFiles { path := filepath.Join(projectPath, f) if info, err := os.Lstat(path); err == nil { @@ -141,6 +137,22 @@ func generaProject(c *command.Config) error { } } + // 创建 README.md + if readmeText, err := assets.ReadFile("assets/README.md"); err != nil { + return err + } else { + data := make(map[string]any) + data["Name"] = c.Init.Name + if content, err := tools.RenderTemplate(string(readmeText), data); err != nil { + return err + } else { + path := filepath.Join(projectPath, "README.md") + if err = ioutil.WriteFile(path, content, 0666); err != nil { + return err + } + } + } + // cmd println("cmd run") cmd := toolsCommand.NewCMD()