From bc69b39ccdef276e2174b503a8468d5a9bba74d7 Mon Sep 17 00:00:00 2001 From: Twacqwq <69360546+Twacqwq@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:58:46 +0800 Subject: [PATCH] feat(cmd/init): change default module name to project name (#3303) * feat(cmd/init): change default module name to project name * chore: write go.mod using chmod 644 * refactor: using go mod edit change module name * docs: update changelog.mdx and cli.mdx * Revert "feat(cmd/init): change default module name to project name" This reverts commit 504d9517591f876e4a3a75fd16e22ed312f991c5. * feat(cmd/init): change default module name to project name --------- Co-authored-by: Lea Anthony --- v2/cmd/wails/init.go | 17 +++++++++++++++++ website/src/pages/changelog.mdx | 1 + 2 files changed, 18 insertions(+) diff --git a/v2/cmd/wails/init.go b/v2/cmd/wails/init.go index 709905c0f..f79e37ffc 100644 --- a/v2/cmd/wails/init.go +++ b/v2/cmd/wails/init.go @@ -125,6 +125,12 @@ func initProject(f *flags.Init) error { return err } + // Change the module name to project name + err = updateModuleNameToProjectName(options, quiet) + if err != nil { + return err + } + if !f.CIMode { // Run `go mod tidy` to ensure `go.sum` is up to date cmd := exec.Command("go", "mod", "tidy") @@ -276,3 +282,14 @@ func updateReplaceLine(targetPath string) { fatal(err.Error()) } } + +func updateModuleNameToProjectName(options *templates.Options, quiet bool) error { + cmd := exec.Command("go", "mod", "edit", "-module", options.ProjectName) + cmd.Dir = options.TargetDir + cmd.Stderr = os.Stderr + if !quiet { + cmd.Stdout = os.Stdout + } + + return cmd.Run() +} diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 4166f46e1..fba49d82d 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added docs to help fix NixOs/Wayland font-size css issue. Added by @atterpac in [PR](https://github.com/wailsapp/wails/pull/3268) - Added -m (skip `go mod tidy`) flag to dev command by @te5se in [PR](https://github.com/wailsapp/wails/pull/3275) - Added mac option `DisableZoom` to remove zoom button. Added by @wizzymore in [PR](https://github.com/wailsapp/wails/pull/3289) +- Changed Create a project with changing the default name to the project’s name. Changed by [@Twacqwq](https://github.com/Twacqwq) in [PR](https://github.com/wailsapp/wails/pull/3303) ## v2.8.0 - 2024-02-08