-
Notifications
You must be signed in to change notification settings - Fork 9
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(Template): Introduce template for react extensions #69
Merged
Merged
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
03207ea
Created first raw version of react extension
Pive01 a835f75
re-added previous template
Pive01 83b452d
Simply added anything in the build folder
Pive01 73d1e94
Fixed missing files
Pive01 db2e683
Simplified routing patterns
Pive01 4936f16
updated template
Pive01 aad8fe5
Updated base endpoint
Pive01 1fbf3a6
Modified cookiecutter to choose base route based on location
Pive01 4c58937
Added hot reloading to extension UI
Pive01 5c5f9f0
Fixed issue with wrong boolean value
Pive01 7a09a16
Updated README for react extension
Pive01 92e2c76
Updated template to use WebAppExtension class
Pive01 88be707
Removed unnecessary dependencies
Pive01 e6d348c
Added comment
Pive01 b026d1b
Moved templates to allow retro-compatibility
Pive01 a018dec
re-ordered template folders
Pive01 817a16e
Bit of adjustment to packaging and naming
Pive01 182cf2f
Added yarn install warning
Pive01 ec8914e
Updated package.json with new published package
Pive01 28306e3
Update README.md
maxhoheiser b148dcc
changed directory layout for react extension
Pive01 458931f
Apply suggestions from code review
Pive01 9560d22
Address some comments
Pive01 94c9637
Added .gitignore
Pive01 0510550
Addressed more comments
Pive01 5b8aa91
update requirements in base template
Pive01 8911b91
use pyproject.toml for react template
dominikschubert 8517417
extend gitignore for react template
dominikschubert 1067819
install dev version of localstack-core
dominikschubert 0f3229f
Changed other templates from setup to pyproject
Pive01 900077e
Update templates/react/{{cookiecutter.project_slug}}/pyproject.toml
Pive01 b80cc5f
updated pyproject.toml
Pive01 e659844
Added checks for corepack / yarn stuff
Pive01 9f93c0c
added .pth for package discovery
Pive01 b0ced60
Merge remote-tracking branch 'origin/main' into react-template
thrau 859faaf
reset changes to original template
thrau 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Extension Template | ||
================== | ||
|
||
This is a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template that is used when you invoke. | ||
|
||
```console | ||
localstack extensions dev new | ||
``` | ||
|
||
It contains a simple python distribution config, and some boilerplate extension code. |
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,11 @@ | ||
{ | ||
"project_name": "My LocalStack Extension", | ||
"project_short_description": "All the boilerplate you need to create a LocalStack extension.", | ||
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}", | ||
"module_name": "{{ cookiecutter.project_slug.replace('-', '_') }}", | ||
"class_name": "{{ cookiecutter.project_name.replace('-', ' ').replace('_', ' ').title().replace(' ', '') }}", | ||
"full_name": "Jane Doe", | ||
"email": "jane@example.com", | ||
"github_username": "janedoe", | ||
"version": "0.1.0" | ||
} |
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,5 @@ | ||
.venv | ||
dist | ||
build | ||
**/*.egg-info | ||
.eggs |
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,32 @@ | ||
VENV_BIN = python3 -m venv | ||
VENV_DIR ?= .venv | ||
VENV_ACTIVATE = $(VENV_DIR)/bin/activate | ||
VENV_RUN = . $(VENV_ACTIVATE) | ||
|
||
venv: $(VENV_ACTIVATE) | ||
|
||
$(VENV_ACTIVATE): setup.py setup.cfg | ||
test -d .venv || $(VENV_BIN) .venv | ||
$(VENV_RUN); pip install --upgrade pip setuptools plux | ||
$(VENV_RUN); pip install -e . | ||
touch $(VENV_DIR)/bin/activate | ||
|
||
clean: | ||
rm -rf .venv/ | ||
rm -rf build/ | ||
rm -rf .eggs/ | ||
rm -rf *.egg-info/ | ||
|
||
install: venv | ||
$(VENV_RUN); python setup.py develop | ||
|
||
dist: venv | ||
$(VENV_RUN); python setup.py sdist bdist_wheel | ||
|
||
publish: clean-dist venv dist | ||
$(VENV_RUN); pip install --upgrade twine; twine upload dist/* | ||
|
||
clean-dist: clean | ||
rm -rf dist/ | ||
|
||
.PHONY: clean clean-dist dist install publish |
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,34 @@ | ||
{{ cookiecutter.project_name }} | ||
=============================== | ||
|
||
{{ cookiecutter.project_short_description }} | ||
|
||
## Install local development version | ||
|
||
To install the extension into localstack in developer mode, you will need Python 3.10, and create a virtual environment in the extensions project. | ||
|
||
In the newly generated project, simply run | ||
|
||
```bash | ||
make install | ||
``` | ||
|
||
Then, to enable the extension for LocalStack, run | ||
|
||
```bash | ||
localstack extensions dev enable . | ||
``` | ||
|
||
You can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions: | ||
|
||
```bash | ||
EXTENSION_DEV_MODE=1 localstack start | ||
``` | ||
|
||
## Install from GitHub repository | ||
|
||
To distribute your extension, simply upload it to your github account. Your extension can then be installed via: | ||
|
||
```bash | ||
localstack extensions install "git+https://github.com/{{cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/#egg={{ cookiecutter.project_slug }}" | ||
``` |
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,22 @@ | ||
[metadata] | ||
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. same comments apply here of course as with the react template below |
||
name = {{ cookiecutter.project_slug }} | ||
version = {{ cookiecutter.version }} | ||
summary = LocalStack Extension: {{ cookiecutter.project_name }} | ||
url = https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }} | ||
author = {{ cookiecutter.full_name }} | ||
author_email = {{ cookiecutter.email }} | ||
description = {{ cookiecutter.project_short_description }} | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown; charset=UTF-8 | ||
|
||
[options] | ||
zip_safe = False | ||
packages = find: | ||
|
||
[options.extras_require] | ||
test= | ||
localstack-core>=2.2 | ||
|
||
[options.entry_points] | ||
localstack.extensions = | ||
{{ cookiecutter.project_slug }} = {{ cookiecutter.module_name }}.extension:{{ cookiecutter.class_name }} |
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,4 @@ | ||
#!/usr/bin/env python | ||
from setuptools import setup | ||
|
||
setup() |
1 change: 1 addition & 0 deletions
1
templates/basic/{{cookiecutter.project_slug}}/{{cookiecutter.module_name}}/__init__.py
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 @@ | ||
name = "{{ cookiecutter.module_name }}" |
22 changes: 22 additions & 0 deletions
22
templates/basic/{{cookiecutter.project_slug}}/{{cookiecutter.module_name}}/extension.py
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,22 @@ | ||
from localstack.extensions.api import Extension, http, aws | ||
|
||
class {{ cookiecutter.class_name }}(Extension): | ||
name = "{{ cookiecutter.project_slug }}" | ||
|
||
def on_extension_load(self): | ||
print("MyExtension: extension is loaded") | ||
|
||
def on_platform_start(self): | ||
print("MyExtension: localstack is starting") | ||
|
||
def on_platform_ready(self): | ||
print("MyExtension: localstack is running") | ||
|
||
def update_gateway_routes(self, router: http.Router[http.RouteHandler]): | ||
pass | ||
|
||
def update_request_handlers(self, handlers: aws.CompositeHandler): | ||
pass | ||
|
||
def update_response_handlers(self, handlers: aws.CompositeResponseHandler): | ||
pass |
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,10 @@ | ||
Extension Template | ||
================== | ||
|
||
This is a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template that is used when you invoke. | ||
|
||
```console | ||
localstack extensions dev new --template=react | ||
``` | ||
|
||
It contains a simple python distribution config, and some boilerplate extension code. |
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,11 @@ | ||
{ | ||
"project_name": "My LocalStack Extension", | ||
"project_short_description": "All the boilerplate you need to create a LocalStack extension.", | ||
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}", | ||
"module_name": "{{ cookiecutter.project_slug.replace('-', '_') }}", | ||
"class_name": "{{ cookiecutter.project_name.replace('-', ' ').replace('_', ' ').title().replace(' ', '') }}", | ||
"full_name": "Jane Doe", | ||
"email": "jane@example.com", | ||
"github_username": "janedoe", | ||
"version": "0.1.0" | ||
} |
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,9 @@ | ||
.venv | ||
frontend/node_modules | ||
frontend/.yarn | ||
dist | ||
build | ||
**/*.egg-info | ||
.eggs | ||
__pycache__ | ||
*.pyc |
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,56 @@ | ||
VENV_BIN = python3 -m venv | ||
VENV_DIR ?= .venv | ||
VENV_ACTIVATE = $(VENV_DIR)/bin/activate | ||
VENV_RUN = . $(VENV_ACTIVATE) | ||
FRONTEND_FOLDER = frontend | ||
BACKEND_FOLDER = backend | ||
|
||
|
||
INFO_COLOR = \033[0;36m | ||
NO_COLOR = \033[m | ||
|
||
venv: $(VENV_ACTIVATE) | ||
|
||
$(VENV_ACTIVATE): | ||
test -d .venv || $(VENV_BIN) .venv | ||
$(VENV_RUN); pip install --upgrade pip setuptools plux build wheel | ||
$(VENV_RUN); pip install -e .[dev] | ||
touch $(VENV_DIR)/bin/activate | ||
|
||
clean: ## Clean the project | ||
rm -rf .venv/ | ||
rm -rf build/ | ||
rm -rf .eggs/ | ||
rm -rf $(BACKEND_FOLDER)/*.egg-info/ | ||
|
||
install-backend: venv ## Install dependencies of the extension | ||
$(VENV_RUN); python -m plux entrypoints | ||
|
||
install-frontend: venv ## Install dependencies of the frontend | ||
cd $(FRONTEND_FOLDER) && yarn install | ||
|
||
build-frontend: # Build the React app | ||
@if [ ! -d "$(FRONTEND_FOLDER)/node_modules" ]; then \ | ||
$(MAKE) install-frontend; \ | ||
fi | ||
cd $(FRONTEND_FOLDER); rm -rf build && REACT_APP_DEVELOPMENT_ENVIRONMENT=false NODE_ENV=prod npm run build | ||
|
||
start-frontend: ## Start the frontend in dev mode (hot reload) | ||
cd $(FRONTEND_FOLDER); REACT_APP_DEVELOPMENT_ENVIRONMENT=true yarn start | ||
|
||
install: venv install-backend install-frontend ## Install dependencies | ||
|
||
dist: venv build-frontend ## Create distribution files | ||
$(VENV_RUN); python -m build | ||
|
||
publish: clean-dist venv dist ## Build and upload package to pypi | ||
$(VENV_RUN); pip install --upgrade twine; twine upload dist/* | ||
|
||
clean-dist: clean ## Remove dist folder | ||
rm -rf dist/ | ||
|
||
help: ## Show this help | ||
@echo Please specify a build target. The choices are: | ||
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}' | ||
|
||
.PHONY: clean clean-dist dist install install-backend install-frontend build-frontend start-frontend publish venv |
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,42 @@ | ||
{{ cookiecutter.project_name }} | ||
=============================== | ||
|
||
{{ cookiecutter.project_short_description }} | ||
|
||
## Install local development version | ||
|
||
To install the extension into localstack in developer mode, you will need Python 3.10+, and create a virtual environment in the extensions project. | ||
You will also need to install [yarn](https://yarnpkg.com/getting-started/install) as package manager if you haven't already | ||
In the newly generated project, simply run | ||
|
||
```bash | ||
make install | ||
``` | ||
|
||
Then, to enable the extension for LocalStack, run | ||
|
||
```bash | ||
localstack extensions dev enable . | ||
``` | ||
|
||
You can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions: | ||
|
||
```bash | ||
EXTENSION_DEV_MODE=1 localstack start | ||
``` | ||
|
||
## Developing UI | ||
With this template is generated also a UI made in react that is available at either {{ cookiecutter.project_name }}.localhost.localstack.cloud:4566/ or http://localhost.localstack.cloud:4566/_extension/{{ cookiecutter.project_name }}/. | ||
|
||
There are a few make commands available that will help your journey with the UI: | ||
- **build-frontend**: will build the react app into the frontend/build folder which will then be passed into the extension itself allowing the UI to be seen. Remember to always execute this command when you wish to see new changes when using the extension. | ||
- **start-frontend**: will start a live server on port 3000 (by default) that will allow you to have hot reloading when developing locally outside the extension (it will also build the frontend) | ||
|
||
|
||
## Install from GitHub repository | ||
|
||
To distribute your extension, simply upload it to your github account. Your extension can then be installed via: | ||
|
||
```bash | ||
localstack extensions install "git+https://github.com/{{cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/#egg={{ cookiecutter.project_slug }}" | ||
``` |
1 change: 1 addition & 0 deletions
1
...ates/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/__init__.py
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 @@ | ||
name = "{{ cookiecutter.module_name }}" |
12 changes: 12 additions & 0 deletions
12
...lates/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/api/web.py
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,12 @@ | ||
from localstack.http import route, Request, Response | ||
|
||
from .. import static | ||
|
||
class WebApp: | ||
@route("/") | ||
def index(self, request: Request, *args, **kwargs): | ||
return Response.for_resource(static, "index.html") | ||
|
||
@route("/<path:path>") | ||
def index2(self, request: Request, path: str, **kwargs): | ||
return Response.for_resource(static, path) |
19 changes: 19 additions & 0 deletions
19
...tes/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/extension.py
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,19 @@ | ||
import logging | ||
import typing as t | ||
|
||
from localstack.extensions.patterns.webapp import WebAppExtension | ||
|
||
from .api.web import WebApp | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class {{ cookiecutter.class_name }}(WebAppExtension): | ||
name = "{{ cookiecutter.project_slug }}" | ||
|
||
def __init__(self): | ||
super().__init__(template_package_path=None) | ||
|
||
def collect_routes(self, routes: list[t.Any]): | ||
routes.append(WebApp()) | ||
|
Empty file.
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.
same arguments as below in the react template