5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 14:29:50 +08:00

Dev colours

This commit is contained in:
Lea Anthony 2021-02-20 15:25:40 +11:00
parent 0080e9e311
commit 4362a14459
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 23 additions and 10 deletions

View File

@ -10,6 +10,8 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/wailsapp/wails/v2/internal/colour"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -20,6 +22,16 @@ import (
"github.com/wailsapp/wails/v2/pkg/commands/build" "github.com/wailsapp/wails/v2/pkg/commands/build"
) )
func LogGreen(message string, args ...interface{}) {
text := fmt.Sprintf(message, args...)
println(colour.Green(text))
}
func LogDarkYellow(message string, args ...interface{}) {
text := fmt.Sprintf(message, args...)
println(colour.DarkYellow(text))
}
// AddSubcommand adds the `dev` command for the Wails application // AddSubcommand adds the `dev` command for the Wails application
func AddSubcommand(app *clir.Cli, w io.Writer) error { func AddSubcommand(app *clir.Cli, w io.Writer) error {
@ -79,7 +91,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
if err != nil { if err != nil {
logger.Fatal("%s", err.Error()) logger.Fatal("%s", err.Error())
} }
logger.Println("Watching directory: %s", event.Name) LogGreen("[Change] Watching new directory: %s", event.Name)
} }
} }
return return
@ -88,7 +100,6 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
// Check for file writes // Check for file writes
if event.Op&fsnotify.Write == fsnotify.Write { if event.Op&fsnotify.Write == fsnotify.Write {
logger.Println("modified file: %s", event.Name)
var rebuild bool = false var rebuild bool = false
// Iterate all file patterns // Iterate all file patterns
@ -105,11 +116,11 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
} }
if !rebuild { if !rebuild {
logger.Println("Filename change: %s did not match extension list (%s)", event.Name, extensions) LogDarkYellow("Filename change: %s did not match extension list (%s)", event.Name, extensions)
return return
} }
logger.Println("Partial build triggered: %s updated", event.Name) LogGreen("[Rebuild] %s updated", event.Name)
// Do a rebuild // Do a rebuild
@ -139,12 +150,13 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
return err return err
} }
LogGreen("Watching (sub)/directory: %s", dir)
// Setup a watcher for non-node_modules directories // Setup a watcher for non-node_modules directories
dirs.Each(func(dir string) { dirs.Each(func(dir string) {
if strings.Contains(dir, "node_modules") { if strings.Contains(dir, "node_modules") {
return return
} }
logger.Println("Watching directory: %s", dir)
err = watcher.Add(dir) err = watcher.Add(dir)
if err != nil { if err != nil {
logger.Fatal(err.Error()) logger.Fatal(err.Error())
@ -156,7 +168,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
for quit == false { for quit == false {
select { select {
case <-quitChannel: case <-quitChannel:
println("Caught quit") LogGreen("Caught quit")
// Notify debouncer to quit // Notify debouncer to quit
debounceQuit <- true debounceQuit <- true
quit = true quit = true
@ -171,7 +183,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
} }
} }
logger.Println("Development mode exited") LogGreen("Development mode exited")
return nil return nil
}) })
@ -206,7 +218,6 @@ func restartApp(logger *clilogger.CLILogger, outputType string, ldflags string,
logger.Fatal(err.Error()) logger.Fatal(err.Error())
return nil, errors.Wrap(err, "Build Failed:") return nil, errors.Wrap(err, "Build Failed:")
} }
logger.Println("Build new binary: %s", appBinary)
// Kill existing binary if need be // Kill existing binary if need be
if debugBinaryProcess != nil { if debugBinaryProcess != nil {

View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"github.com/wailsapp/wails/v2/internal/colour"
) )
// CLILogger is used by the cli // CLILogger is used by the cli
@ -51,9 +53,9 @@ func (c *CLILogger) Println(message string, args ...interface{}) {
// Fatal prints the given message then aborts // Fatal prints the given message then aborts
func (c *CLILogger) Fatal(message string, args ...interface{}) { func (c *CLILogger) Fatal(message string, args ...interface{}) {
temp := fmt.Sprintf(message, args...) temp := fmt.Sprintf(message, args...)
_, err := fmt.Fprintln(c.Writer, "FATAL: "+temp) _, err := fmt.Fprintln(c.Writer, colour.Red("FATAL: "+temp))
if err != nil { if err != nil {
println("FATAL: ", err) println(colour.Red("FATAL: " + err.Error()))
} }
os.Exit(1) os.Exit(1)
} }