Skip to content

Commit bc1ddec

Browse files
committed
feat: add build command
1 parent 4b201ec commit bc1ddec

File tree

5 files changed

+187
-0
lines changed

5 files changed

+187
-0
lines changed

builder/build.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package builder
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/joshmedeski/sesh/v2/model"
7+
)
8+
9+
func determineCmd(b *RealBuilder, path string) []string {
10+
if _, err := b.os.Stat(path + "/Makefile"); err == nil {
11+
return []string{"make", "build"}
12+
}
13+
if _, err := b.os.Stat(path + "/package-lock.json"); err == nil {
14+
return []string{"npm", "run", "build"}
15+
}
16+
if _, err := b.os.Stat(path + "/pnpm-lock.yaml"); err == nil {
17+
return []string{"pnpm", "run", "build"}
18+
}
19+
if _, err := b.os.Stat(path + "/yarn.lock"); err == nil {
20+
return []string{"yarn", "build"}
21+
}
22+
return []string{}
23+
}
24+
25+
func (b *RealBuilder) Build(session model.SeshSession) (string, error) {
26+
cmd := determineCmd(b, session.Path)
27+
if len(cmd) == 0 {
28+
return "", fmt.Errorf("no build command found for path: %s", session.Path)
29+
}
30+
fmt.Println("Building with command:", fmt.Sprintf("%v", cmd))
31+
cmdOutput, err := b.shell.Cmd(cmd[0], cmd[1:]...)
32+
if err != nil {
33+
return "", err
34+
}
35+
return cmdOutput, nil
36+
}

builder/builder.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package builder
2+
3+
import (
4+
"github.com/joshmedeski/sesh/v2/model"
5+
"github.com/joshmedeski/sesh/v2/oswrap"
6+
"github.com/joshmedeski/sesh/v2/shell"
7+
)
8+
9+
type Builder interface {
10+
Build(path model.SeshSession) (string, error)
11+
}
12+
13+
type RealBuilder struct {
14+
os oswrap.Os
15+
shell shell.Shell
16+
}
17+
18+
func NewBuilder(
19+
os oswrap.Os,
20+
shell shell.Shell,
21+
) Builder {
22+
return &RealBuilder{
23+
os,
24+
shell,
25+
}
26+
}

builder/mock_Builder.go

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seshcli/build.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package seshcli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/joshmedeski/sesh/v2/builder"
7+
"github.com/joshmedeski/sesh/v2/lister"
8+
cli "github.com/urfave/cli/v2"
9+
)
10+
11+
func Build(l lister.Lister, b builder.Builder) *cli.Command {
12+
return &cli.Command{
13+
Name: "build",
14+
Aliases: []string{"b"},
15+
Usage: "Builds the current session (Experimental)",
16+
UseShortOptionHandling: true,
17+
Flags: []cli.Flag{},
18+
Action: func(cCtx *cli.Context) error {
19+
session, exists := l.GetAttachedTmuxSession()
20+
if !exists {
21+
return cli.Exit("No tmux session currently attached", 1)
22+
}
23+
out, err := b.Build(session)
24+
if err != nil {
25+
return cli.Exit(err, 1)
26+
}
27+
fmt.Print(out)
28+
return nil
29+
},
30+
}
31+
}

seshcli/seshcli.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/urfave/cli/v2"
77

8+
"github.com/joshmedeski/sesh/v2/builder"
89
"github.com/joshmedeski/sesh/v2/cloner"
910
"github.com/joshmedeski/sesh/v2/configurator"
1011
"github.com/joshmedeski/sesh/v2/connector"
@@ -63,6 +64,7 @@ func App(version string) cli.App {
6364
startup := startup.NewStartup(config, lister, tmux)
6465
namer := namer.NewNamer(path, git, home)
6566
connector := connector.NewConnector(config, dir, home, lister, namer, startup, tmux, zoxide, tmuxinator)
67+
builder := builder.NewBuilder(os, shell)
6668
icon := icon.NewIcon(config)
6769
previewer := previewer.NewPreviewer(lister, tmux, icon, dir, home, ls, config, shell)
6870
cloner := cloner.NewCloner(connector, git)
@@ -72,6 +74,7 @@ func App(version string) cli.App {
7274
Version: version,
7375
Usage: "Smart session manager for the terminal",
7476
Commands: []*cli.Command{
77+
Build(lister, builder),
7578
List(icon, json, lister),
7679
Last(lister, tmux),
7780
Connect(connector, icon, dir),

0 commit comments

Comments
 (0)