mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 11:40:56 +08:00
[v2] Support Goland IDE
This commit is contained in:
parent
28af34f978
commit
12b7cf09e6
@ -119,7 +119,12 @@ This project is supported by these kind people / companies:
|
||||
<a href="https://github.com/marcus-crane" style="width:50px;border-radius: 50%">
|
||||
<img src="https://github.com/marcus-crane.png?size=50" width="50" style="border-radius: 50%"/>
|
||||
</a>
|
||||
|
||||
<a href="https://github.com/codydbentley" style="width:65px">
|
||||
<img src="https://github.com/codydbentley.png?size=65" width="65"/>
|
||||
</a>
|
||||
<a href="https://github.com/bbergshaven" style="width:45px">
|
||||
<img src="https://github.com/bbergshaven.png?size=45" width="45"/>
|
||||
</a>
|
||||
<span id="nav-5"></span>
|
||||
|
||||
## Installation
|
||||
|
@ -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("")
|
||||
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git"/>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="ALL"/>
|
||||
</component>
|
||||
<component name="GOROOT" url="file://{{.GoSDKPath}}"/>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$"/>
|
||||
</component>
|
||||
<component name="GoLibraries">
|
||||
<option name="indexEntireGoPath" value="false"/>
|
||||
</component>
|
||||
<component name="ProjectId" id="wails-{{.ProjectName}}"/>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true"/>
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true"/>
|
||||
<option name="showLibraryContents" value="true"/>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true"/>
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true"/>
|
||||
<property name="WebServerToolWindowFactoryState" value="false"/>
|
||||
<property name="com.intellij.ide.scratch.LRUPopupBuilder$1/New Scratch File" value="TEXT"/>
|
||||
<property name="go.formatter.settings.were.checked" value="true"/>
|
||||
<property name="go.import.settings.migrated" value="true"/>
|
||||
<property name="go.modules.go.list.on.any.changes.was.set" value="true"/>
|
||||
<property name="go.sdk.automatically.set" value="true"/>
|
||||
<property name="go.tried.to.enable.integration.vgo.integrator" value="true"/>
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$"/>
|
||||
<property name="settings.editor.selected.configurable"
|
||||
value="reference.settingsdialog.IDE.editor.colors.Console Font"/>
|
||||
</component>
|
||||
<component name="RunManager" selected="Go Build.{{.ProjectName}} (dev)">>
|
||||
<configuration name="{{.ProjectName}} (dev)" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
||||
<module name="{{.ProjectName}}"/>
|
||||
<working_directory value="$PROJECT_DIR$"/>
|
||||
<go_parameters value="-gcflags "all=-N -l" -tags dev -o {{.PathToDesktopBinary}}"/>
|
||||
<useCustomBuildTags value="true"/>
|
||||
<parameters value="-assetdir {{.AssetDir}}"/>
|
||||
<envs>
|
||||
<env name="CGO_ENABLED" value=""{{.CGOEnabled}}""/>
|
||||
</envs>
|
||||
<kind value="DIRECTORY"/>
|
||||
<directory value="$PROJECT_DIR$"/>
|
||||
<filePath value="$PROJECT_DIR$"/>
|
||||
<method v="2">
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="{{.ProjectName}} (production)" type="GoApplicationRunConfiguration"
|
||||
factoryName="Go Application">
|
||||
<module name="{{.ProjectName}}"/>
|
||||
<working_directory value="$PROJECT_DIR$"/>
|
||||
<go_parameters
|
||||
value="-ldflags "-w -s{{.WindowsFlags}}" -tags desktop,production -o {{.PathToDesktopBinary}}"/>
|
||||
<useCustomBuildTags value="true"/>
|
||||
<envs>
|
||||
<env name="CGO_ENABLED" value=""{{.CGOEnabled}}""/>
|
||||
</envs>
|
||||
<kind value="DIRECTORY"/>
|
||||
<directory value="$PROJECT_DIR$"/>
|
||||
<filePath value="$PROJECT_DIR$"/>
|
||||
<method v="2">
|
||||
</method>
|
||||
</configuration>
|
||||
|
||||
<list>
|
||||
<item itemvalue="Go Build.{{.ProjectName}} (dev)"/>
|
||||
<item itemvalue="Go Remote.Local"/>
|
||||
</list>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0"
|
||||
DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true"/>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3"/>
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State/>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
<option name="oldMeFiltersMigrated" value="true"/>
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
<integration-enabled>true</integration-enabled>
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
</breakpoint-manager>
|
||||
</component>
|
||||
</project>
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user