mirror of
https://github.com/taigrr/wails.git
synced 2026-04-16 03:40:49 -07:00
Compare commits
3 Commits
Massively-
...
Make-Serve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f50b95f26 | ||
|
|
259eec97d6 | ||
|
|
8b2168abe7 |
@@ -20,6 +20,7 @@ type frontend struct {
|
|||||||
Install string `json:"install"`
|
Install string `json:"install"`
|
||||||
Build string `json:"build"`
|
Build string `json:"build"`
|
||||||
Bridge string `json:"bridge"`
|
Bridge string `json:"bridge"`
|
||||||
|
Serve string `json:"serve"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type framework struct {
|
type framework struct {
|
||||||
@@ -274,6 +275,7 @@ func (po *ProjectOptions) PromptForInputs() error {
|
|||||||
}
|
}
|
||||||
po.FrontEnd.Build = templateMetadata["build"].(string)
|
po.FrontEnd.Build = templateMetadata["build"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if templateMetadata["bridge"] != nil {
|
if templateMetadata["bridge"] != nil {
|
||||||
if po.FrontEnd == nil {
|
if po.FrontEnd == nil {
|
||||||
return fmt.Errorf("bridge set in template metadata but not frontenddir")
|
return fmt.Errorf("bridge set in template metadata but not frontenddir")
|
||||||
@@ -281,6 +283,13 @@ func (po *ProjectOptions) PromptForInputs() error {
|
|||||||
po.FrontEnd.Bridge = templateMetadata["bridge"].(string)
|
po.FrontEnd.Bridge = templateMetadata["bridge"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if templateMetadata["serve"] != nil {
|
||||||
|
if po.FrontEnd == nil {
|
||||||
|
return fmt.Errorf("serve set in template metadata but not frontenddir")
|
||||||
|
}
|
||||||
|
po.FrontEnd.Serve = templateMetadata["serve"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,6 @@
|
|||||||
"frontenddir": "frontend",
|
"frontenddir": "frontend",
|
||||||
"install": "npm install",
|
"install": "npm install",
|
||||||
"build": "npm run build",
|
"build": "npm run build",
|
||||||
|
"serve": "npm run serve",
|
||||||
"bridge": "src"
|
"bridge": "src"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,17 +17,14 @@ func init() {
|
|||||||
|
|
||||||
var packageApp = false
|
var packageApp = false
|
||||||
var forceRebuild = false
|
var forceRebuild = false
|
||||||
var releaseMode = false
|
|
||||||
buildSpinner := spinner.NewSpinner()
|
buildSpinner := spinner.NewSpinner()
|
||||||
buildSpinner.SetSpinSpeed(50)
|
buildSpinner.SetSpinSpeed(50)
|
||||||
|
|
||||||
commandDescription := `This command will check to ensure all pre-requistes are installed prior to building. If not, it will attempt to install them. Building comprises of a number of steps: install frontend dependencies, build frontend, pack frontend, compile main application.`
|
commandDescription := `This command will check to ensure all pre-requistes are installed prior to building. If not, it will attempt to install them. Building comprises of a number of steps: install frontend dependencies, build frontend, pack frontend, compile main application.`
|
||||||
initCmd := app.Command("build", "Builds your Wails project").
|
initCmd := app.Command("build", "Builds your Wails project").
|
||||||
LongDescription(commandDescription).
|
LongDescription(commandDescription).
|
||||||
BoolFlag("p", "Package application on successful build (Implies -r)", &packageApp).
|
BoolFlag("p", "Package application on successful build", &packageApp).
|
||||||
BoolFlag("f", "Force rebuild of application components", &forceRebuild).
|
BoolFlag("f", "Force rebuild of application components", &forceRebuild)
|
||||||
BoolFlag("r", "Build in Release mode", &releaseMode)
|
|
||||||
|
|
||||||
initCmd.Action(func() error {
|
initCmd.Action(func() error {
|
||||||
log := cmd.NewLogger()
|
log := cmd.NewLogger()
|
||||||
message := "Building Application"
|
message := "Building Application"
|
||||||
@@ -145,11 +142,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine which wails bridge to install
|
// Determine which wails bridge to install
|
||||||
var bridgeFile = "wailsbridge.js"
|
bridgeFile := "wailsbridge.prod.js"
|
||||||
if releaseMode || packageApp {
|
|
||||||
// Release mode
|
|
||||||
bridgeFile = "wailsbridge.prod.js"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy bridge to project
|
// Copy bridge to project
|
||||||
_, filename, _, _ := runtime.Caller(1)
|
_, filename, _, _ := runtime.Caller(1)
|
||||||
@@ -193,9 +186,6 @@ func init() {
|
|||||||
depSpinner.Success()
|
depSpinner.Success()
|
||||||
|
|
||||||
compileMessage := "Packing + Compiling project"
|
compileMessage := "Packing + Compiling project"
|
||||||
if releaseMode || packageApp {
|
|
||||||
compileMessage += " (Release Mode)"
|
|
||||||
}
|
|
||||||
|
|
||||||
packSpinner := spinner.New(compileMessage + "...")
|
packSpinner := spinner.New(compileMessage + "...")
|
||||||
packSpinner.SetSpinSpeed(50)
|
packSpinner.SetSpinSpeed(50)
|
||||||
@@ -222,9 +212,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Release mode
|
// Release mode
|
||||||
if releaseMode || packageApp {
|
|
||||||
buildCommand.AddSlice([]string{"-ldflags", "-X github.com/wailsapp/wails.DebugMode=false"})
|
buildCommand.AddSlice([]string{"-ldflags", "-X github.com/wailsapp/wails.DebugMode=false"})
|
||||||
}
|
|
||||||
err = program.RunCommandArray(buildCommand.AsSlice())
|
err = program.RunCommandArray(buildCommand.AsSlice())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
packSpinner.Error()
|
packSpinner.Error()
|
||||||
236
cmd/wails/6_serve.go
Normal file
236
cmd/wails/6_serve.go
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/leaanthony/slicer"
|
||||||
|
"github.com/leaanthony/spinner"
|
||||||
|
"github.com/wailsapp/wails/cmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
var forceRebuild = false
|
||||||
|
buildSpinner := spinner.NewSpinner()
|
||||||
|
buildSpinner.SetSpinSpeed(50)
|
||||||
|
|
||||||
|
commandDescription := `This command builds then serves your application in bridge mode. Useful for developing your app in a browser.`
|
||||||
|
initCmd := app.Command("serve", "Runs your Wails project in bridge mode").
|
||||||
|
LongDescription(commandDescription).
|
||||||
|
BoolFlag("f", "Force rebuild of application components", &forceRebuild)
|
||||||
|
|
||||||
|
initCmd.Action(func() error {
|
||||||
|
log := cmd.NewLogger()
|
||||||
|
message := "Building Application"
|
||||||
|
if forceRebuild {
|
||||||
|
message += " (force rebuild)"
|
||||||
|
}
|
||||||
|
log.WhiteUnderline(message)
|
||||||
|
|
||||||
|
// Project options
|
||||||
|
projectOptions := &cmd.ProjectOptions{}
|
||||||
|
|
||||||
|
// Check we are in project directory
|
||||||
|
// Check project.json loads correctly
|
||||||
|
fs := cmd.NewFSHelper()
|
||||||
|
err := projectOptions.LoadConfig(fs.Cwd())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Validate config
|
||||||
|
// // Check if we have a frontend
|
||||||
|
// if projectOptions.FrontEnd != nil {
|
||||||
|
// if projectOptions.FrontEnd.Dir == "" {
|
||||||
|
// return fmt.Errorf("Frontend directory not set in project.json")
|
||||||
|
// }
|
||||||
|
// if projectOptions.FrontEnd.Build == "" {
|
||||||
|
// return fmt.Errorf("Frontend build command not set in project.json")
|
||||||
|
// }
|
||||||
|
// if projectOptions.FrontEnd.Install == "" {
|
||||||
|
// return fmt.Errorf("Frontend install command not set in project.json")
|
||||||
|
// }
|
||||||
|
// if projectOptions.FrontEnd.Bridge == "" {
|
||||||
|
// return fmt.Errorf("Frontend bridge config not set in project.json")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Check pre-requisites are installed
|
||||||
|
|
||||||
|
// Program checker
|
||||||
|
program := cmd.NewProgramHelper()
|
||||||
|
|
||||||
|
// if projectOptions.FrontEnd != nil {
|
||||||
|
// // npm
|
||||||
|
// if !program.IsInstalled("npm") {
|
||||||
|
// return fmt.Errorf("it appears npm is not installed. Please install and run again")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// packr
|
||||||
|
if !program.IsInstalled("packr") {
|
||||||
|
buildSpinner.Start("Installing packr...")
|
||||||
|
err := program.InstallGoPackage("github.com/gobuffalo/packr/...")
|
||||||
|
if err != nil {
|
||||||
|
buildSpinner.Error()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
buildSpinner.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save project directory
|
||||||
|
projectDir := fs.Cwd()
|
||||||
|
|
||||||
|
// Install backend deps - needed?
|
||||||
|
// if projectOptions.FrontEnd != nil {
|
||||||
|
// // Install frontend deps
|
||||||
|
// err = os.Chdir(projectOptions.FrontEnd.Dir)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Check if frontend deps have been updated
|
||||||
|
// feSpinner := spinner.New("Installing frontend dependencies (This may take a while)...")
|
||||||
|
// feSpinner.SetSpinSpeed(50)
|
||||||
|
// feSpinner.Start()
|
||||||
|
|
||||||
|
// requiresNPMInstall := true
|
||||||
|
|
||||||
|
// // Read in package.json MD5
|
||||||
|
// packageJSONMD5, err := fs.FileMD5("package.json")
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const md5sumFile = "package.json.md5"
|
||||||
|
|
||||||
|
// // If we aren't forcing the install and the md5sum file exists
|
||||||
|
// if !forceRebuild && fs.FileExists(md5sumFile) {
|
||||||
|
// // Yes - read contents
|
||||||
|
// savedMD5sum, err := fs.LoadAsString(md5sumFile)
|
||||||
|
// // File exists
|
||||||
|
// if err == nil {
|
||||||
|
// // Compare md5
|
||||||
|
// if savedMD5sum == packageJSONMD5 {
|
||||||
|
// // Same - no need for reinstall
|
||||||
|
// requiresNPMInstall = false
|
||||||
|
// feSpinner.Success("Skipped frontend dependencies (-f to force rebuild)")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Md5 sum package.json
|
||||||
|
// // Different? Build
|
||||||
|
// if requiresNPMInstall || forceRebuild {
|
||||||
|
// // Install dependencies
|
||||||
|
// err = program.RunCommand(projectOptions.FrontEnd.Install)
|
||||||
|
// if err != nil {
|
||||||
|
// feSpinner.Error()
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// feSpinner.Success()
|
||||||
|
|
||||||
|
// // Update md5sum file
|
||||||
|
// ioutil.WriteFile(md5sumFile, []byte(packageJSONMD5), 0644)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Copy bridge to project
|
||||||
|
var bridgeFile = "wailsbridge.js"
|
||||||
|
_, filename, _, _ := runtime.Caller(1)
|
||||||
|
bridgeFileSource := filepath.Join(path.Dir(filename), "..", "assets", "default", bridgeFile)
|
||||||
|
bridgeFileTarget := filepath.Join(projectDir, projectOptions.FrontEnd.Dir, projectOptions.FrontEnd.Bridge, "wailsbridge.js")
|
||||||
|
err = fs.CopyFile(bridgeFileSource, bridgeFileTarget)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Build frontend
|
||||||
|
// buildFESpinner := spinner.New("Building frontend...")
|
||||||
|
// buildFESpinner.SetSpinSpeed(50)
|
||||||
|
// buildFESpinner.Start()
|
||||||
|
// err = program.RunCommand(projectOptions.FrontEnd.Build)
|
||||||
|
// if err != nil {
|
||||||
|
// buildFESpinner.Error()
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// buildFESpinner.Success()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Run packr in project directory
|
||||||
|
err = os.Chdir(projectDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support build tags
|
||||||
|
buildTags := []string{}
|
||||||
|
|
||||||
|
depSpinner := spinner.New("Installing Dependencies...")
|
||||||
|
depSpinner.SetSpinSpeed(50)
|
||||||
|
depSpinner.Start()
|
||||||
|
installCommand := "go get"
|
||||||
|
err = program.RunCommand(installCommand)
|
||||||
|
if err != nil {
|
||||||
|
depSpinner.Error()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
depSpinner.Success()
|
||||||
|
|
||||||
|
compileMessage := "Packing + Compiling project"
|
||||||
|
|
||||||
|
packSpinner := spinner.New(compileMessage + "...")
|
||||||
|
packSpinner.SetSpinSpeed(50)
|
||||||
|
packSpinner.Start()
|
||||||
|
|
||||||
|
buildCommand := slicer.String()
|
||||||
|
buildCommand.AddSlice([]string{"packr", "build"})
|
||||||
|
|
||||||
|
// Add build tags
|
||||||
|
if len(buildTags) > 0 {
|
||||||
|
buildCommand.Add("--tags")
|
||||||
|
buildCommand.AddSlice(buildTags)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if projectOptions.BinaryName != "" {
|
||||||
|
buildCommand.Add("-o")
|
||||||
|
buildCommand.Add(projectOptions.BinaryName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are forcing a rebuild
|
||||||
|
if forceRebuild {
|
||||||
|
buildCommand.Add("-a")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = program.RunCommandArray(buildCommand.AsSlice())
|
||||||
|
if err != nil {
|
||||||
|
packSpinner.Error()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
packSpinner.Success()
|
||||||
|
|
||||||
|
// Run the App
|
||||||
|
logger.Yellow("Awesome! Project '%s' built!", projectOptions.Name)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
logger.Green(">>>>> To connect, you will need to run '" + projectOptions.FrontEnd.Serve + "' in the '" + projectOptions.FrontEnd.Dir + "' directory <<<<<")
|
||||||
|
}()
|
||||||
|
logger.Yellow("Serving Application: " + projectOptions.BinaryName)
|
||||||
|
cmd := exec.Command(projectOptions.BinaryName)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
2
go.mod
2
go.mod
@@ -13,7 +13,7 @@ require (
|
|||||||
github.com/jackmordaunt/icns v1.0.0
|
github.com/jackmordaunt/icns v1.0.0
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||||
github.com/leaanthony/slicer v0.0.0-20190110113548-aa9ea12f976a
|
github.com/leaanthony/slicer v0.0.0-20190110113548-aa9ea12f976a
|
||||||
github.com/leaanthony/spinner v0.4.0
|
github.com/leaanthony/spinner v0.5.0
|
||||||
github.com/leaanthony/synx v0.0.0-20180923230033-60efbd9984b0 // indirect
|
github.com/leaanthony/synx v0.0.0-20180923230033-60efbd9984b0 // indirect
|
||||||
github.com/leaanthony/wincursor v0.0.0-20180705115120-056510f32d15 // indirect
|
github.com/leaanthony/wincursor v0.0.0-20180705115120-056510f32d15 // indirect
|
||||||
github.com/mattn/go-colorable v0.0.9 // indirect
|
github.com/mattn/go-colorable v0.0.9 // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user