-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
70 lines (62 loc) · 1.25 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/urfave/cli/v2"
"github.com/zbysir/go-vue-ssr/internal/pkg/log"
"github.com/zbysir/go-vue-ssr/internal/pkg/signal"
"github.com/zbysir/go-vue-ssr/internal/version"
"github.com/zbysir/go-vue-ssr/pkg/vuessr"
"os"
)
func main() {
c := cli.NewApp()
c.Name = "go-vue-ssr"
c.Description = "Hey vue go"
c.Version = version.Version
c.Usage = "Vue to Go compiler"
c.Flags = []cli.Flag{
&cli.StringFlag{
Name: "src",
Usage: "The .vue files dir",
},
&cli.StringFlag{
Name: "to",
Value: "./internal/vuetpl",
Usage: "Dist dir",
},
&cli.StringFlag{
Name: "pkg",
Usage: "pkg name",
},
&cli.BoolFlag{
Name: "watch",
Usage: "watch file and rebuild",
},
}
c.Action = func(c *cli.Context) (err error) {
src := c.String("src")
if src == "" {
panic("invalid src")
}
to := c.String("to")
pkg := c.String("pkg")
if c.Bool("watch") {
ctx, cancel := signal.NewTermContext()
defer cancel()
err = vuessr.GenAllFileWithWatch(ctx, src, to, pkg)
if err != nil {
return
}
} else {
err = vuessr.GenAllFile(src, to, pkg)
if err != nil {
return
}
log.Infof("compile success")
}
return
}
err := c.Run(os.Args)
if err != nil {
log.Errorf("%v", err)
}
}