Compare commits

...

5 Commits

Author SHA1 Message Date
88d5d78583 Updated cpl structure model json handling
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
Build on push / prepare (push) Successful in 10s
Build on push / query (push) Successful in 19s
Build on push / core (push) Successful in 23s
Build on push / dependency (push) Successful in 18s
Build on push / cli (push) Successful in 25s
Build on push / mail (push) Successful in 17s
Build on push / application (push) Successful in 21s
Build on push / database (push) Successful in 20s
Build on push / translation (push) Successful in 20s
Build on push / auth (push) Successful in 18s
Build on push / api (push) Successful in 15s
2025-10-19 20:08:31 +02:00
472aba5990 Removed ws with_parents
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
Build on push / prepare (push) Successful in 10s
Build on push / query (push) Successful in 19s
Build on push / core (push) Successful in 22s
Build on push / cli (push) Successful in 16s
Build on push / dependency (push) Successful in 19s
Build on push / mail (push) Successful in 17s
Build on push / application (push) Successful in 21s
Build on push / translation (push) Successful in 20s
Build on push / database (push) Successful in 21s
Build on push / auth (push) Successful in 19s
Build on push / api (push) Successful in 15s
2025-10-19 20:03:43 +02:00
9c75008c9f Add cpl-mail project
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 8s
Build on push / prepare (push) Successful in 10s
Build on push / query (push) Successful in 18s
Build on push / core (push) Successful in 19s
Build on push / dependency (push) Successful in 19s
Build on push / cli (push) Successful in 24s
Build on push / mail (push) Successful in 17s
Build on push / translation (push) Successful in 16s
Build on push / database (push) Successful in 21s
Build on push / application (push) Successful in 21s
Build on push / auth (push) Successful in 15s
Build on push / api (push) Successful in 15s
2025-10-19 20:03:43 +02:00
df2c2b5b56 Workspace check project existence
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 6s
Build on push / prepare (push) Successful in 11s
Build on push / query (push) Successful in 19s
Build on push / core (push) Successful in 19s
Build on push / dependency (push) Successful in 19s
Build on push / cli (push) Successful in 19s
Build on push / application (push) Successful in 16s
Build on push / translation (push) Successful in 17s
Build on push / database (push) Successful in 20s
Build on push / mail (push) Successful in 20s
Build on push / auth (push) Successful in 15s
Build on push / api (push) Successful in 16s
2025-10-19 19:56:59 +02:00
e3b19c9984 Fixed init command regarding structure
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
Build on push / prepare (push) Successful in 10s
Build on push / core (push) Successful in 19s
Build on push / query (push) Successful in 19s
Build on push / cli (push) Successful in 16s
Build on push / dependency (push) Successful in 19s
Build on push / application (push) Successful in 20s
Build on push / database (push) Successful in 21s
Build on push / translation (push) Successful in 20s
Build on push / mail (push) Successful in 23s
Build on push / auth (push) Successful in 15s
Build on push / api (push) Successful in 14s
2025-10-19 19:48:41 +02:00
7 changed files with 62 additions and 27 deletions

View File

