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