Skip to content

Commit cc81751

Browse files
committed
fix: javascript runtime code as config commands
1 parent 14ef260 commit cc81751

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/runtime/javascript.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/docker/docker/api/types/strslice"
2727

2828
"github.com/nitrictech/boxygen/pkg/backend/dockerfile"
29-
"github.com/nitrictech/cli/pkg/utils"
3029
)
3130

3231
type javascript struct {
@@ -45,7 +44,22 @@ func (t *javascript) ContainerName() string {
4544
}
4645

4746
func (t *javascript) FunctionDockerfileForCodeAsConfig(w io.Writer) error {
48-
return utils.NewNotSupportedErr("code-as-config not supported on " + string(t.rte))
47+
con, err := dockerfile.NewContainer(dockerfile.NewContainerOpts{
48+
From: "node:alpine",
49+
Ignore: []string{"node_modules/", ".nitric/", ".git/", ".idea/"},
50+
})
51+
if err != nil {
52+
return err
53+
}
54+
55+
con.Run(dockerfile.RunOptions{Command: []string{"yarn", "global", "add", "nodemon"}})
56+
con.Config(dockerfile.ConfigOptions{
57+
Entrypoint: []string{"node"},
58+
WorkingDir: "/app/",
59+
})
60+
61+
_, err = w.Write([]byte(strings.Join(con.Lines(), "\n")))
62+
return err
4963
}
5064

5165
func (t *javascript) FunctionDockerfile(funcCtxDir, version, provider string, w io.Writer) error {
@@ -82,8 +96,8 @@ func (t *javascript) FunctionDockerfile(funcCtxDir, version, provider string, w
8296
func (t *javascript) LaunchOptsForFunctionCollect(runCtx string) (LaunchOpts, error) {
8397
return LaunchOpts{
8498
Image: t.DevImageName(),
85-
Entrypoint: strslice.StrSlice{"ts-node"},
86-
Cmd: strslice.StrSlice{"-T " + "/app/" + filepath.ToSlash(t.handler)},
99+
Entrypoint: strslice.StrSlice{"node"},
100+
Cmd: strslice.StrSlice{"/app/" + filepath.ToSlash(t.handler)},
87101
TargetWD: "/app",
88102
Mounts: []mount.Mount{
89103
{
@@ -106,6 +120,6 @@ func (t *javascript) LaunchOptsForFunction(runCtx string) (LaunchOpts, error) {
106120
},
107121
TargetWD: "/app",
108122
Entrypoint: strslice.StrSlice{"nodemon"},
109-
Cmd: strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "--exec", "ts-node -T " + "/app/" + filepath.ToSlash(t.handler)},
123+
Cmd: strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "--exec", "node " + "/app/" + filepath.ToSlash(t.handler)},
110124
}, nil
111125
}

0 commit comments

Comments
 (0)