Skip to content

Commit

Permalink
Add module for using VScode with scaffolded applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
aholmes committed Oct 16, 2024
1 parent 4459d67 commit e4646ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/web/Ligare/web/scaffolding/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ScaffoldInputArgs(Namespace):
name: Operation # pyright: ignore[reportUninitializedInstanceVariable]
endpoints: list[Operation] | None = None
template_type: Literal["basic", "openapi"] = "basic"
modules: list[Literal["database", "test"]] | None = None
modules: list[str] | None = None
output_directory: str | None = None


Expand All @@ -35,7 +35,7 @@ class ScaffoldParsedArgs(NamedTuple):
name: Operation
endpoints: list[Operation]
template_type: Literal["basic", "openapi"]
modules: list[Literal["database", "test"]] | None
modules: list[str] | None
output_directory: str


Expand All @@ -62,6 +62,14 @@ def __init__(self, log_level: int | str | None = None) -> None:

self._log = logging.getLogger()

def _find_modules(self):
return [
module_path.name
for module_path in Path(
Path(__file__).parent.parent, Scaffolder.MODULE_TEMPLATE_DIRECTORY
).iterdir()
]

def _parse_args(self, args: list[str]) -> ScaffoldParsedArgs:
parser = ArgumentParser(description="Ligare Web Project Scaffolding Tool")

Expand Down Expand Up @@ -95,7 +103,7 @@ def _parse_args(self, args: list[str]) -> ScaffoldParsedArgs:
default="basic",
help="The type of template to scaffold.",
)
modules = ["database", "test"]
modules = self._find_modules()
_ = create_parser.add_argument(
"-m",
choices=modules,
Expand Down
6 changes: 5 additions & 1 deletion src/web/Ligare/web/scaffolding/scaffolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class Scaffolder:
_manager: Any
_provider: IResourceProvider

MODULE_TEMPLATE_DIRECTORY = Path(
f"scaffolding/templates/optional/{{{{application.module_name}}}}/modules"
)

def __init__(self, config: ScaffoldConfig, log: logging.Logger) -> None:
self._config = config
self._config_dict = asdict(config)
Expand Down Expand Up @@ -338,7 +342,7 @@ def _scaffold_modules(self, overwrite_existing_files: bool = True):
# module templates are stored under `optional/`
# because we don't always want to render any given module.
module_template_directory = Path(
f"scaffolding/templates/optional/{{{{application.module_name}}}}/modules/{module.module_name}"
Scaffolder.MODULE_TEMPLATE_DIRECTORY, module.module_name
)
# executed module hooks before any rendering is done
# so the hooks can modify the config or do other
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ render_module_template(".vscode/launch.json.j2", module_config, ".") }}

0 comments on commit e4646ec

Please sign in to comment.