{ return "tailwind" }
{ return 0 }
{
log.Printf("tailwind: starting build")
bin, err := exec.LookPath("tailwindcss")
if err != nil {
log.Printf("tailwind: tailwindcss not found, please install it manually")
return err
}
cfg := struct {
Input string `json:"input"`
Output string `json:"output"`
Minify bool `json:"minify"`
Args []string `json:"args"`
}{
Input: "index.css",
Output: "tailwind.css",
Minify: true,
}
if len(raw) > 0 {
_ = json.Unmarshal(raw, &cfg)
}
p.output = cfg.Output
args := []string{"-i", cfg.Input, "-o", cfg.Output}
if cfg.Minify {
args = append(args, "--minify")
}
if len(cfg.Args) > 0 {
args = append(args, cfg.Args...)
}
log.Printf("tailwind: running %s %s", bin, strings.Join(args, " "))
cmd := exec.Command(bin, args...)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("tailwind build failed: %s: %w", strings.TrimSpace(string(output)), err)
}
log.Printf("tailwind: build complete")
return nil
}
{
if strings.HasSuffix(path, ".css") && !strings.HasSuffix(path, p.output) {
log.Printf("tailwind: rebuild triggered by %s", path)
return true
}
if strings.HasSuffix(path, ".rtml") || strings.HasSuffix(path, ".html") || strings.HasSuffix(path, ".go") {
log.Printf("tailwind: rebuild triggered by %s", path)
return true
}
return false
}
{
plugins.Register(&plugin{})
}
TestShouldRebuild ensures the plugin's rebuild triggers are detected
correctly based on file paths and extensions.
{
p := &plugin{output: "tailwind.css"}
if !p.ShouldRebuild("style.css") {
t.Fatalf("expected css change to trigger rebuild")
}
if p.ShouldRebuild("tailwind.css") {
t.Fatalf("output file should not trigger rebuild")
}
if !p.ShouldRebuild("index.html") || !p.ShouldRebuild("tmpl.rtml") {
t.Fatalf("html/rtml should trigger rebuild")
}
if !p.ShouldRebuild("main.go") {
t.Fatalf("go files should trigger rebuild")
}
if p.ShouldRebuild("image.png") {
t.Fatalf("unrelated files should not trigger rebuild")
}
}
import "encoding/json"
import "fmt"
import "log"
import "os/exec"
import "strings"
import "github.com/rfwlab/rfw/cmd/rfw/plugins"
import "testing"