feat(09-03): scaffold Winter admin controller layout
- config_form.yaml and config_list.yaml point at models/<name>/fields.yaml and columns.yaml - Duplicate model or controller assets fail before any new file is written
This commit is contained in:
@@ -27,6 +27,8 @@ type artifactData struct {
|
||||
Worker string
|
||||
Kind string
|
||||
ConfigDir string
|
||||
PluginPath string
|
||||
Snake string
|
||||
MigrationID string
|
||||
UpSQL string
|
||||
DownSQL string
|
||||
@@ -246,20 +248,33 @@ func MakeAdminController(ctx context.Context, startDir, pluginID, name string) (
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
configDir := filepath.ToSlash(filepath.Join("controllers", snake))
|
||||
fieldsRel := filepath.Join("controllers", snake, "fields.yaml")
|
||||
columnsRel := filepath.Join("controllers", snake, "columns.yaml")
|
||||
for _, yamlRel := range []string{fieldsRel, columnsRel} {
|
||||
formRel := filepath.Join("controllers", snake, "config_form.yaml")
|
||||
listRel := filepath.Join("controllers", snake, "config_list.yaml")
|
||||
fieldsRel := filepath.Join("models", snake, "fields.yaml")
|
||||
columnsRel := filepath.Join("models", snake, "columns.yaml")
|
||||
for _, yamlRel := range []string{formRel, listRel, fieldsRel, columnsRel} {
|
||||
if err := rejectDuplicateFile(plugin.Dir, yamlRel); err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
}
|
||||
src, err := renderStub("admin_controller.go", artifactData{
|
||||
Ident: name,
|
||||
Func: fn,
|
||||
Worker: unexportedIdent(name) + "Admin",
|
||||
Kind: plugin.ID + "." + snake,
|
||||
ConfigDir: configDir,
|
||||
})
|
||||
data := artifactData{
|
||||
Ident: name,
|
||||
Func: fn,
|
||||
Worker: unexportedIdent(name) + "Admin",
|
||||
Kind: plugin.ID + "." + snake,
|
||||
ConfigDir: configDir,
|
||||
PluginPath: strings.ReplaceAll(plugin.ID, ".", "/"),
|
||||
Snake: snake,
|
||||
}
|
||||
src, err := renderStub("admin_controller.go", data)
|
||||
if err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
formSrc, err := renderStub("config_form.yaml", data)
|
||||
if err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
listSrc, err := renderStub("config_list.yaml", data)
|
||||
if err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
@@ -286,16 +301,21 @@ func MakeAdminController(ctx context.Context, startDir, pluginID, name string) (
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
created = append(created, goPath)
|
||||
fieldsPath := filepath.Join(plugin.Dir, fieldsRel)
|
||||
if err := writeFile(fieldsPath, fieldsSrc); err != nil {
|
||||
return ArtifactResult{}, err
|
||||
for _, item := range []struct {
|
||||
rel string
|
||||
body []byte
|
||||
}{
|
||||
{formRel, formSrc},
|
||||
{listRel, listSrc},
|
||||
{fieldsRel, fieldsSrc},
|
||||
{columnsRel, columnsSrc},
|
||||
} {
|
||||
path := filepath.Join(plugin.Dir, item.rel)
|
||||
if err := writeFile(path, item.body); err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
created = append(created, path)
|
||||
}
|
||||
created = append(created, fieldsPath)
|
||||
columnsPath := filepath.Join(plugin.Dir, columnsRel)
|
||||
if err := writeFile(columnsPath, columnsSrc); err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
created = append(created, columnsPath)
|
||||
if err := finishArtifact(ctx, plugin); err != nil {
|
||||
return ArtifactResult{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user