-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.go
120 lines (111 loc) · 2.56 KB
/
cli.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"fmt"
"internal/commands"
"github.com/urfave/cli/v2"
)
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
func SetupCliApp() (cli.App, error) {
cliCommands := []*cli.Command{
{Name: "create",
Usage: "Create a new application",
Action: func(c *cli.Context) error {
return commands.HandleCreateCommand(c.Args().First())
},
},
{
Name: "dev",
Usage: "This run the app in dev mode with file watching",
Action: func(c *cli.Context) error {
// handle dev
return commands.HandleDevCommand(c.Args().First())
},
},
{
Name: "build",
Usage: "This builds the app for production.",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "dts",
Usage: "Will emit .d.ts files and bundle them",
},
},
Action: func(c *cli.Context) error {
return commands.HandleBuildCommand(c.Args().First(), c.Bool("dts"))
},
},
{
Name: "dts",
Usage: "Emit .d.ts files for package",
Action: func(c *cli.Context) error {
return commands.RunDts()
},
},
{
Name: "prettier",
Usage: "Will run pretty-quick",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "Will prettify all files instead of staged files",
},
},
Action: func(c *cli.Context) error {
return commands.HandlePrettierCommand(c.Bool("all"))
},
},
{
Name: "lint",
Usage: "Will lint the application",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "fix",
Usage: "Will auto fix linter problems",
},
},
Action: func(c *cli.Context) error {
return commands.HandleLintCommand(c.Bool("fix"))
},
},
{
Name: "version",
Usage: "Version of cli",
Aliases: []string{"v"},
Action: func(c *cli.Context) error {
fmt.Printf("tsdev %s, commit %s, built at %s by %s", version, commit, date, builtBy)
return nil
},
},
}
app := &cli.App{
Name: "tsdev",
Commands: cliCommands,
Usage: "Zero config modern typescript tooling",
EnableBashCompletion: true,
ArgsUsage: "Run a .ts file with zero config directly",
Action: func(c *cli.Context) error {
if c.Bool("version") {
fmt.Printf("tsdev %s, commit %s, built at %s by %s", version, commit, date, builtBy)
return nil
} else {
return commands.HandleDefault(c.Bool("watch"), c.Args().Slice())
}
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "watch",
Usage: "Run in watch mode",
},
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
},
},
}
return *app, nil
}