diff --git a/README.md b/README.md index c23b7b120..7019b3ee8 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,12 @@ This project is supported by these kind people / companies: - + + + + + + ## Installation diff --git a/v2/cmd/wails/internal/commands/initialise/initialise.go b/v2/cmd/wails/internal/commands/initialise/initialise.go index 86b410457..f87e6b7a3 100644 --- a/v2/cmd/wails/internal/commands/initialise/initialise.go +++ b/v2/cmd/wails/internal/commands/initialise/initialise.go @@ -5,6 +5,9 @@ import ( "github.com/flytam/filenamify" "github.com/leaanthony/slicer" "io" + "os" + "os/exec" + "path/filepath" "strings" "time" @@ -78,7 +81,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { } // Validate IDE option - supportedIDEs := slicer.String([]string{"vscode"}) + supportedIDEs := slicer.String([]string{"vscode", "goland"}) ide = strings.ToLower(ide) if ide != "" { if !supportedIDEs.Contains(ide) { @@ -101,6 +104,16 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { if err != nil { return err } + goBinary, err := exec.LookPath("go") + if err != nil { + return fmt.Errorf("unable to find Go compiler. Please download and install Go: https://golang.org/dl/") + } + + // Get base path and convert to forward slashes + goPath := filepath.ToSlash(filepath.Dir(goBinary)) + // Trim bin directory + goSDKPath := strings.TrimSuffix(goPath, "/bin") + // Create Template Options options := &templates.Options{ ProjectName: projectName, @@ -111,19 +124,20 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { InitGit: initGit, ProjectNameFilename: projectFilename, WailsVersion: app.Version(), + GoSDKPath: goSDKPath, } // Try to discover author details from git config findAuthorDetails(options) - return initProject(options) + return initProject(options, quiet) }) return nil } // initProject is our main init command -func initProject(options *templates.Options) error { +func initProject(options *templates.Options, quiet bool) error { // Start Time start := time.Now() @@ -140,6 +154,19 @@ func initProject(options *templates.Options) error { return err } + // Run `go mod tidy` to ensure `go.sum` is up to date + cmd := exec.Command("go", "mod", "tidy") + cmd.Dir = options.TargetDir + cmd.Stderr = os.Stderr + if !quiet { + println("") + cmd.Stdout = os.Stdout + } + err = cmd.Run() + if err != nil { + return err + } + if options.InitGit { err = initGit(options) if err != nil { @@ -147,6 +174,10 @@ func initProject(options *templates.Options) error { } } + if quiet { + return nil + } + // Output stats elapsed := time.Since(start) options.Logger.Println("") diff --git a/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/modules.xml b/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/modules.tmpl.xml similarity index 100% rename from v2/cmd/wails/internal/commands/initialise/templates/ides/goland/modules.xml rename to v2/cmd/wails/internal/commands/initialise/templates/ides/goland/modules.tmpl.xml diff --git a/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/vcs.xml b/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/vcs.xml new file mode 100644 index 000000000..78f5bc6f7 --- /dev/null +++ b/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/workspace.tmpl.xml b/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/workspace.tmpl.xml new file mode 100644 index 000000000..42f98045b --- /dev/null +++ b/v2/cmd/wails/internal/commands/initialise/templates/ides/goland/workspace.tmpl.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + \ No newline at end of file diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates.go b/v2/cmd/wails/internal/commands/initialise/templates/templates.go index ade152a25..a584486d1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates.go @@ -42,6 +42,11 @@ type Data struct { AuthorEmail string AuthorNameAndEmail string WailsDirectory string + GoSDKPath string + AssetDir string + WindowsFlags string + CGOEnabled string + OutputFile string } // Options for installing a template @@ -60,6 +65,10 @@ type Options struct { IDE string ProjectNameFilename string // The project name but as a valid filename WailsVersion string + GoSDKPath string + WindowsFlags string + CGOEnabled string + OutputFile string } // Template holds data relating to a template @@ -243,6 +252,7 @@ func Install(options *Options) (bool, *Template, error) { BinaryName := filepath.Base(options.TargetDir) NPMProjectName := strings.ToLower(strings.ReplaceAll(BinaryName, " ", "")) localWailsDirectory := fs.RelativePath("../../../../../..") + templateData := &Data{ ProjectName: options.ProjectName, BinaryName: filepath.Base(options.TargetDir), @@ -251,6 +261,8 @@ func Install(options *Options) (bool, *Template, error) { AuthorEmail: options.AuthorEmail, AuthorName: options.AuthorName, WailsVersion: options.WailsVersion, + GoSDKPath: options.GoSDKPath, + AssetDir: options.AssetDir, } // Create a formatted name and email combo. @@ -330,14 +342,29 @@ func generateIDEFiles(options *Options) error { return nil } +type ideOptions struct { + name string + targetDir string + options *Options + renameFiles map[string]string + ignoredFiles []string +} + func generateGolandFiles(options *Options) error { - targetDir := filepath.Join(options.TargetDir, ".idea") - renameFiles := map[string]string{ - "projectname.iml": options.ProjectNameFilename + ".iml", - "gitignore.txt": ".gitignore", - "name": ".name", + ideoptions := ideOptions{ + name: "goland", + targetDir: filepath.Join(options.TargetDir, ".idea"), + options: options, + renameFiles: map[string]string{ + "projectname.iml": options.ProjectNameFilename + ".iml", + "gitignore.txt": ".gitignore", + "name": ".name", + }, } - err := installIDEFiles("goland", targetDir, options, renameFiles) + if !options.InitGit { + ideoptions.ignoredFiles = []string{"vcs.xml"} + } + err := installIDEFiles(ideoptions) if err != nil { return errors.Wrap(err, "generating Goland IDE files") } @@ -346,13 +373,17 @@ func generateGolandFiles(options *Options) error { } func generateVSCodeFiles(options *Options) error { - targetDir := filepath.Join(options.TargetDir, ".vscode") - return installIDEFiles("vscode", targetDir, options, nil) + ideoptions := ideOptions{ + name: "vscode", + targetDir: filepath.Join(options.TargetDir, ".vscode"), + options: options, + } + return installIDEFiles(ideoptions) } -func installIDEFiles(ideName string, targetDir string, options *Options, renameFiles map[string]string) error { - source, err := debme.FS(ides, "ides/"+ideName) +func installIDEFiles(o ideOptions) error { + source, err := debme.FS(ides, "ides/"+o.name) if err != nil { return err } @@ -360,18 +391,22 @@ func installIDEFiles(ideName string, targetDir string, options *Options, renameF // Use gosod to install the template installer := gosod.New(source) - if renameFiles != nil { - installer.RenameFiles(renameFiles) + if o.renameFiles != nil { + installer.RenameFiles(o.renameFiles) } - binaryName := filepath.Base(options.TargetDir) + for _, ignoreFile := range o.ignoredFiles { + installer.IgnoreFile(ignoreFile) + } + + binaryName := filepath.Base(o.options.TargetDir) if runtime.GOOS == "windows" { // yay windows binaryName += ".exe" } // Parse wails.json for assetdir - wailsJSONBytes, err := os.ReadFile(filepath.Join(options.TargetDir, "wails.json")) + wailsJSONBytes, err := os.ReadFile(filepath.Join(o.options.TargetDir, "wails.json")) if err != nil { return err } @@ -385,10 +420,16 @@ func installIDEFiles(ideName string, targetDir string, options *Options, renameF return fmt.Errorf("Unable to find 'assetdir' in 'wails.json' ") } - options.AssetDir = assetDir.(string) - options.PathToDesktopBinary = filepath.ToSlash(filepath.Join("build", "bin", binaryName)) + o.options.AssetDir = assetDir.(string) + o.options.PathToDesktopBinary = filepath.ToSlash(filepath.Join("build", "bin", binaryName)) - err = installer.Extract(targetDir, options) + o.options.WindowsFlags = "" + o.options.CGOEnabled = "1" + if runtime.GOOS == "windows" { + o.options.WindowsFlags = " -H windowsgui" + o.options.CGOEnabled = "0" + } + err = installer.Extract(o.targetDir, o.options) if err != nil { return err }