Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ To help you start building real-world applications, we've created Kool Presets a
- **Node**: [NestJS](docs/03-Presets/NestJS.md), [AdonisJs](docs/03-Presets/AdonisJs.md), [Express.js](/docs/03-Presets/ExpressJS.md)
- **PHP**: [Laravel](docs/03-Presets/Laravel.md), [Laravel Octane](docs/03-Presets/Laravel+Octane.md), [Symfony](docs/03-Presets/Symfony.md), [CodeIgniter](docs/03-Presets/CodeIgniter.md)
- **Javascript**: [Next.js](docs/03-Presets/NextJS.md), [NuxtJS](docs/03-Presets/NuxtJS.md)
- **Java**: [Java with Gradle](docs/03-Presets/Java.md), [Spring Boot](docs/03-Presets/SpringBoot.md)
- **Others**: [Hugo](docs/03-Presets/Hugo.md), [WordPress](docs/03-Presets/WordPress.md)

#### Monorepo structures
Expand Down
33 changes: 33 additions & 0 deletions core/automate/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const (
TypePrompt
TypeRecipe
TypeMerge
TypeInput
TypeAPI
TypeReplace
)

// ActionSet represents a set of single actions or a question
Expand All @@ -34,8 +37,26 @@ type Action struct {
Scripts []string `yaml:"scripts"`
// prompt
Prompt string `yaml:"prompt"`
Input string `yaml:"input"`
Default string `yaml:"default"`
Options []*ActionSet `yaml:"options"`
// api
API string `yaml:"api"`
Prompts []*APIField `yaml:"prompts"`
// replace
Replace string `yaml:"replace"`
}

// APIField describes a prompt backed by a field in an API response.
type APIField struct {
Path string `yaml:"path"`
Options string `yaml:"options"`
Value string `yaml:"value"`
Label string `yaml:"label"`
Default string `yaml:"default"`
Prompt string `yaml:"prompt"`
Ref string `yaml:"ref"`
Multiple bool `yaml:"multiple"`
}

// Type tells the actual implementation of this action
Expand All @@ -56,9 +77,21 @@ func (a *Action) Type() ActionType {
return TypePrompt
}

if a.Input != "" {
return TypeInput
}

if a.Merge != "" {
return TypeMerge
}

if a.API != "" {
return TypeAPI
}

if a.Replace != "" {
return TypeReplace
}

return TypeUnknown
}
54 changes: 54 additions & 0 deletions core/automate/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,60 @@ func TestParseActionPrompt(t *testing.T) {
})
}

func TestParseActionInput(t *testing.T) {
a := parseAction("input: 'Project name'\nref: 'PROJECT_NAME'\ndefault: 'application'", t)

if a.Input != "Project name" || a.Ref != "PROJECT_NAME" || a.Default != "application" {
t.Errorf("failed parsing ActionInput: %v", a)
}
if a.Type() != TypeInput {
t.Errorf("failed parsing ActionInput type; got: %v", a.Type())
}
}

func TestParseActionAPI(t *testing.T) {
a := parseAction("api: 'https://example.test/options'\nprompts:\n - path: 'data'\n options: 'items'\n value: 'key'\n label: 'title'\n multiple: true", t)

if a.API == "" || len(a.Prompts) != 1 || a.Prompts[0].Options != "items" || !a.Prompts[0].Multiple {
t.Errorf("failed parsing ActionAPI: %v", a)
}
if a.Type() != TypeAPI {
t.Errorf("failed parsing ActionAPI type; got: %v", a.Type())
}
}

func TestParseActionReplace(t *testing.T) {
a := parseAction("replace: 'JAVA_VERSION $JAVA_VERSION'", t)

if a.Replace != "JAVA_VERSION $JAVA_VERSION" {
t.Errorf("failed parsing ActionReplace: %v", a)
}
if a.Type() != TypeReplace {
t.Errorf("failed parsing ActionReplace type; got: %v", a.Type())
}
}

func TestAPIOptions(t *testing.T) {
data := map[string]any{
"data": map[string]any{
"default": "two",
"items": []any{
map[string]any{"key": "one", "title": "One"},
map[string]any{"key": "two", "title": "Two"},
},
},
}
options, defaultValue, err := apiOptions(data, &APIField{
Path: "data",
Options: "items",
Value: "key",
Label: "title",
})
if err != nil || len(options) != 2 || options[1].Value != "two" || defaultValue != "two" {
t.Errorf("unexpected API options: options=%v default=%q err=%v", options, defaultValue, err)
}
}

func TestParseActionMerge(t *testing.T) {
t.Run("Parse merge basic", func(t *testing.T) {
a := parseAction("merge: 'foo'", t)
Expand Down
Loading
Loading