-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: frontend js project type #135
Open
Pehesi97
wants to merge
20
commits into
main
Choose a base branch
from
feat/issue-134
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
22ab806
feat: frontend js project type
Pehesi97 eef1ba3
fix: npm i command
Pehesi97 52a88b8
fix: frontend tests
Pehesi97 e94eb6d
fix: newline on docker templates
Pehesi97 060b600
fix: create dist folder in example frontend project
Pehesi97 4077dd8
fix: improve frontend detection
Pehesi97 c8191c1
fix: using user node
Pehesi97 a1c0c6e
fix: docker template test
Pehesi97 84b5982
fix: expose frontend port
Pehesi97 8d089ab
fix: expected frontend docker template
Pehesi97 a04fb6a
fix: expose build folder
Pehesi97 7919cd0
fix: env ci true
Pehesi97 2ecb927
fix: expected image template test
Pehesi97 9672bf1
fix: reverting to default knative service port on frontend
Pehesi97 616491c
fix: detect frontend frameworks only in node dependencies
Pehesi97 e4c7529
docs: fix frontend type in readme
Pehesi97 ea6d1ba
fix: use the default port or process.env.PORT
Pehesi97 9a93d51
fix: changing CMD to ENTRYPOINT
Pehesi97 2fd755a
fix: dependencies object format
Pehesi97 c62cbc3
fix: json unmarshalling
Pehesi97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ Dockerfile.initium | |
*.init_test* | ||
initium_onmain.yaml | ||
initium_onbranch.yaml | ||
dist/ | ||
/dist | ||
|
||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM node:{{ or .RuntimeVersion .DefaultRuntimeVersion }} AS build-env | ||
|
||
ENV CI=true | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json tsconfig*.json ./ | ||
|
||
RUN {{ .NodeInstallCommand }} | ||
|
||
COPY . . | ||
|
||
RUN npm run build --if-present | ||
RUN npm test | ||
|
||
FROM node:{{ or .RuntimeVersion .DefaultRuntimeVersion }} | ||
|
||
COPY --from=build-env /app /app | ||
|
||
WORKDIR /app | ||
|
||
USER node | ||
|
||
ENTRYPOINT npx http-server ./build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Initium Frontend Sample</title> | ||
</head> | ||
|
||
<body> | ||
Welcome to Initium! | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "frontend-js", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@testing-library/jest-dom": "^5.17.0", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^13.5.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "5.0.1", | ||
"web-vitals": "^2.1.4" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,12 @@ package project | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/nearform/initium-cli/src/services/git" | ||
|
@@ -15,8 +17,9 @@ import ( | |
type ProjectType string | ||
|
||
const ( | ||
NodeProject ProjectType = "node" | ||
GoProject ProjectType = "go" | ||
NodeProject ProjectType = "node" | ||
GoProject ProjectType = "go" | ||
FrontendJsProject ProjectType = "frontend-js" | ||
) | ||
|
||
type Project struct { | ||
|
@@ -65,6 +68,8 @@ func IsValidProjectType(projectType string) bool { | |
return true | ||
case string(GoProject): | ||
return true | ||
case string(FrontendJsProject): | ||
return true | ||
default: | ||
return false | ||
} | ||
|
@@ -74,8 +79,28 @@ func DetectType(directory string) (ProjectType, error) { | |
var detectedRuntimes []ProjectType | ||
var projectType ProjectType | ||
if _, err := os.Stat(path.Join(directory, "package.json")); err == nil { | ||
detectedRuntimes = append(detectedRuntimes, NodeProject) | ||
projectType = NodeProject | ||
bytes, err := os.ReadFile(path.Join(directory, "package.json")) | ||
var result map[string]any | ||
json.Unmarshal(bytes, &result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lack error validation |
||
dependencies := result["dependencies"].(map[string]any) | ||
|
||
if err != nil { | ||
fmt.Print(err) | ||
} | ||
|
||
frontendDetected := false | ||
for dependency := range dependencies { | ||
if strings.Contains(string(dependency), "react") || strings.Contains(string(dependency), "angular") || strings.Contains(string(dependency), "vue") { | ||
frontendDetected = true | ||
} | ||
} | ||
if frontendDetected { | ||
detectedRuntimes = append(detectedRuntimes, FrontendJsProject) | ||
projectType = FrontendJsProject | ||
} else { | ||
detectedRuntimes = append(detectedRuntimes, NodeProject) | ||
projectType = NodeProject | ||
} | ||
} | ||
if _, err := os.Stat(path.Join(directory, "go.mod")); err == nil { | ||
detectedRuntimes = append(detectedRuntimes, GoProject) | ||
|
@@ -98,6 +123,9 @@ func (proj *Project) setRuntimeVersion() error { | |
case GoProject: | ||
proj.DefaultRuntimeVersion = defaults.DefaultGoRuntimeVersion | ||
return nil | ||
case FrontendJsProject: | ||
proj.DefaultRuntimeVersion = defaults.DefaultFrontendJsRuntimeVersion | ||
return nil | ||
default: | ||
return fmt.Errorf("cannot detect runtime version for project type %s", proj.Type) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add an actual basic react code here?