process fixes windows
This commit is contained in:
parent
a55bd1a2b4
commit
a1a335691d
6 changed files with 29 additions and 11 deletions
|
|
@ -65,7 +65,7 @@ func main() {
|
|||
css.GenerateCssWatch(process.ExitOnError)
|
||||
}()
|
||||
go func() {
|
||||
_ = run.Server(process.ExitOnError)
|
||||
_ = run.Server()
|
||||
}()
|
||||
startWatcher(reloader.OnFileChange)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ func findPublicFuncsReturningHPartial(dir string, predicate func(partial Partial
|
|||
if selectorExpr.Sel.Name == "Partial" {
|
||||
p := Partial{
|
||||
Package: node.Name.Name,
|
||||
Import: sliceCommonPrefix(cwd, filepath.Dir(path)),
|
||||
Import: sliceCommonPrefix(cwd, strings.ReplaceAll(filepath.Dir(path), `\`, `/`)),
|
||||
FuncName: funcDecl.Name.Name,
|
||||
}
|
||||
if predicate(p) {
|
||||
|
|
@ -168,7 +168,7 @@ func findPublicFuncsReturningHPage(dir string) ([]Page, error) {
|
|||
if selectorExpr.Sel.Name == "Page" {
|
||||
pages = append(pages, Page{
|
||||
Package: node.Name.Name,
|
||||
Import: filepath.Dir(path),
|
||||
Import: strings.ReplaceAll(filepath.Dir(path), `\`, `/`),
|
||||
Path: path,
|
||||
FuncName: funcDecl.Name.Name,
|
||||
})
|
||||
|
|
@ -285,9 +285,11 @@ func formatRoute(path string) string {
|
|||
path = strings.TrimSuffix(path, "index.go")
|
||||
path = strings.TrimSuffix(path, ".go")
|
||||
path = strings.TrimPrefix(path, "pages/")
|
||||
path = strings.TrimPrefix(path, "pages\\")
|
||||
path = strings.ReplaceAll(path, "$", ":")
|
||||
path = strings.ReplaceAll(path, "_", "/")
|
||||
path = strings.ReplaceAll(path, ".", "/")
|
||||
path = strings.ReplaceAll(path, "\\", "/")
|
||||
if path == "" {
|
||||
return "/"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package process
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
|
|
@ -10,7 +13,9 @@ func KillProcess(process *os.Process) error {
|
|||
if process == nil {
|
||||
return nil
|
||||
}
|
||||
return process.Kill()
|
||||
Run(fmt.Sprintf("taskkill /F /T /PID %s", strconv.Itoa(process.Pid)))
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrepareCommand(command *exec.Cmd) {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func shouldSkipKilling(flags []RunFlag, skipFlag []RunFlag) bool {
|
|||
func KillAll(skipFlag ...RunFlag) {
|
||||
|
||||
tries := 0
|
||||
removeIndexes := make([]int, 0)
|
||||
updatedCommands := make([]CmdWithFlags, len(commands))
|
||||
for {
|
||||
tries++
|
||||
allFinished := true
|
||||
|
|
@ -66,12 +66,13 @@ func KillAll(skipFlag ...RunFlag) {
|
|||
args := strings.Join(cmd.cmd.Args, " ")
|
||||
slog.Debug("process is not running after 50 tries, breaking.", slog.String("command", args))
|
||||
allFinished = true
|
||||
removeIndexes = append(removeIndexes, i)
|
||||
break
|
||||
} else {
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
updatedCommands[i] = cmd
|
||||
}
|
||||
}
|
||||
if allFinished {
|
||||
|
|
@ -79,8 +80,11 @@ func KillAll(skipFlag ...RunFlag) {
|
|||
}
|
||||
}
|
||||
|
||||
for i := len(removeIndexes) - 1; i >= 0; i-- {
|
||||
commands = append(commands[:removeIndexes[i]], commands[removeIndexes[i]+1:]...)
|
||||
commands = make([]CmdWithFlags, 0)
|
||||
for _, command := range updatedCommands {
|
||||
if command.cmd != nil && command.cmd.Process != nil {
|
||||
commands = append(commands, command)
|
||||
}
|
||||
}
|
||||
|
||||
for _, command := range commands {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/maddalax/htmgo/framework/internal/process"
|
||||
"github.com/maddalax/htmgo/framework/service"
|
||||
"log/slog"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -94,7 +96,13 @@ func (a App) start() {
|
|||
// and try again
|
||||
if IsDevelopment() && IsWatchMode() {
|
||||
slog.Info("Port already in use, trying to kill the process and start again")
|
||||
process.RunOrExit(fmt.Sprintf("kill -9 $(lsof -t -i%s)", port))
|
||||
if runtime.GOOS == "windows" {
|
||||
cmd := exec.Command("cmd", "/C", fmt.Sprintf(`for /F "tokens=5" %%i in ('netstat -aon ^| findstr :%s') do taskkill /F /PID %%i`, port))
|
||||
cmd.Run()
|
||||
} else {
|
||||
process.RunOrExit(fmt.Sprintf("kill -9 $(lsof -t -i%s)", port))
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
err = a.Echo.Start(port)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ func main() {
|
|||
}
|
||||
})
|
||||
|
||||
__htmgo.RegisterPartials(e)
|
||||
__htmgo.RegisterPages(e)
|
||||
__htmgo.Register(e)
|
||||
|
||||
pages.RegisterMarkdown(e, "md", MarkdownAssets, func(ctx echo.Context, path string) error {
|
||||
return pages.MarkdownHandler(ctx.(*h.RequestContext), path, "")
|
||||
|
|
|
|||
Loading…
Reference in a new issue