2022-11-16 11:49:45PM
This commit is contained in:
parent
e08a0fb8dc
commit
c8739d8147
2 changed files with 23 additions and 16 deletions
|
|
@ -132,7 +132,15 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
return xmain.UsageErrorf("-w[atch] cannot be combined with reading input from stdin")
|
return xmain.UsageErrorf("-w[atch] cannot be combined with reading input from stdin")
|
||||||
}
|
}
|
||||||
ms.Env.Setenv("LOG_TIMESTAMPS", "1")
|
ms.Env.Setenv("LOG_TIMESTAMPS", "1")
|
||||||
w, err := newWatcher(ctx, ms, plugin, *themeFlag, *hostFlag, *portFlag, inputPath, outputPath)
|
|
||||||
|
w, err := newWatcher(ctx, ms, watcherOpts{
|
||||||
|
layoutPlugin: plugin,
|
||||||
|
themeID: *themeFlag,
|
||||||
|
host: *hostFlag,
|
||||||
|
port: *portFlag,
|
||||||
|
inputPath: inputPath,
|
||||||
|
outputPath: outputPath,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,15 @@ var devMode = false
|
||||||
//go:embed static
|
//go:embed static
|
||||||
var staticFS embed.FS
|
var staticFS embed.FS
|
||||||
|
|
||||||
|
type watcherOpts struct {
|
||||||
|
layoutPlugin d2plugin.Plugin
|
||||||
|
themeID int64
|
||||||
|
host string
|
||||||
|
port string
|
||||||
|
inputPath string
|
||||||
|
outputPath string
|
||||||
|
}
|
||||||
|
|
||||||
type watcher struct {
|
type watcher struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
|
@ -41,12 +50,7 @@ type watcher struct {
|
||||||
devMode bool
|
devMode bool
|
||||||
|
|
||||||
ms *xmain.State
|
ms *xmain.State
|
||||||
layoutPlugin d2plugin.Plugin
|
watcherOpts
|
||||||
themeID int64
|
|
||||||
host string
|
|
||||||
port string
|
|
||||||
inputPath string
|
|
||||||
outputPath string
|
|
||||||
|
|
||||||
compileCh chan struct{}
|
compileCh chan struct{}
|
||||||
|
|
||||||
|
|
@ -71,7 +75,7 @@ type compileResult struct {
|
||||||
SVG string `json:"svg"`
|
SVG string `json:"svg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWatcher(ctx context.Context, ms *xmain.State, layoutPlugin d2plugin.Plugin, themeID int64, host, port, inputPath, outputPath string) (*watcher, error) {
|
func newWatcher(ctx context.Context, ms *xmain.State, opts watcherOpts) (*watcher, error) {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
w := &watcher{
|
w := &watcher{
|
||||||
|
|
@ -80,12 +84,7 @@ func newWatcher(ctx context.Context, ms *xmain.State, layoutPlugin d2plugin.Plug
|
||||||
devMode: devMode,
|
devMode: devMode,
|
||||||
|
|
||||||
ms: ms,
|
ms: ms,
|
||||||
layoutPlugin: layoutPlugin,
|
watcherOpts: opts,
|
||||||
themeID: themeID,
|
|
||||||
host: host,
|
|
||||||
port: port,
|
|
||||||
inputPath: inputPath,
|
|
||||||
outputPath: outputPath,
|
|
||||||
|
|
||||||
compileCh: make(chan struct{}, 1),
|
compileCh: make(chan struct{}, 1),
|
||||||
wsclients: make(map[*wsclient]struct{}),
|
wsclients: make(map[*wsclient]struct{}),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue