-
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 6 commits
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -526,6 +526,60 @@ _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
|
||||||||||||||
| if [[ ! "$name" =~ ^[a-zA-Z0-9_-]+$ ]]; then | ||||||||||||||
| echo "Error: project name must contain only alphanumerics, hyphens, and underscores" | ||||||||||||||
| return 1 | ||||||||||||||
|
Comment on lines
+554
to
+556
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 pattern
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: utility.sh
Line: 536-538
Comment:
**Regex permits names starting with `-`**
The pattern `^[a-zA-Z0-9_-]+$` allows project names that begin with a hyphen (e.g., `-myapp`, `--help`). Although most path-based operations are safe once a `/` is present in the full path, some downstream tools called with a bare `$name` (e.g., tools that don't use `--`) could misinterpret it as a flag. Anchoring the first character to an alphanumeric avoids the ambiguity:
```suggestion
if [[ ! "$name" =~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]]; then
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||
| fi | ||||||||||||||
| if [[ -d "$name" ]]; then | ||||||||||||||
| echo "Error: directory '$name' already exists" | ||||||||||||||
| return 1 | ||||||||||||||
| fi | ||||||||||||||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| if [[ "$_U7_DRY_RUN" == "1" ]]; then | ||||||||||||||
| echo "[dry-run] Create $tmpl project: $name" | ||||||||||||||
| return 0 | ||||||||||||||
| fi | ||||||||||||||
| case "$tmpl" in | ||||||||||||||
| python) | ||||||||||||||
| 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_require jq || return 1 | ||||||||||||||
| mkdir -p "$name/src" "$name/test" | ||||||||||||||
| echo "# $name" > "$name/README.md" | ||||||||||||||
| jq -n --arg name "$name" '{"name": $name, "version": "0.1.0", "main": "src/index.js"}' > "$name/package.json" | ||||||||||||||
| echo "// $name" > "$name/src/index.js" | ||||||||||||||
| echo "Created Node project: $name" | ||||||||||||||
| ;; | ||||||||||||||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| bash) | ||||||||||||||
| mkdir -p "$name" | ||||||||||||||
| echo "# $name" > "$name/README.md" | ||||||||||||||
| printf '#!/usr/bin/env bash\nset -euo pipefail\n\necho '\''Hello from %s'\''\n' "$name" > "$name/main.sh" | ||||||||||||||
| chmod +x "$name/main.sh" | ||||||||||||||
| echo "Created Bash project: $name" | ||||||||||||||
| ;; | ||||||||||||||
| web) | ||||||||||||||
| mkdir -p "$name/css" "$name/js" | ||||||||||||||
| local escaped_name="${name//</<}" | ||||||||||||||
| escaped_name="${escaped_name//>/>}" | ||||||||||||||
|
Comment on lines
+591
to
+592
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
Suggested change
Removing the dead escaping also makes it immediately obvious that the name is safe to embed directly, thanks to the earlier validation guard. Prompt To Fix With AIThis is a comment left during a code review.
Path: utility.sh
Line: 573-574
Comment:
**HTML escaping is now dead code**
The `<` → `<` and `>` → `>` substitutions on these two lines can never trigger because the input validation on line 536 (`^[a-zA-Z0-9_-]+$`) already rejects any name containing `<`, `>`, or `&`. The `escaped_name` variable is identical to `$name` in every reachable code path, so the variable and both assignments can be removed:
```suggestion
echo "<!DOCTYPE html><html><head><title>$name</title><link rel=\"stylesheet\" href=\"css/style.css\"></head><body><h1>$name</h1><script src=\"js/main.js\"></script></body></html>" > "$name/index.html"
```
Removing the dead escaping also makes it immediately obvious that the name is safe to embed directly, thanks to the earlier validation guard.
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||
| echo "<!DOCTYPE html><html><head><title>$escaped_name</title><link rel=\"stylesheet\" href=\"css/style.css\"></head><body><h1>$escaped_name</h1><script src=\"js/main.js\"></script></body></html>" > "$name/index.html" | ||||||||||||||
|
Comment on lines
+591
to
+593
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 previous fix added <title>foo & bar</title>
<h1>foo & bar</h1>A bare
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: utility.sh
Line: 569-571
Comment:
**`&` not escaped in HTML template (incomplete fix)**
The previous fix added `<` → `<` and `>` → `>` escaping, but `&` → `&` is still missing. This means a project name like `foo & bar` will produce:
```html
<title>foo & bar</title>
<h1>foo & bar</h1>
```
A bare `&` not followed by a valid entity reference is technically invalid HTML and can cause browsers to issue parse warnings. Additionally, the `&` substitution **must happen first** — if it were added after the current `<`/`>` substitutions, the `<` and `>` sequences already written would get double-encoded into `&lt;` / `&gt;`.
```suggestion
local escaped_name="${name//&/&}"
escaped_name="${escaped_name//</<}"
escaped_name="${escaped_name//>/>}"
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||
| touch "$name/css/style.css" "$name/js/main.js" | ||||||||||||||
| echo "Created Web project: $name" | ||||||||||||||
| ;; | ||||||||||||||
| *) echo "Unknown template: $tmpl. Available: python, node, bash, web" ; return 1 ;; | ||||||||||||||
| esac | ||||||||||||||
| ;; | ||||||||||||||
|
|
||||||||||||||
| sequence) | ||||||||||||||
| if [[ "$1" != "with" || "$2" != "prefix" ]]; then | ||||||||||||||
| echo "Usage: u7 mk sequence with prefix <prefix> limit <N>" | ||||||||||||||
|
|
@@ -557,6 +611,7 @@ Entities: | |||||||||||||
| link <source> to <destination> Create symbolic link | ||||||||||||||
| archive <output> from <files...> Create archive from <files...> to <output> | ||||||||||||||
| clone <repo> [to <directory>] Git clone a repository | ||||||||||||||
| template <python|node|bash|web> <name> Scaffold a project structure | ||||||||||||||
| sequence with prefix <prefix> limit <N> Generate numbered sequence with prefix <prefix> and limit <N> | ||||||||||||||
| EOF | ||||||||||||||
| ;; | ||||||||||||||
|
|
||||||||||||||
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 Node.js template is incomplete. The scaffolding logic also creates a
README.mdfile and atestdirectory, but this test doesn't verify their existence. Expanding the check will make the test more robust.