Skip to content

Commit

Permalink
feat: Add Installation Command (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Luca Lanziani <luca@lanziani.com>
  • Loading branch information
amanvr and LucaLanziani authored May 26, 2023
1 parent aa2b6d2 commit 233f4bd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/docker/Dockerfile.node.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:{{ or .RuntimeVersion .DefaultRuntimeVersion }} AS build-env
COPY . /src
WORKDIR /src
RUN npm i
RUN {{ .NodeInstallCommand }}
RUN npm run build --if-present
RUN npm test

Expand Down
9 changes: 9 additions & 0 deletions src/services/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,12 @@ func ProjectInit(options InitOptions, resources fs.FS) ([]string, error) {

return append(returnData, destinationFile), nil
}

func (proj Project) NodeInstallCommand() string {
installCommand := "npm i"

if _, err := os.Stat(path.Join(proj.Directory, "package-lock.json")); err == nil {
installCommand = "npm ci"
}
return installCommand
}
32 changes: 32 additions & 0 deletions src/services/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,35 @@ func TestInit(t *testing.T) {

}
}

func TestNodeInstallCommand(t *testing.T) {

for project_type, props := range projects {
proj := Project{
Name: string(project_type),
Directory: path.Join(root, props["directory"]),
Resources: os.DirFS(root),
}

if (project_type == NodeProject) {
expected := "npm i"
installCommand := proj.NodeInstallCommand()
if (installCommand != expected) {
t.Fatalf("Expected '%s', got '%s'", expected, installCommand)
}

packageLockFile := path.Join(root, props["directory"], "package-lock.json")
_, err := os.Create(packageLockFile)
if (err != nil) {
t.Errorf("Failed to create package-lock.json file for testing: %s", err)
}

expected = "npm ci"
installCommand = proj.NodeInstallCommand()
if (installCommand != expected) {
t.Fatalf("Expected '%s', got '%s'", expected, installCommand)
}
os.Remove(packageLockFile)
}
}
}

0 comments on commit 233f4bd

Please sign in to comment.