Skip to content

Commit

Permalink
chore: linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine committed Jan 7, 2025
1 parent b418e01 commit 1622765
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions frontend/cli/cmd_schema_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (s *schemaGenerateCmd) hotReload(ctx context.Context, client ftlv1connect.S

absTemplatePath, err := filepath.Abs(s.Template)
if err != nil {
return err
return fmt.Errorf("failed to get absolute path for template: %w", err)
}
absDestPath, err := filepath.Abs(s.Dest)
if err != nil {
return err
return fmt.Errorf("failed to get absolute path for destination: %w", err)
}

if strings.HasPrefix(absDestPath, absTemplatePath) {
Expand All @@ -69,7 +69,7 @@ func (s *schemaGenerateCmd) hotReload(ctx context.Context, client ftlv1connect.S
logger.Debugf("Watching %s", s.Template)

if err := watch.AddRecursive(s.Template); err != nil {
return err
return fmt.Errorf("failed to watch template directory: %w", err)
}

wg, ctx := errgroup.WithContext(ctx)
Expand All @@ -80,7 +80,7 @@ func (s *schemaGenerateCmd) hotReload(ctx context.Context, client ftlv1connect.S
for {
stream, err := client.PullSchema(ctx, connect.NewRequest(&ftlv1.PullSchemaRequest{}))
if err != nil {
return err
return fmt.Errorf("failed to pull schema: %w", err)
}

modules := map[string]*schema.Module{}
Expand All @@ -105,6 +105,7 @@ func (s *schemaGenerateCmd) hotReload(ctx context.Context, client ftlv1connect.S
if msg.ModuleRemoved {
delete(modules, msg.Schema.Name)
}
default:
}
if !msg.More {
regenerate = true
Expand All @@ -128,33 +129,33 @@ func (s *schemaGenerateCmd) hotReload(ctx context.Context, client ftlv1connect.S
for {
select {
case <-ctx.Done():
return wg.Wait()
return fmt.Errorf("context cancelled: %w", wg.Wait())

case event := <-watch.Event:
logger.Debugf("Template changed (%s), regenerating modules", event.Path)
if err := s.regenerateModules(logger, previousModules); err != nil {
return err
return fmt.Errorf("failed to regenerate modules: %w", err)
}

case modules := <-moduleChange:
previousModules = modules
if err := s.regenerateModules(logger, modules); err != nil {
return err
return fmt.Errorf("failed to regenerate modules: %w", err)
}
}
}
}

func (s *schemaGenerateCmd) regenerateModules(logger *log.Logger, modules []*schema.Module) error {
if err := os.RemoveAll(s.Dest); err != nil {
return err
return fmt.Errorf("failed to remove destination directory: %w", err)
}

for _, module := range modules {
if err := scaffolder.Scaffold(s.Template, s.Dest, module,
scaffolder.Extend(javascript.Extension("template.js", javascript.WithLogger(makeJSLoggerAdapter(logger)))),
); err != nil {
return err
return fmt.Errorf("failed to scaffold module %s: %w", module.Name, err)
}
}
logger.Debugf("Generated %d modules in %s", len(modules), s.Dest)
Expand Down

0 comments on commit 1622765

Please sign in to comment.