Compare commits
5 Commits
2025.10.19
...
2025.10.19
| Author | SHA1 | Date | |
|---|---|---|---|
| df2c2b5b56 | |||
| e3b19c9984 | |||
| 91269f351b | |||
| 5d07973940 | |||
| 0a9b7b81be |
@@ -2,8 +2,7 @@
|
|||||||
"name": "cpl",
|
"name": "cpl",
|
||||||
"projects": [
|
"projects": [
|
||||||
"src/cli/cpl.project.json",
|
"src/cli/cpl.project.json",
|
||||||
"src/core/cpl.project.json",
|
"src/core/cpl.project.json"
|
||||||
"test/cpl.project.json"
|
|
||||||
],
|
],
|
||||||
"defaultProject": "cpl-cli",
|
"defaultProject": "cpl-cli",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from cpl.core.console import Console
|
|||||||
@click.command("init")
|
@click.command("init")
|
||||||
@click.argument("target", required=False)
|
@click.argument("target", required=False)
|
||||||
@click.argument("name", required=False)
|
@click.argument("name", required=False)
|
||||||
def init(target: str, name: str):
|
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
|
||||||
|
def init(target: str, name: str, verbose: bool = False):
|
||||||
workspace = None
|
workspace = None
|
||||||
project = None
|
project = None
|
||||||
|
|
||||||
@@ -30,9 +31,9 @@ def init(target: str, name: str):
|
|||||||
if target in ["workspace", "ws"]:
|
if target in ["workspace", "ws"]:
|
||||||
workspace = Structure.init_workspace("./", name or click.prompt("Workspace name", default="my-workspace"))
|
workspace = Structure.init_workspace("./", name or click.prompt("Workspace name", default="my-workspace"))
|
||||||
elif target in PROJECT_TYPES:
|
elif target in PROJECT_TYPES:
|
||||||
workspace = Structure.find_workspace_in_path(Path(name).parent)
|
workspace = Structure.find_workspace_in_path(Path(name or "./").parent, with_parents=True)
|
||||||
project = Structure.init_project(
|
project = Structure.init_project(
|
||||||
"./", name or click.prompt("Project name", default=f"my-{target}"), target, workspace
|
"./", name or click.prompt("Project name", default=f"my-{target}"), target, workspace, verbose=verbose
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
Console.error(f"Unknown target '{target}'")
|
Console.error(f"Unknown target '{target}'")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from pathlib import Path
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
|
|
||||||
from cpl.cli.model.cpl_structure_model import CPLStructureModel
|
from cpl.cli.model.cpl_structure_model import CPLStructureModel
|
||||||
@@ -28,6 +29,20 @@ class Workspace(CPLStructureModel):
|
|||||||
self._name = name
|
self._name = name
|
||||||
self._projects = projects
|
self._projects = projects
|
||||||
self._default_project = default_project
|
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
|
self._scripts = scripts
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -48,11 +63,11 @@ class Workspace(CPLStructureModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def actual_projects(self) -> List[Project]:
|
def actual_projects(self) -> List[Project]:
|
||||||
return [Project.from_file(p) for p in self._projects]
|
return self._actual_projects
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project_names(self) -> List[str]:
|
def project_names(self) -> List[str]:
|
||||||
return [Project.from_file(p).name for p in self._projects]
|
return self._project_names
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_project(self) -> Optional[str]:
|
def default_project(self) -> Optional[str]:
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Structure:
|
|||||||
|
|
||||||
return Project.from_file(path)
|
return Project.from_file(path)
|
||||||
|
|
||||||
workspace = Structure.find_workspace_in_path(path.parent)
|
workspace = Structure.find_workspace_in_path(path.parent, with_parents=True)
|
||||||
if workspace is None:
|
if workspace is None:
|
||||||
raise RuntimeError("No workspace found. Please run 'cpl init workspace' first.")
|
raise RuntimeError("No workspace found. Please run 'cpl init workspace' first.")
|
||||||
|
|
||||||
@@ -138,6 +138,16 @@ class Structure:
|
|||||||
)
|
)
|
||||||
|
|
||||||
project.save()
|
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
|
from cpl.cli.command.package.install import install
|
||||||
|
|
||||||
@@ -149,17 +159,6 @@ class Structure:
|
|||||||
install.callback(package, project.name, dev=False, verbose=verbose)
|
install.callback(package, project.name, dev=False, verbose=verbose)
|
||||||
|
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
if workspace is not None:
|
|
||||||
rel_path = str(path.resolve().absolute().relative_to(Path(workspace.path).parent))
|
|
||||||
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
|
return project
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -199,4 +198,4 @@ class Structure:
|
|||||||
shutil.copy(src_file, tgt_file)
|
shutil.copy(src_file, tgt_file)
|
||||||
|
|
||||||
Console.write_line()
|
Console.write_line()
|
||||||
Structure.init_project(str(path), name, project_type, workspace)
|
Structure.init_project(str(path), name, project_type, workspace, verbose=verbose)
|
||||||
|
|||||||
Reference in New Issue
Block a user