Skip to content

Commit 4c5c1af

Browse files
committed
tsunami_distpath
1 parent eabda0d commit 4c5c1af

3 files changed

Lines changed: 50 additions & 10 deletions

File tree

tsunami/build/build.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
)
1313

1414
type BuildOpts struct {
15-
Dir string
16-
Verbose bool
15+
Dir string
16+
Verbose bool
17+
DistPath string
1718
}
1819

1920
func verifyEnvironment(verbose bool) error {
@@ -130,6 +131,33 @@ func verifyTsunamiDir(dir string) error {
130131
return nil
131132
}
132133

134+
func verifyDistPath(distPath string) error {
135+
if distPath == "" {
136+
return fmt.Errorf("distPath cannot be empty")
137+
}
138+
139+
// Check if directory exists
140+
info, err := os.Stat(distPath)
141+
if err != nil {
142+
if os.IsNotExist(err) {
143+
return fmt.Errorf("distPath directory %q does not exist", distPath)
144+
}
145+
return fmt.Errorf("error accessing distPath directory %q: %w", distPath, err)
146+
}
147+
148+
if !info.IsDir() {
149+
return fmt.Errorf("distPath %q is not a directory", distPath)
150+
}
151+
152+
// Check for index.html file
153+
indexPath := filepath.Join(distPath, "index.html")
154+
if err := CheckFileExists(indexPath); err != nil {
155+
return fmt.Errorf("index.html check failed in distPath %q: %w", distPath, err)
156+
}
157+
158+
return nil
159+
}
160+
133161
func TsunamiBuild(opts BuildOpts) error {
134162
if err := verifyEnvironment(opts.Verbose); err != nil {
135163
return err
@@ -139,6 +167,10 @@ func TsunamiBuild(opts BuildOpts) error {
139167
return err
140168
}
141169

170+
if err := verifyDistPath(opts.DistPath); err != nil {
171+
return err
172+
}
173+
142174
// Create temporary directory
143175
tempDir, err := os.MkdirTemp("", "tsunami-build-*")
144176
if err != nil {

tsunami/cmd/main-tsunami.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ var buildCmd = &cobra.Command{
3535
Args: cobra.ExactArgs(1),
3636
Run: func(cmd *cobra.Command, args []string) {
3737
verbose, _ := cmd.Flags().GetBool("verbose")
38+
distPath := os.Getenv("TSUNAMI_DISTPATH")
39+
if distPath == "" {
40+
fmt.Printf("Error: TSUNAMI_DISTPATH environment variable must be set\n")
41+
os.Exit(1)
42+
}
3843
opts := build.BuildOpts{
39-
Dir: args[0],
40-
Verbose: verbose,
44+
Dir: args[0],
45+
Verbose: verbose,
46+
DistPath: distPath,
4147
}
4248
if err := build.TsunamiBuild(opts); err != nil {
4349
fmt.Printf("Build failed: %v\n", err)
@@ -53,9 +59,15 @@ var runCmd = &cobra.Command{
5359
Args: cobra.ExactArgs(1),
5460
Run: func(cmd *cobra.Command, args []string) {
5561
verbose, _ := cmd.Flags().GetBool("verbose")
62+
distPath := os.Getenv("TSUNAMI_DISTPATH")
63+
if distPath == "" {
64+
fmt.Printf("Error: TSUNAMI_DISTPATH environment variable must be set\n")
65+
os.Exit(1)
66+
}
5667
opts := build.BuildOpts{
57-
Dir: args[0],
58-
Verbose: verbose,
68+
Dir: args[0],
69+
Verbose: verbose,
70+
DistPath: distPath,
5971
}
6072
if err := build.TsunamiRun(opts); err != nil {
6173
fmt.Printf("Run failed: %v\n", err)

tsunami/demo/todo/app.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,3 @@ var App = app.DefineComponent("App",
183183
)
184184
},
185185
)
186-
187-
func main() {
188-
app.RunMain()
189-
}

0 commit comments

Comments
 (0)