-
Notifications
You must be signed in to change notification settings - Fork 6
add react extension as template #4
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
Conversation
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.
Copying files directly creates a maintenance burden when the source template changes.
Possible better approaches:
Option 1: Git Submodule (Recommended)
git submodule add https://github.com/Comfy-Org/ComfyUI-React-Extension-Template react-template-source
Then copy/transform files at generation time in hooks/post_gen_project.py
Option 2: Runtime Git Clone
Clone the latest template during cookiecutter execution in pre-generation hooks
Option 3: Template Registry
Reference templates by URL/commit in cookiecutter.json and fetch dynamically
The submodule approach keeps templates synchronized automatically while allowing version pinning and maintaining git attribution.
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.
To clarify - the suggested approaches would still support the processing steps listedn in PR description:
With Git Submodule approach:
- Keep your
common/
folder structure for shared files - Use submodule as source, then in
hooks/post_gen_project.py
:- Copy files from submodule to target locations
- Apply cookiecutter variable substitutions programmatically
- Handle the
_copy_without_render
logic for .tsx/.ts files
Key advantage: When the source React template updates, you just git submodule update
and the processing logic handles the new files automatically, rather than manually syncing copied files.
The folder structure and frontend_type logic you've designed is solid - it's just about changing the source of the react template files from static copies to a dynamic reference.
@christian-byrne I tried your option1 - git submodule, but there is one issue, it is unable to use the way |
Thanks for implementing the submodule approach! I see the `--recurse-submodules` requirement is limiting the GitHub usage. Here are the main options with detailed implementation steps: Option 1: Download during generation (recommended)No releases/tags needed - downloads directly from main branch Implementation:
import os
import shutil
import urllib.request
import zipfile
import tempfile
if "{{ cookiecutter.frontend_type }}" == "react":
# Download from main branch
url = "https://github.com/Comfy-Org/ComfyUI-React-Extension-Template/archive/refs/heads/main.zip"
with tempfile.TemporaryDirectory() as temp_dir:
# Download and extract
zip_path = os.path.join(temp_dir, "template.zip")
urllib.request.urlretrieve(url, zip_path)
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
# Copy files to project, replacing cookiecutter variables
template_dir = os.path.join(temp_dir, "ComfyUI-React-Extension-Template-main")
# Process and copy files...
Benefits:
Option 2: Use releases/tags (if version control needed)Requires setting up releases in template repos first Implementation:
url = "https://github.com/Comfy-Org/ComfyUI-React-Extension-Template/archive/refs/tags/v1.0.0.zip"
Option 3: Keep submodules but document usage
Option 4: Copy files and make GH workflow to update from template repos:Template repos can add on:
push:
branches: [main]
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Trigger cookiecutter update
run: < /dev/null |
# Create PR to cookiecutter repo notifying of changes Recommendation:I recommend Option 1 - it's the simplest to implement and maintain while preserving the GitHub usage pattern users expect. No need to set up releases immediately, and template repos stay independent. Feel free to implement whichever approach works best for your workflow! Happy to help with the implementation details if needed. |
@christian-byrne I am still figuring out submodule way, it may work, (using my own repo as testing) I will ping you soon about the results |
Nice, sounds good. Just go with what you think is best, I trust! |
@christian-byrne I implemented react by git submodule.
Pre-gen-project:
Post-gen-project:
|
I'll test it quickly then merge |
Nice, I tested it and it works. Thank you! Testing steps:
|
add react extension (original is from https://github.com/Comfy-Org/ComfyUI-React-Extension-Template) as template, key changes are: