gitstack

grindlemire/gothem-stack code browser

1.2 KB Go 63 lines 2025-01-11 · 04d4ded raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main

import (
	"context"

	"github.com/grindlemire/gothem-stack/magefiles/cmd"

	"go.uber.org/zap"
)

func run(ctx context.Context) error {
	config, err := GetConfig(ctx)
	if err != nil {
		return err
	}

	zap.S().Infof("mage running with config: %+v", config)

	// tailwindcss will recompute and compile the necessary styles if any of the
	// classes change in the templ files
	go func() {
		err = cmd.Run(ctx,
			cmd.WithDir("./web"),
			cmd.WithCMD(
				"node_modules/.bin/tailwindcss",
				"-i", "tailwind.css",
				"-o", "public/styles.min.css",
				"--watch",
			),
		)
	}()

	// templ watch will watch for changes to templ files and regenerate the code
	// as necessary
	go func() {
		err = cmd.Run(ctx,
			cmd.WithCMD(
				"templ",
				"generate",
				"--watch",
				`--proxy=http://localhost:4433`,
				"--open-browser=false",
			),
		)
		if err != nil {
			zap.S().Errorf("Error running templ watch: %v", err)
		}
	}()

	// air will restart the main binary when it detects a change
	// to a templ or go file.
	err = cmd.Run(ctx,
		cmd.WithCMD(
			"air",
			"-c", ".air.toml",
		),
	)
	if err != nil {
		zap.S().Errorf("Error running air server: %v", err)
	}
	return err

}