@@ -3,7 +3,7 @@
"projects": [
"src/cli/cpl.project.json",
"src/core/cpl.project.json",
"test/cpl.project.json"
"src/mail/cpl.project.json"
],
"defaultProject": "cpl-cli",
"scripts": {

View File

@@ -31,7 +31,7 @@ def init(target: str, name: str, verbose: bool = False):
if target in ["workspace", "ws"]:
workspace = Structure.init_workspace("./", name or click.prompt("Workspace name", default="my-workspace"))
elif target in PROJECT_TYPES:
workspace = Structure.find_workspace_in_path(Path(name or "./").parent, with_parents=True)
workspace = Structure.find_workspace_in_path(Path(name or "./").parent)
project = Structure.init_project(
"./", name or click.prompt("Project name", default=f"my-{target}"), target, workspace, verbose=verbose
)

View File

@@ -44,7 +44,7 @@ def new(type: str, name: str, in_name: str | None, project: list[str] | None, ve
path = Path(workspace.path).parent / Path(project[1]).parent
project_name = Path(project[1]).stem
workspace = Structure.find_workspace_in_path(path, with_parents=False)
workspace = Structure.find_workspace_in_path(path)
if workspace is None:
Console.error("No workspace found. Please run 'cpl init workspace' first.")
raise SystemExit(1)

View File

@@ -12,11 +12,11 @@ T = TypeVar("T", bound="CPLStructureModel")
class CPLStructureModel:
def __init__(self, path: Optional[str] = None):
self._path = path
self.__path = path
@property
def path(self) -> Optional[str]:
return self._path
return self.__path
@classmethod
def from_file(cls: Type[T], path: Path | str) -> T:
@@ -68,7 +68,7 @@ class CPLStructureModel:
def to_json(self) -> Dict[str, Any]:
result: Dict[str, Any] = {}
for key, value in self.__dict__.items():
if not key.startswith("_") or key == "_path":
if not key.startswith("_") or key.startswith("__") or key.endswith("_"):
continue
out_key = _self_or_cls_snake_to_camel(key[1:])
@@ -79,13 +79,13 @@ class CPLStructureModel:
return result
def save(self):
if not self._path:
if not self.__path:
raise ValueError("Cannot save model without a path.")
if not Path(self._path).exists():
os.makedirs(Path(self._path).parent, exist_ok=True)
if not Path(self.__path).exists():
os.makedirs(Path(self.__path).parent, exist_ok=True)
with open(self._path, "w", encoding="utf-8") as f:
with open(self.__path, "w", encoding="utf-8") as f:
json.dump(self.to_json(), f, indent=2)
@staticmethod

View File

@@ -1,3 +1,4 @@
from pathlib import Path
from typing import Optional, List, Dict
from cpl.cli.model.cpl_structure_model import CPLStructureModel
@@ -28,6 +29,20 @@ class Workspace(CPLStructureModel):
self._name = name
self._projects = projects
self._default_project = default_project
self.__actual_projects = []
self.__project_names = []
for project in projects:
if Path(project).is_dir() or not Path(project).exists():
raise ValueError(f"Project path '{project}' does not exist or is a directory.")
p = Project.from_file(project)
self.__actual_projects.append(p)
self.__project_names.append(p.name)
if default_project is not None and default_project not in self.__project_names:
raise ValueError(f"Default project '{default_project}' not found in workspace projects.")
self._scripts = scripts
@property
@@ -48,11 +63,11 @@ class Workspace(CPLStructureModel):
@property
def actual_projects(self) -> List[Project]:
return [Project.from_file(p) for p in self._projects]
return self.__actual_projects
@property
def project_names(self) -> List[str]:
return [Project.from_file(p).name for p in self._projects]
return self.__project_names
@property
def default_project(self) -> Optional[str]:

View File

@@ -32,11 +32,9 @@ class Structure:
}
@staticmethod
def find_workspace_in_path(path: Path, with_parents=False) -> Workspace | None:
def find_workspace_in_path(path: Path) -> Workspace | None:
current_path = path.resolve()
paths = [current_path]
if with_parents:
paths.extend(current_path.parents)
paths = [current_path, *current_path.parents]
for parent in paths:
workspace_file = parent / "cpl.workspace.json"
@@ -138,6 +136,16 @@ class Structure:
)
project.save()
Console.write_line(f"Created {project_type} project '{name}'")
if workspace is not None:
rel_path = str(path.resolve().absolute().relative_to(Path(workspace.path).parent)).replace("\\", "/")
if rel_path not in workspace.projects:
workspace.projects.append(rel_path)
workspace.save()
if verbose:
Console.write_line(f"Registered '{name}' in workspace.json")
from cpl.cli.command.package.install import install
@@ -149,17 +157,6 @@ class Structure:
install.callback(package, project.name, dev=False, verbose=verbose)
os.chdir(old_cwd)
if workspace is not None:
rel_path = str(path.resolve().absolute().relative_to(Path(workspace.path).parent)).replace("\\", "/")
if rel_path not in workspace.projects:
workspace.projects.append(rel_path)
workspace.save()
if verbose:
Console.write_line(f"Registered '{name}' in workspace.json")
Console.write_line(f"Created {project_type} project '{name}'")
return project
@staticmethod

23
src/mail/cpl.project.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "cpl-mail",
"version": "0.1.0",
"type": "library",
"license": "",
"author": "",
"description": "",
"homepage": "",
"keywords": [],
"dependencies": {
"cpl-core": "~2024.7.0"
},
"devDependencies": {
"cpl-cli": ">2024.7.0"
},
"references": [],
"main": null,
"directory": "./",
"build": {
"include": [],
"exclude": []
}
}