-
Notifications
You must be signed in to change notification settings - Fork 78
[WIP] feat: express JS #781
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
76bcce6
fix: craft-cli branch ref to main
yanksyoon ce9efe5
high-level functions
yanksyoon a9c6c5a
public interfaces
yanksyoon 8e234d9
Revert "fix: craft-cli branch ref to main"
yanksyoon 70a1aaf
rename
yanksyoon b405e2d
Merge branch 'main' into feat/expressjs
yanksyoon dc367d1
Merge branch 'main' into feat/expressjs
yanksyoon f814e75
Merge branch 'main' into feat/expressjs
yanksyoon 3dd3ae7
parts
yanksyoon a03d789
chore: rename express js module
yanksyoon fd98937
test: unit test expressjs module
yanksyoon 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 hidden or 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,121 @@ | ||
| # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
| # | ||
| # Copyright 2024 Canonical Ltd. | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License version 3 as | ||
| # published by the Free Software Foundation. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| """An extension for the NodeJS based Javascript application extension.""" | ||
| from typing import Any, Dict, Tuple | ||
|
|
||
| from overrides import override | ||
|
|
||
| from .extension import Extension | ||
|
|
||
|
|
||
| class ExpressJSFramework(Extension): | ||
| """An extension for constructing Javascript applications based on the ExpressJS framework.""" | ||
|
|
||
| @staticmethod | ||
| @override | ||
| def get_supported_bases() -> Tuple[str, ...]: | ||
| """Return supported bases.""" | ||
| return "bare", "ubuntu@22.04", "ubuntu:22.04", "ubuntu@24.04", "ubuntu:24.04" | ||
|
yanksyoon marked this conversation as resolved.
Outdated
|
||
|
|
||
| @staticmethod | ||
| @override | ||
| def is_experimental(base: str | None) -> bool: | ||
| """Check if the extension is in an experimental state.""" | ||
| return False | ||
|
yanksyoon marked this conversation as resolved.
Outdated
|
||
|
|
||
| @property | ||
| @override | ||
| def framework(self) -> str: | ||
| """Return the framework name, i.e. expressjs.""" | ||
| return "expressjs" | ||
|
yanksyoon marked this conversation as resolved.
Outdated
|
||
|
|
||
| @override | ||
| def get_root_snippet(self) -> Dict[str, Any]: | ||
| """Fill in some default root components. | ||
|
|
||
| Default values: | ||
| - run_user: _daemon_ | ||
| - build-base: ubuntu:22.04 (only if user specify bare without a build-base) | ||
| - platform: amd64 | ||
| - services: a service to run the ExpressJS server | ||
| - parts: see ExpressJSFramework._gen_parts | ||
| """ | ||
| snippet: Dict[str, Any] = { | ||
| "run-user": "_daemon_", | ||
| "services": { | ||
| "app": { | ||
| "override": "replace", | ||
| "command": "npm start", | ||
| "startup": "enabled", | ||
| "on-success": "shutdown", | ||
| "on-failure": "shutdown", | ||
| "working-dir": f"{self.framework}/app", | ||
| } | ||
| }, | ||
| } | ||
| return snippet | ||
|
|
||
| @override | ||
| def get_part_snippet(self) -> dict[str, Any]: | ||
| """Return the part snippet to apply to existing parts. | ||
|
|
||
| This is unused but is required by the ABC. | ||
| """ | ||
| return {} | ||
|
|
||
| @override | ||
| def get_parts_snippet(self) -> dict[str, Any]: | ||
| """Return the parts to add to parts. | ||
|
|
||
| This is unused but is required by the ABC. | ||
| """ | ||
| return {} | ||
|
|
||
| def _gen_parts(self) -> dict: | ||
| """Generate the parts associated with this extension. | ||
|
|
||
| The parts generated are the following: | ||
| 1. install-app: Install the application with npm installs. | ||
| 2. install-dependencies: Install application host dependencies (e.g. pg lib) | ||
| """ | ||
| ... | ||
|
|
||
| def _gen_install_app_part(self) -> dict: | ||
| """Generate the install app part using NPM plugin.""" | ||
| ... | ||
|
|
||
| def _gen_install_dependencies_part(self) -> dict: | ||
| """Generate the install dependencies part using dump plugin.""" | ||
| ... | ||
|
|
||
| @property | ||
| def _app_prime(self): | ||
| """Return the prime list for the ExpressJS proejct. | ||
|
|
||
| Use the paths generated by the | ||
| express-generator (https://expressjs.com/en/starter/generator.html) tool by default if no | ||
| user prime paths are provided. Use only user prime paths otherwise. | ||
| """ | ||
| ... | ||
|
|
||
| def _check_project(self): | ||
| """Ensure this extension can apply to the current rockcraft project. | ||
|
|
||
| The ExpressJS framework assumes that: | ||
| - The npm start script exists. | ||
| """ | ||
| ... | ||
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.
Thanks, in general perhaps a better reference is https://github.com/canonical/rockcraft/blob/main/rockcraft/extensions/fastapi.py as it is stand-alone. Flask is unique because it shares a common parent class for Django
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.
We'll need:
Also check anywhere that mentions
fast-apiframework and check if we need to do something similar forexpressjs-framework