web panel edit settings
This commit is contained in:
parent
dba785ebcd
commit
0647c03d75
@ -33,7 +33,7 @@ type realize struct {
|
||||
Sync chan string `yaml:"-"`
|
||||
Blueprint w.Blueprint `yaml:"-"`
|
||||
Server s.Server `yaml:"-"`
|
||||
Projects *[]w.Project `yaml:"projects"`
|
||||
Projects *[]w.Project `yaml:"projects" json:"projects"`
|
||||
}
|
||||
|
||||
// Realize struct initialization
|
||||
@ -154,6 +154,7 @@ func main() {
|
||||
r.Blueprint.Add(p)
|
||||
handle(r.Server.Start(p))
|
||||
handle(r.Blueprint.Run())
|
||||
handle(r.Record(r))
|
||||
return nil
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
|
File diff suppressed because one or more lines are too long
@ -8,6 +8,7 @@ import (
|
||||
w "github.com/tockins/realize/watcher"
|
||||
"golang.org/x/net/websocket"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
@ -50,6 +51,7 @@ func (s *Server) Start(p *cli.Context) (err error) {
|
||||
if !p.Bool("no-server") && s.Enabled {
|
||||
e := echo.New()
|
||||
e.Use(middleware.Gzip())
|
||||
e.Use(middleware.Recover())
|
||||
|
||||
// web panel
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
@ -81,7 +83,8 @@ func (s *Server) Start(p *cli.Context) (err error) {
|
||||
})
|
||||
|
||||
//websocket
|
||||
e.GET("/ws", echo.WrapHandler(s.projects()))
|
||||
//e.GET("/ws", echo.WrapHandler(s.projects()))
|
||||
e.GET("/ws", s.hello)
|
||||
|
||||
go e.Start(string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
|
||||
if s.Open || p.Bool("open") {
|
||||
@ -94,19 +97,36 @@ func (s *Server) Start(p *cli.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// The WebSocket for projects list
|
||||
func (s *Server) projects() websocket.Handler {
|
||||
return websocket.Handler(func(ws *websocket.Conn) {
|
||||
msg := func() {
|
||||
message, _ := json.Marshal(s.Blueprint.Projects)
|
||||
websocket.Message.Send(ws, string(message))
|
||||
}
|
||||
msg()
|
||||
func (s *Server) hello(c echo.Context) error {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
defer ws.Close()
|
||||
msg, _ := json.Marshal(s.Blueprint.Projects)
|
||||
err := websocket.Message.Send(ws, string(msg))
|
||||
for {
|
||||
select {
|
||||
case <-s.Sync:
|
||||
msg()
|
||||
msg, _ := json.Marshal(s.Blueprint.Projects)
|
||||
err = websocket.Message.Send(ws, string(msg))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Read
|
||||
text := ""
|
||||
err := websocket.Message.Receive(ws, &text)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
break
|
||||
} else {
|
||||
err := json.Unmarshal([]byte(text), &s.Blueprint.Projects)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}).ServeHTTP(c.Response(), c.Request())
|
||||
return nil
|
||||
}
|
||||
|
@ -7,26 +7,26 @@ import (
|
||||
|
||||
type Settings struct {
|
||||
Colors `yaml:"-"`
|
||||
Resources `yaml:"resources,omitempty"`
|
||||
Server `yaml:"server,omitempty"`
|
||||
Config `yaml:"config,omitempty"`
|
||||
Resources `yaml:"resources,omitempty" json:"resources,omitempty"`
|
||||
Server `yaml:"server,omitempty" json:"server,omitempty"`
|
||||
Config `yaml:"config,omitempty" json:"config,omitempty"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Flimit uint64 `yaml:"flimit"`
|
||||
Flimit uint64 `yaml:"flimit" json:"flimit"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Enabled bool `yaml:"enable"`
|
||||
Open bool `yaml:"open"`
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Enabled bool `yaml:"enable" json:"enable"`
|
||||
Open bool `yaml:"open" json:"open"`
|
||||
Host string `yaml:"host" json:"host"`
|
||||
Port int `yaml:"port" json:"port"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
Config string `yaml:"-"`
|
||||
Output string `yaml:"output"`
|
||||
Log string `yaml:"log"`
|
||||
Config string `yaml:"-" json:"-"`
|
||||
Output string `yaml:"output" json:"output"`
|
||||
Log string `yaml:"log" json:"log"`
|
||||
}
|
||||
|
||||
// Flimit defines the max number of watched files
|
||||
|
@ -17,28 +17,28 @@ type logWriter struct {
|
||||
// Projects struct contains a projects list
|
||||
type Blueprint struct {
|
||||
*c.Settings `yaml:"-"`
|
||||
Projects []Project `yaml:"projects,omitempty"`
|
||||
Projects []Project `yaml:"projects,omitempty" json:"projects,omitempty"`
|
||||
Sync chan string `yaml:"-"`
|
||||
}
|
||||
|
||||
// Project defines the informations of a single project
|
||||
type Project struct {
|
||||
c.Settings `yaml:"-"`
|
||||
LastChangedOn time.Time `yaml:"-"`
|
||||
LastChangedOn time.Time `yaml:"-" json:"-"`
|
||||
base string
|
||||
Name string `yaml:"name"`
|
||||
Path string `yaml:"path"`
|
||||
Run bool `yaml:"run"`
|
||||
Bin bool `yaml:"bin"`
|
||||
Generate bool `yaml:"generate"`
|
||||
Build bool `yaml:"build"`
|
||||
Fmt bool `yaml:"fmt"`
|
||||
Test bool `yaml:"test"`
|
||||
Params []string `yaml:"params"`
|
||||
Watcher Watcher `yaml:"watcher"`
|
||||
Cli Cli `yaml:"cli"`
|
||||
File File `yaml:"file"`
|
||||
Buffer Buffer `yaml:"-"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Run bool `yaml:"run" json:"run"`
|
||||
Bin bool `yaml:"bin" json:"bin"`
|
||||
Generate bool `yaml:"generate" json:"generate"`
|
||||
Build bool `yaml:"build" json:"build"`
|
||||
Fmt bool `yaml:"fmt" json:"fmt"`
|
||||
Test bool `yaml:"test" json:"test"`
|
||||
Params []string `yaml:"params" json:"params"`
|
||||
Watcher Watcher `yaml:"watcher" json:"watcher"`
|
||||
Cli Cli `yaml:"cli" json:"cli"`
|
||||
File File `yaml:"file" json:"file"`
|
||||
Buffer Buffer `yaml:"-" json:"buffer"`
|
||||
parent *Blueprint
|
||||
path string
|
||||
}
|
||||
@ -46,38 +46,38 @@ type Project struct {
|
||||
// Watcher struct defines the livereload's logic
|
||||
type Watcher struct {
|
||||
// different before and after on re-run?
|
||||
Before []string `yaml:"before"`
|
||||
After []string `yaml:"after"`
|
||||
Paths []string `yaml:"paths"`
|
||||
Ignore []string `yaml:"ignore_paths"`
|
||||
Exts []string `yaml:"exts"`
|
||||
Preview bool `yaml:"preview"`
|
||||
Before []string `yaml:"before" json:"before"`
|
||||
After []string `yaml:"after" json:"after"`
|
||||
Paths []string `yaml:"paths" json:"paths"`
|
||||
Ignore []string `yaml:"ignore_paths" json:"ignore"`
|
||||
Exts []string `yaml:"exts" json:"exts"`
|
||||
Preview bool `yaml:"preview" json:"preview"`
|
||||
}
|
||||
|
||||
type Cli struct {
|
||||
Streams bool `yaml:"streams"`
|
||||
Streams bool `yaml:"streams" json:"streams"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Streams bool `yaml:"streams"`
|
||||
Logs bool `yaml:"logs"`
|
||||
Errors bool `yaml:"errors"`
|
||||
Streams bool `yaml:"streams" json:"streams"`
|
||||
Logs bool `yaml:"logs" json:"logs"`
|
||||
Errors bool `yaml:"errors" json:"errors"`
|
||||
}
|
||||
|
||||
// Buffer struct for buffering outputs
|
||||
type Buffer struct {
|
||||
StdOut []BufferOut
|
||||
StdLog []BufferOut
|
||||
StdErr []BufferOut
|
||||
StdOut []BufferOut `json:"stdOut"`
|
||||
StdLog []BufferOut `json:"stdLog"`
|
||||
StdErr []BufferOut `json:"stdErr"`
|
||||
}
|
||||
|
||||
type BufferOut struct {
|
||||
Time time.Time
|
||||
Text string
|
||||
Path string
|
||||
Type string
|
||||
Stream string
|
||||
Errors []string
|
||||
Time time.Time `json:"time"`
|
||||
Text string `json:"text"`
|
||||
Path string `json:"path"`
|
||||
Type string `json:"type"`
|
||||
Stream string `json:"stream"`
|
||||
Errors []string `json:"errors"`
|
||||
}
|
||||
|
||||
// Initialize the application
|
||||
|
Loading…
Reference in New Issue
Block a user