-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
44 lines (39 loc) · 1.05 KB
/
run.go
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
package main
import (
"context"
"errors"
"github.com/swdunlop/rig-go/rig"
"github.com/swdunlop/rig-go/rig/esbuild"
"github.com/swdunlop/rig-go/rig/golang"
"github.com/swdunlop/zugzug-go"
"github.com/swdunlop/zugzug-go/zug/parser"
)
func init() {
tasks = append(tasks, zugzug.Tasks{
{Name: "run", Use: "Runs a rigged service", Fn: runRig, Parser: parser.New(
parser.String(&wwwDir, "www", "d", "The directory to serve for static files"),
parser.String(&golangPkg, "pkg", "g", "The Go package to serve for API requests"),
parser.String(&esbuildFile, "ui", "u", "The esbuild file to build for the UI"),
)},
}...)
}
func runRig(ctx context.Context) error {
var options []rig.Option
if esbuildFile != "" {
if wwwDir == "" {
return errors.New("esbuild requires a www directory")
}
options = append(options, esbuild.Rig(
esbuild.EntryPoint(esbuildFile),
))
}
if golangPkg != "" {
options = append(options, golang.Rig(golangPkg))
}
return rig.Run(ctx, options...)
}
var (
wwwDir string
golangPkg string
esbuildFile string
)