-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add mk template for scaffolding project structures #40
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
Changes from 1 commit
f874908
6700684
e8fb5c4
128a0dd
351cb79
05e9656
f3c0163
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -838,6 +838,31 @@ else | |||||
| ((PASSED++)) | ||||||
| fi | ||||||
|
|
||||||
| # Test: mk template python | ||||||
| cd "$TEST_DIR" | ||||||
| u7 mk template python myapp >/dev/null 2>&1 | ||||||
| if [[ -f "myapp/src/main.py" && -f "myapp/README.md" && -f "myapp/tests/__init__.py" ]]; then | ||||||
| echo -e "${GREEN}✓${NC} mk template python works" | ||||||
| ((PASSED++)) | ||||||
| else | ||||||
| echo -e "${RED}✗${NC} mk template python failed" | ||||||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| ((FAILED++)) | ||||||
| fi | ||||||
|
|
||||||
| # Test: mk template node | ||||||
| u7 mk template node mynode >/dev/null 2>&1 | ||||||
| if [[ -f "mynode/package.json" && -f "mynode/src/index.js" ]]; then | ||||||
|
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. This test for the Node.js template is incomplete. The scaffolding logic also creates a
Suggested change
|
||||||
| echo -e "${GREEN}✓${NC} mk template node works" | ||||||
| ((PASSED++)) | ||||||
| else | ||||||
| echo -e "${RED}✗${NC} mk template node failed" | ||||||
| ((FAILED++)) | ||||||
| fi | ||||||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| # Test: mk template requires args | ||||||
| result=$(u7 mk template 2>&1) | ||||||
| assert_contains "mk template requires args" "Usage:" "$result" | ||||||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+841
to
+883
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. The test coverage for the new
|
||||||
|
|
||||||
| # Cleanup | ||||||
| cd / | ||||||
| rm -rf "$TEST_DIR" | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -526,6 +526,45 @@ _u7_make() { | |||||
| fi | ||||||
| ;; | ||||||
|
|
||||||
| template) | ||||||
| local tmpl="$1" | ||||||
| local name="$2" | ||||||
| if [[ -z "$tmpl" || -z "$name" ]]; then | ||||||
| echo "Usage: u7 mk template <python|node|bash|web> <project-name>" | ||||||
| return 1 | ||||||
| fi | ||||||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| case "$tmpl" in | ||||||
| python) | ||||||
| _u7_exec mkdir -p "$name/src" "$name/tests" | ||||||
| echo "# $name" > "$name/README.md" | ||||||
| echo "#!/usr/bin/env python3" > "$name/src/main.py" | ||||||
| touch "$name/src/__init__.py" "$name/tests/__init__.py" | ||||||
| echo "Created Python project: $name" | ||||||
| ;; | ||||||
| node) | ||||||
| _u7_exec mkdir -p "$name/src" "$name/test" | ||||||
| echo "# $name" > "$name/README.md" | ||||||
| echo '{"name": "'"$name"'", "version": "0.1.0", "main": "src/index.js"}' > "$name/package.json" | ||||||
|
||||||
| echo '{"name": "'"$name"'", "version": "0.1.0", "main": "src/index.js"}' > "$name/package.json" | |
| echo '{"name": "'"${name//\"/\\\"}"'", "version": "0.1.0", "main": "src/index.js"}' > "$name/package.json" |
greptile-apps[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
The project name is not escaped when being inserted into package.json. If the project name contains a double quote, it will result in an invalid JSON file. You should use a tool like jq to safely generate the JSON. Since jq seems to be a dependency for other parts of the script, you could use it like this: jq -n --arg name "$name" '{name: $name, version: "0.1.0", main: "src/index.js"}' > "$name/package.json"
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
greptile-apps[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
greptile-apps[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
The project name is directly embedded into the HTML content without escaping. This creates a Cross-Site Scripting (XSS) vulnerability. If a project name contains HTML tags (e.g., <script>...), they will be rendered by the browser.
You should HTML-escape the $name variable before using it. A simple approach in bash is to replace special characters:
local name_html_escaped="$name"
name_html_escaped="${name_html_escaped//&/&}"
name_html_escaped="${name_html_escaped//</<}"
name_html_escaped="${name_html_escaped//>/>}"
# ... and then use $name_html_escaped in the echo command.
greptile-apps[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
The project name is not escaped when being inserted into index.html. If the project name contains HTML special characters like < or >, it will result in an invalid or malformed HTML file. The project name should be HTML-escaped before being embedded in the title and body. You can use sed for basic escaping, for example: escaped_name=$(printf '%s' "$name" | sed 's/&/\&/g; s/</\</g; s/>/\>/g;')
Outdated
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.
The usage message here is identical to the one on line 533. This duplication can make maintenance harder. To improve clarity, consider making this error message more specific to an invalid template type, distinguishing it from the missing-argument error.
| *) echo "Usage: u7 mk template <python|node|bash|web> <project-name>" ; return 1 ;; | |
| *) echo "Error: Invalid template type '$tmpl'. Must be one of python, node, bash, web." ; return 1 ;; |
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.
This test for the Python template is incomplete. The scaffolding logic creates
src/__init__.py, but this check doesn't verify its existence. Adding this check will make the test more thorough and prevent future regressions.