refactor(tools): modularize CLI with urfave/cli/v2, externalise template metadata
- Split monolithic build-preview.go into modular packages: tools.go (entry), cli/ (list/create/delete/preview commands), config/ (JSON loading), preview/ (rendering engine, funcs, locale) - Extract all template metadata into data/templates_config.json as single source of truth — no hardcoded template data in Go - Replace hand-rolled CLI parsing with github.com/urfave/cli/v2 - Add sensible defaults for --folder (../themes) and --config (./data/templates_config.json) — most commands now run bare - Add type-coercing gt/lt/ge/le template funcs for JSON float64 - Fix AppUrl to gitea.com matching official template convention - rendered.js now exports __REGISTRY__ and __PARAMS__ alongside __RENDERED__ — preview/index.html reads all from single source - Cross-validate all 11 template data contexts against official Gitea source (services/mailer/*.go + templates/mail/*.tmpl) - Update all docs (README, AGENTS, CONTRIBUTING, 5 languages) to reflect new CLI workflow with create scaffolding command Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
77854ee0ed
commit
0bf982ffb9
30 files changed
+1274
-540
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"gitea-mail-templates/tools/preview"
|
||||
)
|
||||
|
||||
// ListCommand returns the "list" subcommand.
|
||||
func ListCommand() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "list",
|
||||
Usage: "List available theme styles in the target folder",
|
||||
UsageText: "go run . list [--folder <themes-dir>]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "folder",
|
||||
Value: "../themes",
|
||||
Usage: "Path to the themes directory",
|
||||
},
|
||||
},
|
||||
Action: runList,
|
||||
}
|
||||
}
|
||||
|
||||
func runList(c *cli.Context) error {
|
||||
folder := c.String("folder")
|
||||
|
||||
themes, err := preview.DiscoverThemes(folder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
absDir, _ := filepath.Abs(folder)
|
||||
fmt.Printf("Available styles in '%s' (%d):\n", filepath.Base(absDir), len(themes))
|
||||
|
||||
sort.Strings(themes)
|
||||
for _, t := range themes {
|
||||
count := 0
|
||||
filepath.Walk(filepath.Join(folder, t), func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if filepath.Ext(path) == ".tmpl" {
|
||||
count++
|
||||
}
|
||||
return nil
|
||||
})
|
||||
fmt.Printf(" %-16s (%d .tmpl files)\n", t, count)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user