package cli import ( "encoding/json" "fmt" "gitea-mail-templates/tools/builder" "gitea-mail-templates/tools/logging" "github.com/urfave/cli/v2" "os" "path/filepath" ) func CreateCommand() *cli.Command { return &cli.Command{Name: "create", Usage: "Create CSS and metadata using the shared control framework", Flags: []cli.Flag{&cli.StringFlag{Name: "folder", Value: "../themes"}}, Action: runCreate} } func runCreate(c *cli.Context) error { names := c.Args().Slice() if len(names) == 0 { return fmt.Errorf("at least one theme name is required") } for _, name := range names { if !builder.ValidName(name) { return fmt.Errorf("invalid theme name %q", name) } dir := filepath.Join(c.String("folder"), name) if _, err := os.Lstat(dir); err == nil { return fmt.Errorf("theme %s already exists", name) } if err := os.MkdirAll(dir, 0755); err != nil { return err } meta, _ := json.MarshalIndent(builder.Theme{Name: name, Description: "New theme", Mode: "framed", Layout: "standard"}, "", " ") if err := os.WriteFile(filepath.Join(dir, "theme.json"), append(meta, '\n'), 0644); err != nil { return err } css := "/* Presentation only; shared controls own mail data and translations. */\nbody { margin:0; padding:24px 16px; background:#f4f6f9; }\nbody, td { font-family:Arial, sans-serif; }\n.email-wrap { max-width:600px; margin:auto; background:#fff; }\n.email-header, .email-card, .email-footer { padding:24px; }\n.email-logo { vertical-align:middle; margin-right:8px; }\n.email-btn,.card-body .email-btn,.card-body .email-btn:visited { display:inline-block; padding:12px 24px; color:#fff!important; background:#2563eb; text-decoration:none; border-radius:6px; }\n.email-link-url { overflow-wrap:anywhere; }\na, a:visited { color:#2563eb; }\n" if err := os.WriteFile(filepath.Join(dir, "theme.css"), []byte(css), 0644); err != nil { return err } logging.Info("CLI", "Created framework theme %s", name) } return nil }