This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend.go
69 lines (64 loc) · 1.64 KB
/
frontend.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
package builder
import (
"fmt"
"log"
"os"
"os/exec"
)
const frontendModule = "github.com/yaptide/ui"
func startDevFrontend(conf config) (*exec.Cmd, error) {
cmd := exec.Command("npm", "start")
absolutePath, getPackageErr := getPackagePath(frontendModule)
if getPackageErr != nil {
return nil, getPackageErr
}
cmd.Dir = absolutePath
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("YAPTIDE_BACKEND_PUBLIC_URL=%s", conf.backendPublicUrl))
cmd.Env = append(cmd.Env, fmt.Sprintf("YAPTIDE_FRONTEND_PORT=%d", conf.frontendPort))
cmd.Env = append(cmd.Env, fmt.Sprintf("YAPTIDE_FRONTEND_PUBLIC_URL=%s", conf.frontendPublicUrl))
log.Print(cmd.Env)
return cmd, cmd.Start()
}
func ensureNpm() error {
_, pathErr := exec.LookPath("npm")
if pathErr != nil {
log.Println("Install nvm")
cmd := exec.Command(
"bash",
"-c",
"curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash",
)
runErr := cmd.Run()
if runErr != nil {
return runErr
}
log.Println("Download npm")
if err := exec.Command("nvm", "install", "8").Run(); err != nil {
return err
}
log.Println("Install npm")
if err := exec.Command("nvm", "use", "8").Run(); err != nil {
return err
}
return nil
}
return nil
}
func ensureNpmDeps(importPath string) error {
npmErr := ensureNpm()
if npmErr != nil {
return npmErr
}
cmd := exec.Command("bash", "-c", "npm", "install")
absolutePath, getPackageErr := getPackagePath(importPath)
if getPackageErr != nil {
return getPackageErr
}
cmd.Dir = absolutePath
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}