Skip to content

Commit

Permalink
Merge pull request #107 from wailsapp/develop
Browse files Browse the repository at this point in the history
Release v0.15.0
  • Loading branch information
leaanthony authored May 26, 2019
2 parents 9cb2ed1 + 249a35f commit 1ce0620
Show file tree
Hide file tree
Showing 31 changed files with 797 additions and 11,237 deletions.
26 changes: 24 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,36 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"name": "Wails Init",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/wails/main.go",
"env": {},
"cwd": "/tmp",
"args": [
"setup"
"init",
"-name",
"runtime",
"-dir",
"runtime",
"-output",
"runtime",
"-template",
"vuebasic"
]
},
{
"name": "Wails Update Pre",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/wails/main.go",
"env": {},
"cwd": "/tmp",
"args": [
"update",
"-pre"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Wails is currently in Beta. Please make sure you read the [Project Status](https

Wails uses cgo to bind to the native rendering engines so a number of platform dependent libraries are needed as well as an installation of Go. The basic requirements are:

- Go 1.11 or above
- Go 1.12
- npm

### MacOS
Expand Down
15 changes: 15 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type Command struct {
flagCount int
log *Logger
helpFlag bool
hidden bool
}

// NewCommand creates a new Command
Expand All @@ -106,6 +107,7 @@ func NewCommand(name string, description string, app *Cli, parentCommandPath str
SubCommandsMap: make(map[string]*Command),
App: app,
log: NewLogger(),
hidden: false,
}

// Set up command path
Expand Down Expand Up @@ -212,6 +214,9 @@ func (c *Command) PrintHelp() {
c.log.White("Available commands:")
fmt.Println("")
for _, subcommand := range c.SubCommands {
if subcommand.isHidden() {
continue
}
spacer := strings.Repeat(" ", 3+c.longestSubcommand-len(subcommand.Name))
isDefault := ""
if subcommand.isDefaultCommand() {
Expand All @@ -237,6 +242,16 @@ func (c *Command) isDefaultCommand() bool {
return c.App.defaultCommand == c
}

// isHidden returns true if the command is a hidden command
func (c *Command) isHidden() bool {
return c.hidden
}

// Hidden hides the command from the Help system
func (c *Command) Hidden() {
c.hidden = true
}

// Command - Defines a subcommand
func (c *Command) Command(name, description string) *Command {
result := NewCommand(name, description, c.App, c.CommandPath)
Expand Down
31 changes: 0 additions & 31 deletions cmd/cmd-mewn.go

This file was deleted.

76 changes: 72 additions & 4 deletions cmd/fs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package cmd

import (
"bytes"
"crypto/md5"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"runtime"

"github.com/leaanthony/slicer"
)

// FSHelper - Wrapper struct for File System utility commands
Expand Down Expand Up @@ -104,11 +110,33 @@ func (fs *FSHelper) RemoveFiles(files []string) error {
return nil
}

// Dir holds information about a directory
type Dir struct {
localPath string
fullPath string
}

// Directory creates a new Dir struct with the given directory path
func (fs *FSHelper) Directory(dir string) (*Dir, error) {
fullPath, err := filepath.Abs(dir)
return &Dir{fullPath: fullPath}, err
}

// LocalDir creates a new Dir struct based on a path relative to the caller
func (fs *FSHelper) LocalDir(dir string) (*Dir, error) {
_, filename, _, _ := runtime.Caller(1)
fullPath, err := filepath.Abs(filepath.Join(path.Dir(filename), dir))
return &Dir{
localPath: dir,
fullPath: fullPath,
}, err
}

// GetSubdirs will return a list of FQPs to subdirectories in the given directory
func (fs *FSHelper) GetSubdirs(dir string) (map[string]string, error) {
func (d *Dir) GetSubdirs() (map[string]string, error) {

// Read in the directory information
fileInfo, err := ioutil.ReadDir(dir)
fileInfo, err := ioutil.ReadDir(d.fullPath)
if err != nil {
return nil, err
}
Expand All @@ -120,25 +148,65 @@ func (fs *FSHelper) GetSubdirs(dir string) (map[string]string, error) {
// map["directoryName"] = "path/to/directoryName"
for _, file := range fileInfo {
if file.IsDir() {
subdirs[file.Name()] = filepath.Join(dir, file.Name())
subdirs[file.Name()] = filepath.Join(d.fullPath, file.Name())
}
}
return subdirs, nil
}

// GetAllFilenames returns all filename in and below this directory
func (d *Dir) GetAllFilenames() (*slicer.StringSlicer, error) {
result := slicer.String()
err := filepath.Walk(d.fullPath, func(dir string, info os.FileInfo, err error) error {
if dir == d.fullPath {
return nil
}
if err != nil {
return err
}

// Don't copy template metadata
result.Add(dir)

return nil
})
return result, err
}

// MkDir creates the given directory.
// Returns error on failure
func (fs *FSHelper) MkDir(dir string) error {
return os.Mkdir(dir, 0700)
}

// SaveAsJSON saves the JSON representation of the given data to the given filename
func (fs *FSHelper) SaveAsJSON(data interface{}, filename string) error {

var buf bytes.Buffer
e := json.NewEncoder(&buf)
e.SetEscapeHTML(false)
e.SetIndent("", " ")
e.Encode(data)

err := ioutil.WriteFile(filename, buf.Bytes(), 0755)
if err != nil {
return err
}
return nil
}

// LoadAsString will attempt to load the given file and return
// its contents as a string
func (fs *FSHelper) LoadAsString(filename string) (string, error) {
bytes, err := ioutil.ReadFile(filename)
bytes, err := fs.LoadAsBytes(filename)
return string(bytes), err
}

// LoadAsBytes returns the contents of the file as a byte slice
func (fs *FSHelper) LoadAsBytes(filename string) ([]byte, error) {
return ioutil.ReadFile(filename)
}

// FileMD5 returns the md5sum of the given file
func (fs *FSHelper) FileMD5(filename string) (string, error) {
f, err := os.Open(filename)
Expand Down
2 changes: 1 addition & 1 deletion cmd/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func GetLinuxDistroInfo() *DistroInfo {
switch value {
case "Ubuntu":
result.Distribution = Ubuntu
case "Arch":
case "Arch", "ManjaroLinux":
result.Distribution = Arch
}
case "Description":
Expand Down
2 changes: 1 addition & 1 deletion cmd/prerequisites.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func getRequiredProgramsLinux() *Prerequisites {
case Ubuntu:
result.Add(newPrerequisite("gcc", "Please install with `sudo apt install build-essentials` and try again"))
result.Add(newPrerequisite("pkg-config", "Please install with `sudo apt install pkg-config` and try again"))
result.Add(newPrerequisite("npm", "Please install with `sudo apt install npm` and try again"))
result.Add(newPrerequisite("npm", "Please install with `sudo snap install node --channel=12/stable --classic` and try again"))

default:
result.Add(newPrerequisite("gcc", "Please install with your system package manager and try again"))
Expand Down
49 changes: 32 additions & 17 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ func NewProjectHelper() *ProjectHelper {
// GenerateProject generates a new project using the options given
func (ph *ProjectHelper) GenerateProject(projectOptions *ProjectOptions) error {

// exists := ph.templates.TemplateExists(projectOptions.Template)

// if !exists {
// return fmt.Errorf("template '%s' is invalid", projectOptions.Template)
// }

// Calculate project path
projectPath, err := filepath.Abs(projectOptions.OutputDirectory)
if err != nil {
Expand Down Expand Up @@ -90,8 +84,6 @@ func (ph *ProjectHelper) GenerateProject(projectOptions *ProjectOptions) error {
// ph.GenerateWindowsResourceConfig(projectOptions)
// }

ph.log.Yellow("Project '%s' generated in directory '%s'!", projectOptions.Name, projectOptions.OutputDirectory)
ph.log.Yellow("To compile the project, run 'wails build' in the project directory.")
return nil
}

Expand Down Expand Up @@ -173,19 +165,43 @@ func (po *ProjectOptions) PromptForInputs() error {
// Process Templates
templateList := slicer.Interface()
options := slicer.String()
for _, templateDetails := range po.templates.TemplateList.details {
templateList.Add(templateDetails)
options.Add(fmt.Sprintf("%s - %s", templateDetails.Metadata.Name, templateDetails.Metadata.ShortDescription))
templateDetails, err := po.templates.GetTemplateDetails()
if err != nil {
return err
}

templateIndex := 0
if po.Template != "" {
// Check template is valid if given
if templateDetails[po.Template] == nil {
keys := make([]string, 0, len(templateDetails))
for k := range templateDetails {
keys = append(keys, k)
}
return fmt.Errorf("invalid template name '%s'. Valid options: %s", po.Template, strings.Join(keys, ", "))
}
po.selectedTemplate = templateDetails[po.Template]
} else {

if len(options.AsSlice()) > 1 {
templateIndex = PromptSelection("Please select a template", options.AsSlice(), 0)
for _, templateDetail := range templateDetails {
templateList.Add(templateDetail)
options.Add(fmt.Sprintf("%s - %s", templateDetail.Metadata.Name, templateDetail.Metadata.ShortDescription))
}

templateIndex := 0

if len(options.AsSlice()) > 1 {
templateIndex = PromptSelection("Please select a template", options.AsSlice(), 0)
}

if len(templateList.AsSlice()) == 0 {
return fmt.Errorf("aborting: no templates found")
}

// After selection do this....
po.selectedTemplate = templateList.AsSlice()[templateIndex].(*TemplateDetails)
}

// After selection do this....
po.selectedTemplate = templateList.AsSlice()[templateIndex].(*TemplateDetails)
fmt.Println("Template: " + po.selectedTemplate.Metadata.Name)

// Setup NPM Project name
po.NPMProjectName = strings.ToLower(strings.Replace(po.Name, " ", "_", -1))
Expand Down Expand Up @@ -266,7 +282,6 @@ func processProjectName(po *ProjectOptions) {
po.Name = Prompt("The name of the project", "My Project")
}
fmt.Println("Project Name: " + po.Name)

}

func processBinaryName(po *ProjectOptions) {
Expand Down
11 changes: 11 additions & 0 deletions cmd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ func (s *SystemHelper) ConfigFileIsValid() bool {
return err == nil
}

// GetAuthor returns a formatted string of the user's name and email
func (s *SystemHelper) GetAuthor() (string, error) {
var config *SystemConfig
config, err := s.LoadConfig()
if err != nil {
return "", err
}

return fmt.Sprintf("%s <%s>", config.Name, config.Email), nil
}

// BackupConfig attempts to backup the system config file
func (s *SystemHelper) BackupConfig() (string, error) {
now := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
Expand Down
Loading

0 comments on commit 1ce0620

Please sign in to comment.