Skip to content

Commit

Permalink
feat: Update schemas (#163)
Browse files Browse the repository at this point in the history
- Use yaml for official waku styles
- Fix yaml Unmarshalling for prompts
- Do not unmarshal  into a pointer to a slice (as a slice is a pointer itself)

---------

Signed-off-by: AlexNg <[email protected]>
  • Loading branch information
caffeine-addictt authored Oct 11, 2024
2 parents a0fbec2 + 5a2fb97 commit ef3dbca
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 243 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dist/*

www/
!www/mkdocs.yml
!www/static/schema.json
!www/docs/static/schema.json

template/
!template/template.json
Expand Down
12 changes: 6 additions & 6 deletions cmd/commands/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ var NewCmd = &cobra.Command{
var style types.CleanString
var styleInfo config.TemplateStyle

if tmpl.Styles != nil && len(*tmpl.Styles) == 1 {
for s, v := range *tmpl.Styles {
if len(tmpl.Styles) == 1 {
for s, v := range tmpl.Styles {
style = s
styleInfo = v
rootDir = filepath.Join(rootDir, v.Source.String())
break
}
} else if tmpl.Styles != nil {
} else {
if err := huh.NewForm(huh.NewGroup(
template.PromptForStyle(*tmpl.Styles, &style, &styleInfo),
template.PromptForStyle(tmpl.Styles, &style, &styleInfo),
)).WithAccessible(options.GlobalOpts.Accessible).Run(); err != nil {
return errors.ToWakuError(err)
}
Expand All @@ -130,12 +130,12 @@ var NewCmd = &cobra.Command{
log.Debugln("resolving prompts...")
extraPrompts := map[string]config.TemplatePrompt{}
if tmpl.Prompts != nil {
for _, ask := range *tmpl.Prompts {
for _, ask := range tmpl.Prompts {
extraPrompts[string(ask.Key)] = ask
}
}
if tmpl.Styles != nil && styleInfo.Prompts != nil {
for _, ask := range *styleInfo.Prompts {
for _, ask := range styleInfo.Prompts {
extraPrompts[string(ask.Key)] = ask
}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type TemplatePrompts []TemplatePrompt
// They prompt keys are case sensitive
// and Pacal case is recommended.
type TemplatePrompt struct {
Value any
value any
Format *string `json:"fmt,omitempty" yaml:"fmt,omitempty"`
Separator *string `json:"sep,omitempty" yaml:"sep,omitempty"`
Capture *types.RegexString `json:"capture,omitempty" yaml:"capture,omitempty"`
Expand Down Expand Up @@ -72,7 +72,7 @@ func (t *TemplatePrompt) GetPrompt(f map[string]any) *huh.Text {
return err
}

f[t.Key.String()] = t.Value
f[t.Key.String()] = t.value
return nil
})
}
Expand All @@ -86,7 +86,7 @@ func (t *TemplatePrompt) Set(s string) error {
return err
}

t.Value = val
t.value = val

case TemplatePromptTypeArray:
vals := strings.Split(s, *t.Separator)
Expand All @@ -99,7 +99,7 @@ func (t *TemplatePrompt) Set(s string) error {
vals[i] = val
}

t.Value = vals
t.value = vals

default:
panic(fmt.Sprintf("unexpected prompt type while setting value: %s", t.Type))
Expand Down Expand Up @@ -192,6 +192,7 @@ func (t *TemplatePrompt) UnmarshalYAML(node *yaml.Node) error {
return err
}

*t = ss
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/config/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type TemplateStyles map[types.CleanString]TemplateStyle
type TemplateStyle struct {
Setup *TemplateSetup `json:"setup,omitempty" yaml:"setup,omitempty"` // Paths to executable files for post-setup
Ignore *TemplateIgnore `json:"ignore,omitempty" yaml:"ignore,omitempty"` // The files that should be ignored when copying
Labels *TemplateLabel `json:"labels,omitempty" yaml:"labels,omitempty"` // The repository labels
Prompts *TemplatePrompts `json:"prompts,omitempty" yaml:"prompts,omitempty"` // The additional prompts to use
Source types.CleanString `json:"source" yaml:"source"` // The source template path
Labels TemplateLabel `json:"labels,omitempty" yaml:"labels,omitempty"` // The repository labels
Prompts TemplatePrompts `json:"prompts,omitempty" yaml:"prompts,omitempty"` // The additional prompts to use
}

func (t *TemplateStyles) Validate(root string) error {
Expand Down
25 changes: 7 additions & 18 deletions pkg/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,20 @@ package config

import (
"fmt"

"github.com/caffeine-addictt/waku/internal/types"
)

// The config file
type TemplateJson struct {
Setup *TemplateSetup `json:"setup,omitempty" yaml:"setup,omitempty"` // Paths to executable files for post-setup
Ignore *TemplateIgnore `json:"ignore,omitempty" yaml:"ignore,omitempty"` // The files that should be ignored when copying
Labels *TemplateLabel `json:"labels,omitempty" yaml:"labels,omitempty"` // The repository labels
Styles *TemplateStyles `json:"styles,omitempty" yaml:"styles,omitempty"` // The name of the style mapped to the path to the directory
Prompts *TemplatePrompts `json:"prompts,omitempty" yaml:"prompts,omitempty"` // The additional prompts to use
Name types.CleanString `json:"name,omitempty" yaml:"name,omitempty"` // The name of the template
Setup *TemplateSetup `json:"setup,omitempty" yaml:"setup,omitempty"` // Paths to executable files for post-setup
Ignore *TemplateIgnore `json:"ignore,omitempty" yaml:"ignore,omitempty"` // The files that should be ignored when copying
Labels TemplateLabel `json:"labels,omitempty" yaml:"labels,omitempty"` // The repository labels
Styles TemplateStyles `json:"styles" yaml:"styles"` // The name of the style mapped to the path to the directory
Prompts TemplatePrompts `json:"prompts,omitempty" yaml:"prompts,omitempty"` // The additional prompts to use
}

func (t *TemplateJson) Validate(root string) error {
// Ensure that `Name` is required if `Styles` is not present or empty
// If `Styles` is present, `Name` must not be present
if t.Styles == nil || len(*t.Styles) == 0 {
if t.Name == "" {
return fmt.Errorf("'name' is required when 'styles' is not present or empty")
}
} else {
if t.Name != "" {
return fmt.Errorf("'name' must not be present when 'styles' is provided")
}
if len(t.Styles) == 0 {
return fmt.Errorf("'styles' cannot be empty")
}

if t.Setup != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// The current app version
const Version = "0.7.0"
const Version = "0.7.1"
176 changes: 0 additions & 176 deletions template/template.json

This file was deleted.

Loading

0 comments on commit ef3dbca

Please sign in to comment.