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")
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,19 +34,23 @@ var devMode = false
|
|||
//go:embed static
|
||||
var staticFS embed.FS
|
||||
|
||||
type watcher struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
devMode bool
|
||||
|
||||
ms *xmain.State
|
||||
type watcherOpts struct {
|
||||
layoutPlugin d2plugin.Plugin
|
||||
themeID int64
|
||||
host string
|
||||
port string
|
||||
inputPath string
|
||||
outputPath string
|
||||
}
|
||||
|
||||
type watcher struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
devMode bool
|
||||
|
||||
ms *xmain.State
|
||||
watcherOpts
|
||||
|
||||
compileCh chan struct{}
|
||||
|
||||
|
|
@ -71,7 +75,7 @@ type compileResult struct {
|
|||
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)
|
||||
|
||||
w := &watcher{
|
||||
|
|
@ -79,13 +83,8 @@ func newWatcher(ctx context.Context, ms *xmain.State, layoutPlugin d2plugin.Plug
|
|||
cancel: cancel,
|
||||
devMode: devMode,
|
||||
|
||||
ms: ms,
|
||||
layoutPlugin: layoutPlugin,
|
||||
themeID: themeID,
|
||||
host: host,
|
||||
port: port,
|
||||
inputPath: inputPath,
|
||||
outputPath: outputPath,
|
||||
ms: ms,
|
||||
watcherOpts: opts,
|
||||
|
||||
compileCh: make(chan struct{}, 1),
|
||||
wsclients: make(map[*wsclient]struct{}),
|
||||
|
|
|
|||
Loading…
Reference in a new issue