tailwind
API
tailwind
packageAPI reference for the tailwind
package.
Imports
(7)
S
struct
plugin
cmd/rfw/plugins/tailwind/tailwind.go:13-15
type plugin struct
Methods
Build
Method
Parameters
raw
json.RawMessage
Returns
error
func (*plugin) Build(raw json.RawMessage) error
{
logging.Log.Info("starting build", logging.F("plugin", "tailwind"))
bin, err := exec.LookPath("tailwindcss")
if err != nil {
logging.Log.Warn("tailwindcss not found, please install it manually", logging.F("plugin", "tailwind"))
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...)
}
logging.Log.Info("running command", logging.F("plugin", "tailwind"), logging.F("bin", bin), logging.F("args", 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)
}
logging.Log.Info("build complete", logging.F("plugin", "tailwind"))
return nil
}
ShouldRebuild
Method
Parameters
path
string
Returns
bool
func (*plugin) ShouldRebuild(path string) bool
{
if strings.HasSuffix(path, ".css") && !strings.HasSuffix(path, p.output) {
logging.Log.Info("rebuild triggered", logging.F("plugin", "tailwind"), logging.F("path", path))
return true
}
if strings.HasSuffix(path, ".rtml") || strings.HasSuffix(path, ".html") || strings.HasSuffix(path, ".go") {
logging.Log.Info("rebuild triggered", logging.F("plugin", "tailwind"), logging.F("path", path))
return true
}
return false
}
Fields
| Name | Type | Description |
|---|---|---|
| output | string |
F
function
init
cmd/rfw/plugins/tailwind/tailwind.go:17-19
func init()
{
plugins.Register(&plugin{})
}
F
function
TestShouldRebuild
TestShouldRebuild ensures the plugin’s rebuild triggers are detected
correctly based on file paths and extensions.
Parameters
t
cmd/rfw/plugins/tailwind/tailwind_test.go:7-25
func TestShouldRebuild(t *testing.T)
{
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")
}
}