11package tailwind
22
33import (
4+ "encoding/json"
45 "fmt"
56 "log"
67 "os/exec"
@@ -9,28 +10,45 @@ import (
910 "github.com/rfwlab/rfw/cmd/rfw/plugins"
1011)
1112
12- type plugin struct {}
13+ type plugin struct {
14+ output string
15+ }
1316
1417func init () {
1518 plugins .Register (& plugin {})
1619}
1720
1821func (p * plugin ) Name () string { return "tailwind" }
1922
20- func (p * plugin ) Build () error {
23+ func (p * plugin ) Build (raw json. RawMessage ) error {
2124 log .Printf ("tailwind: starting build" )
2225 bin , err := exec .LookPath ("tailwindcss" )
2326 if err != nil {
2427 log .Printf ("tailwind: tailwindcss not found, please install it manually" )
2528 return err
2629 }
2730
28- // FIXME: in future an rfw project should have a root manifest file with plugins configurations and so on,
29- // for the moment we will look for an input.css file in the project root
30- args := []string {
31- "-i" , "input.css" ,
32- "-o" , "tailwind.css" ,
33- "--minify" ,
31+ cfg := struct {
32+ Input string `json:"input"`
33+ Output string `json:"output"`
34+ Minify bool `json:"minify"`
35+ Args []string `json:"args"`
36+ }{
37+ Input : "index.css" ,
38+ Output : "tailwind.css" ,
39+ Minify : true ,
40+ }
41+ if len (raw ) > 0 {
42+ _ = json .Unmarshal (raw , & cfg )
43+ }
44+ p .output = cfg .Output
45+
46+ args := []string {"-i" , cfg .Input , "-o" , cfg .Output }
47+ if cfg .Minify {
48+ args = append (args , "--minify" )
49+ }
50+ if len (cfg .Args ) > 0 {
51+ args = append (args , cfg .Args ... )
3452 }
3553
3654 log .Printf ("tailwind: running %s %s" , bin , strings .Join (args , " " ))
@@ -43,7 +61,7 @@ func (p *plugin) Build() error {
4361}
4462
4563func (p * plugin ) ShouldRebuild (path string ) bool {
46- if strings .HasSuffix (path , ".css" ) && ! strings .HasSuffix (path , "tailwind.css" ) {
64+ if strings .HasSuffix (path , ".css" ) && ! strings .HasSuffix (path , p . output ) {
4765 log .Printf ("tailwind: rebuild triggered by %s" , path )
4866 return true
4967 }
0 commit comments