-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ft-generate-command-cli'
- Loading branch information
Showing
13 changed files
with
353 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/charmbracelet/log" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
const ( | ||
InstallFrontendDependencies = "npm install" | ||
LaunchDevServer = "npm run dev" | ||
BuildFrontend = "npm run build" | ||
CompileBackend = "mvn compile" | ||
BundleApp = "mvn compile assembly:single" | ||
LaunchApp = "mvn exec:java" | ||
GenerateAppBinds = "mvn exec:java -Dexec.args=\"generate\"" | ||
) | ||
|
||
type Opt = func(cmd *exec.Cmd) | ||
|
||
func WithStdout(cmd *exec.Cmd) { | ||
cmd.Stdout = os.Stdout | ||
} | ||
|
||
func WithStderr(cmd *exec.Cmd) { | ||
cmd.Stderr = os.Stderr | ||
} | ||
|
||
type CmdProps struct { | ||
Cmd string | ||
LogBefore string | ||
Sync bool | ||
Opts []Opt | ||
} | ||
|
||
func Opts(opts ...Opt) []Opt { | ||
var ropts []Opt | ||
for _, o := range opts { | ||
ropts = append(ropts, o) | ||
} | ||
return ropts | ||
} | ||
|
||
func RunCommand(props CmdProps) (*exec.Cmd, error) { | ||
words := strings.Split(props.Cmd, " ") | ||
name := words[0] | ||
args := words[1:] | ||
command := exec.Command(name, args...) | ||
for _, opt := range props.Opts { | ||
opt(command) | ||
} | ||
var err error = nil | ||
log.Info(props.LogBefore) | ||
if props.Sync { | ||
err = command.Run() | ||
} else { | ||
err = command.Start() | ||
} | ||
return command, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import "github.com/charmbracelet/log" | ||
|
||
func Generate() { | ||
_, err := RunCommand(CmdProps{ | ||
Cmd: CompileBackend, | ||
Sync: true, | ||
LogBefore: "Compiling backend code", | ||
Opts: Opts(WithStdout, WithStderr), | ||
}) | ||
if err != nil { | ||
log.Errorf("Error compiling backend code for generate. %v", err) | ||
return | ||
} | ||
|
||
_, err = RunCommand(CmdProps{ | ||
Cmd: GenerateAppBinds, | ||
Opts: Opts(WithStdout, WithStderr), | ||
LogBefore: "Generating bindings.", | ||
Sync: true, | ||
}) | ||
if err != nil { | ||
log.Errorf("Couldn't generate bindings for some reason. %v", err) | ||
return | ||
} | ||
} |
Oops, something went wrong.