-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnode_application_finder.go
47 lines (36 loc) · 1.13 KB
/
node_application_finder.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
package nodestart
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/paketo-buildpacks/packit/v2"
)
type NodeApplicationFinder struct{}
func NewNodeApplicationFinder() NodeApplicationFinder {
return NodeApplicationFinder{}
}
func (n NodeApplicationFinder) Find(workingDir, launchpoint, projectPath string) (string, error) {
if launchpoint != "" {
if _, err := os.Stat(filepath.Join(workingDir, launchpoint)); err != nil {
if errors.Is(err, os.ErrNotExist) {
return "", fmt.Errorf("expected value derived from BP_LAUNCHPOINT [%s] to be an existing file", launchpoint)
}
return "", err
}
return filepath.Clean(launchpoint), nil
}
files := []string{"server.js", "app.js", "main.js", "index.js"}
for _, file := range files {
_, err := os.Stat(filepath.Join(workingDir, projectPath, file))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
continue
}
return "", err
}
return filepath.Join(projectPath, file), nil
}
return "", packit.Fail.WithMessage("could not find app in %s: expected one of %s", filepath.Clean(filepath.Join(workingDir, projectPath)), strings.Join(files, " | "))
}