mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 14:10:58 +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%">
|
<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%"/>
|
<img src="https://github.com/marcus-crane.png?size=50" width="50" style="border-radius: 50%"/>
|
||||||
</a>
|
</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>
|
<span id="nav-5"></span>
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
@ -5,6 +5,9 @@ import (
|
|||||||
"github.com/flytam/filenamify"
|
"github.com/flytam/filenamify"
|
||||||
"github.com/leaanthony/slicer"
|
"github.com/leaanthony/slicer"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -78,7 +81,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate IDE option
|
// Validate IDE option
|
||||||
supportedIDEs := slicer.String([]string{"vscode"})
|
supportedIDEs := slicer.String([]string{"vscode", "goland"})
|
||||||
ide = strings.ToLower(ide)
|
ide = strings.ToLower(ide)
|
||||||
if ide != "" {
|
if ide != "" {
|
||||||
if !supportedIDEs.Contains(ide) {
|
if !supportedIDEs.Contains(ide) {
|
||||||
@ -101,6 +104,16 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// Create Template Options
|
||||||
options := &templates.Options{
|
options := &templates.Options{
|
||||||
ProjectName: projectName,
|
ProjectName: projectName,
|
||||||
@ -111,19 +124,20 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
InitGit: initGit,
|
InitGit: initGit,
|
||||||
ProjectNameFilename: projectFilename,
|
ProjectNameFilename: projectFilename,
|
||||||
WailsVersion: app.Version(),
|
WailsVersion: app.Version(),
|
||||||
|
GoSDKPath: goSDKPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to discover author details from git config
|
// Try to discover author details from git config
|
||||||
findAuthorDetails(options)
|
findAuthorDetails(options)
|
||||||
|
|
||||||
return initProject(options)
|
return initProject(options, quiet)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// initProject is our main init command
|
// initProject is our main init command
|
||||||
func initProject(options *templates.Options) error {
|
func initProject(options *templates.Options, quiet bool) error {
|
||||||
|
|
||||||
// Start Time
|
// Start Time
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
@ -140,6 +154,19 @@ func initProject(options *templates.Options) error {
|
|||||||
return err
|
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 {
|
if options.InitGit {
|
||||||
err = initGit(options)
|
err = initGit(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,6 +174,10 @@ func initProject(options *templates.Options) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if quiet {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Output stats
|
// Output stats
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
options.Logger.Println("")
|
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
|
AuthorEmail string
|
||||||
AuthorNameAndEmail string
|
AuthorNameAndEmail string
|
||||||
WailsDirectory string
|
WailsDirectory string
|
||||||
|
GoSDKPath string
|
||||||
|
AssetDir string
|
||||||
|
WindowsFlags string
|
||||||
|
CGOEnabled string
|
||||||
|
OutputFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options for installing a template
|
// Options for installing a template
|
||||||
@ -60,6 +65,10 @@ type Options struct {
|
|||||||
IDE string
|
IDE string
|
||||||
ProjectNameFilename string // The project name but as a valid filename
|
ProjectNameFilename string // The project name but as a valid filename
|
||||||
WailsVersion string
|
WailsVersion string
|
||||||
|
GoSDKPath string
|
||||||
|
WindowsFlags string
|
||||||
|
CGOEnabled string
|
||||||
|
OutputFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template holds data relating to a template
|
// Template holds data relating to a template
|
||||||
@ -243,6 +252,7 @@ func Install(options *Options) (bool, *Template, error) {
|
|||||||
BinaryName := filepath.Base(options.TargetDir)
|
BinaryName := filepath.Base(options.TargetDir)
|
||||||
NPMProjectName := strings.ToLower(strings.ReplaceAll(BinaryName, " ", ""))
|
NPMProjectName := strings.ToLower(strings.ReplaceAll(BinaryName, " ", ""))
|
||||||
localWailsDirectory := fs.RelativePath("../../../../../..")
|
localWailsDirectory := fs.RelativePath("../../../../../..")
|
||||||
|
|
||||||
templateData := &Data{
|
templateData := &Data{
|
||||||
ProjectName: options.ProjectName,
|
ProjectName: options.ProjectName,
|
||||||
BinaryName: filepath.Base(options.TargetDir),
|
BinaryName: filepath.Base(options.TargetDir),
|
||||||
@ -251,6 +261,8 @@ func Install(options *Options) (bool, *Template, error) {
|
|||||||
AuthorEmail: options.AuthorEmail,
|
AuthorEmail: options.AuthorEmail,
|
||||||
AuthorName: options.AuthorName,
|
AuthorName: options.AuthorName,
|
||||||
WailsVersion: options.WailsVersion,
|
WailsVersion: options.WailsVersion,
|
||||||
|
GoSDKPath: options.GoSDKPath,
|
||||||
|
AssetDir: options.AssetDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a formatted name and email combo.
|
// Create a formatted name and email combo.
|
||||||
@ -330,14 +342,29 @@ func generateIDEFiles(options *Options) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ideOptions struct {
|
||||||
|
name string
|
||||||
|
targetDir string
|
||||||
|
options *Options
|
||||||
|
renameFiles map[string]string
|
||||||
|
ignoredFiles []string
|
||||||
|
}
|
||||||
|
|
||||||
func generateGolandFiles(options *Options) error {
|
func generateGolandFiles(options *Options) error {
|
||||||
targetDir := filepath.Join(options.TargetDir, ".idea")
|
ideoptions := ideOptions{
|
||||||
renameFiles := map[string]string{
|
name: "goland",
|
||||||
"projectname.iml": options.ProjectNameFilename + ".iml",
|
targetDir: filepath.Join(options.TargetDir, ".idea"),
|
||||||
"gitignore.txt": ".gitignore",
|
options: options,
|
||||||
"name": ".name",
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "generating Goland IDE files")
|
return errors.Wrap(err, "generating Goland IDE files")
|
||||||
}
|
}
|
||||||
@ -346,13 +373,17 @@ func generateGolandFiles(options *Options) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateVSCodeFiles(options *Options) error {
|
func generateVSCodeFiles(options *Options) error {
|
||||||
targetDir := filepath.Join(options.TargetDir, ".vscode")
|
ideoptions := ideOptions{
|
||||||
return installIDEFiles("vscode", targetDir, options, nil)
|
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 {
|
func installIDEFiles(o ideOptions) error {
|
||||||
source, err := debme.FS(ides, "ides/"+ideName)
|
source, err := debme.FS(ides, "ides/"+o.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -360,18 +391,22 @@ func installIDEFiles(ideName string, targetDir string, options *Options, renameF
|
|||||||
// Use gosod to install the template
|
// Use gosod to install the template
|
||||||
installer := gosod.New(source)
|
installer := gosod.New(source)
|
||||||
|
|
||||||
if renameFiles != nil {
|
if o.renameFiles != nil {
|
||||||
installer.RenameFiles(renameFiles)
|
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" {
|
if runtime.GOOS == "windows" {
|
||||||
// yay windows
|
// yay windows
|
||||||
binaryName += ".exe"
|
binaryName += ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse wails.json for assetdir
|
// 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 {
|
if err != nil {
|
||||||
return err
|
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' ")
|
return fmt.Errorf("Unable to find 'assetdir' in 'wails.json' ")
|
||||||
}
|
}
|
||||||
|
|
||||||
options.AssetDir = assetDir.(string)
|
o.options.AssetDir = assetDir.(string)
|
||||||
options.PathToDesktopBinary = filepath.ToSlash(filepath.Join("build", "bin", binaryName))
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user