@@ -155,6 +155,18 @@ func verifyDistPath(distPath string) error {
155155 return fmt .Errorf ("index.html check failed in distPath %q: %w" , distPath , err )
156156 }
157157
158+ // Check for templates/tailwind.css file
159+ tailwindPath := filepath .Join (distPath , "templates" , "tailwind.css" )
160+ if err := CheckFileExists (tailwindPath ); err != nil {
161+ return fmt .Errorf ("templates/tailwind.css check failed in distPath %q: %w" , distPath , err )
162+ }
163+
164+ // Check for templates/main.go.tmpl file
165+ mainTmplPath := filepath .Join (distPath , "templates" , "main.go.tmpl" )
166+ if err := CheckFileExists (mainTmplPath ); err != nil {
167+ return fmt .Errorf ("templates/main.go.tmpl check failed in distPath %q: %w" , distPath , err )
168+ }
169+
158170 return nil
159171}
160172
@@ -204,6 +216,46 @@ func TsunamiBuild(opts BuildOpts) error {
204216 if opts .Verbose {
205217 log .Printf ("Copied %d go files, %d static files\n " , goCount , staticCount )
206218 }
219+
220+ // Copy main.go.tmpl from dist/templates to temp dir as main-app.go
221+ mainTmplSrc := filepath .Join (opts .DistPath , "templates" , "main.go.tmpl" )
222+ mainTmplDest := filepath .Join (tempDir , "main-app.go" )
223+ if err := copyFile (mainTmplSrc , mainTmplDest ); err != nil {
224+ return fmt .Errorf ("failed to copy main.go.tmpl: %w" , err )
225+ }
226+
227+ // Generate Tailwind CSS
228+ if err := generateAppTailwindCss (opts .DistPath , tempDir , opts .Verbose ); err != nil {
229+ return fmt .Errorf ("failed to generate tailwind css: %w" , err )
230+ }
231+
232+ return nil
233+ }
234+
235+ func generateAppTailwindCss (distPath , tempDir string , verbose bool ) error {
236+ tailwindInput := filepath .Join (distPath , "templates" , "tailwind.css" )
237+ tailwindOutput := filepath .Join (tempDir , "static" , "tw.css" )
238+ contentGlob := filepath .Join (tempDir , "*.go" )
239+
240+ tailwindCmd := exec .Command ("npx" , "@tailwindcss/cli" ,
241+ "-i" , tailwindInput ,
242+ "-o" , tailwindOutput ,
243+ "--content" , contentGlob )
244+
245+ if verbose {
246+ log .Printf ("Running: %s" , strings .Join (tailwindCmd .Args , " " ))
247+ tailwindCmd .Stdout = os .Stdout
248+ tailwindCmd .Stderr = os .Stderr
249+ }
250+
251+ if err := tailwindCmd .Run (); err != nil {
252+ return fmt .Errorf ("failed to run tailwind command: %w" , err )
253+ }
254+
255+ if verbose {
256+ log .Printf ("Tailwind CSS generated successfully" )
257+ }
258+
207259 return nil
208260}
209261
0 commit comments