xgic-payload-cms-cli 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xgic/cli/payload/__init__.py +40 -0
- xgic/cli/payload/commands/__init__.py +1 -0
- xgic/cli/payload/commands/dev.py +87 -0
- xgic/cli/payload/commands/payload_env.py +65 -0
- xgic/cli/payload/commands/reset.py +108 -0
- xgic/cli/payload/commands/schema.py +38 -0
- xgic/cli/payload/commands/setup.py +12 -0
- xgic/cli/payload/config.py +136 -0
- xgic/cli/payload/env_helpers.py +91 -0
- xgic/cli/payload/plugin.py +121 -0
- xgic/cli/payload/project.py +212 -0
- xgic_payload_cms_cli-0.2.0.dist-info/METADATA +113 -0
- xgic_payload_cms_cli-0.2.0.dist-info/RECORD +17 -0
- xgic_payload_cms_cli-0.2.0.dist-info/WHEEL +4 -0
- xgic_payload_cms_cli-0.2.0.dist-info/entry_points.txt +2 -0
- xgic_payload_cms_cli-0.2.0.dist-info/licenses/LICENSE +202 -0
- xgic_payload_cms_cli-0.2.0.dist-info/licenses/NOTICE +8 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""XGIC CLI Payload CMS module (``xgic.cli.payload``)."""
|
|
2
|
+
|
|
3
|
+
from xgic.cli.payload.config import (
|
|
4
|
+
DEFAULT_COMPOSE_PROJECT,
|
|
5
|
+
DEFAULT_CONFIG_FILE,
|
|
6
|
+
DEFAULT_PRIMARY_SERVICE,
|
|
7
|
+
db_ready,
|
|
8
|
+
get_db_config,
|
|
9
|
+
get_db_profile,
|
|
10
|
+
get_payload_project_name,
|
|
11
|
+
make_payload_docker_controller,
|
|
12
|
+
)
|
|
13
|
+
from xgic.cli.payload.env_helpers import (
|
|
14
|
+
generate_fresh_env_content,
|
|
15
|
+
perform_env_regenerate,
|
|
16
|
+
)
|
|
17
|
+
from xgic.cli.payload.project import (
|
|
18
|
+
build_create_payload_command,
|
|
19
|
+
ensure_payload_project,
|
|
20
|
+
load_create_payload_config,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__version__ = "0.2.0"
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"DEFAULT_COMPOSE_PROJECT",
|
|
27
|
+
"DEFAULT_CONFIG_FILE",
|
|
28
|
+
"DEFAULT_PRIMARY_SERVICE",
|
|
29
|
+
"build_create_payload_command",
|
|
30
|
+
"db_ready",
|
|
31
|
+
"ensure_payload_project",
|
|
32
|
+
"generate_fresh_env_content",
|
|
33
|
+
"get_db_config",
|
|
34
|
+
"get_db_profile",
|
|
35
|
+
"get_payload_project_name",
|
|
36
|
+
"load_create_payload_config",
|
|
37
|
+
"make_payload_docker_controller",
|
|
38
|
+
"perform_env_regenerate",
|
|
39
|
+
"__version__",
|
|
40
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI command handlers for ``xgic.cli.payload``."""
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""``xgic payload dev`` — smart Payload CMS development server start."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
|
|
7
|
+
from xgic.cli.app import CommandContext
|
|
8
|
+
from xgic.cli.core.environment import EnvironmentType
|
|
9
|
+
from xgic.cli.payload.config import (
|
|
10
|
+
DEFAULT_PRIMARY_SERVICE,
|
|
11
|
+
db_ready,
|
|
12
|
+
get_db_profile,
|
|
13
|
+
get_payload_project_name,
|
|
14
|
+
make_payload_docker_controller,
|
|
15
|
+
)
|
|
16
|
+
from xgic.cli.utils.output import print_info, print_success, print_warning
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def run_dev(ctx: CommandContext) -> int:
|
|
20
|
+
"""Start services if needed and launch the Payload CMS app dev server."""
|
|
21
|
+
env = ctx.env
|
|
22
|
+
docker = make_payload_docker_controller(env)
|
|
23
|
+
print_info("Starting Payload CMS development server...")
|
|
24
|
+
|
|
25
|
+
profile = get_db_profile()
|
|
26
|
+
if not docker.services_running():
|
|
27
|
+
print_warning("Services not running. Attempting to bring them up...")
|
|
28
|
+
docker.up(profile=profile)
|
|
29
|
+
print_success("Services started. Proceeding...")
|
|
30
|
+
|
|
31
|
+
payload_project = get_payload_project_name()
|
|
32
|
+
|
|
33
|
+
if db_ready(docker):
|
|
34
|
+
print_success("Database is ready")
|
|
35
|
+
else:
|
|
36
|
+
print_warning(
|
|
37
|
+
"Database not ready yet. You may need a reset / wait for DB startup."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
print_info(f"Target Payload CMS project: {payload_project}")
|
|
41
|
+
|
|
42
|
+
if env.env_type == EnvironmentType.DEV_CONTAINER:
|
|
43
|
+
try:
|
|
44
|
+
print_info(f"Launching pnpm dev inside {payload_project}...")
|
|
45
|
+
project_dir = f"/workspace/{payload_project}"
|
|
46
|
+
result = subprocess.run(
|
|
47
|
+
["sh", "-c", 'trap "exit 0" INT TERM; exec pnpm dev'],
|
|
48
|
+
cwd=project_dir,
|
|
49
|
+
check=False,
|
|
50
|
+
)
|
|
51
|
+
if result.returncode in (130, -2, 2):
|
|
52
|
+
print_info("Development server stopped by user (Ctrl+C).")
|
|
53
|
+
return 0
|
|
54
|
+
if result.returncode != 0:
|
|
55
|
+
print_warning(f"pnpm dev exited with code {result.returncode}.")
|
|
56
|
+
print_info(
|
|
57
|
+
f"Fallback: cd {payload_project} && pnpm dev "
|
|
58
|
+
"(or xgic shell --service …)."
|
|
59
|
+
)
|
|
60
|
+
return result.returncode or 1
|
|
61
|
+
print_info("Development server exited cleanly.")
|
|
62
|
+
return 0
|
|
63
|
+
except KeyboardInterrupt:
|
|
64
|
+
print_info("Development server stopped by user (Ctrl+C).")
|
|
65
|
+
return 0
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
print_info(
|
|
69
|
+
f"Launching pnpm dev inside {payload_project} (via container)..."
|
|
70
|
+
)
|
|
71
|
+
docker.exec(
|
|
72
|
+
DEFAULT_PRIMARY_SERVICE,
|
|
73
|
+
"sh",
|
|
74
|
+
"-c",
|
|
75
|
+
f"cd /workspace/{payload_project} && "
|
|
76
|
+
"sh -c 'trap \"exit 0\" INT TERM; exec pnpm dev'",
|
|
77
|
+
check=False,
|
|
78
|
+
)
|
|
79
|
+
except Exception as e:
|
|
80
|
+
print_warning(f"Failed to launch pnpm dev: {e}")
|
|
81
|
+
print_info(
|
|
82
|
+
f"Fallback: cd {payload_project} && pnpm dev (or xgic shell)."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
print_success("Environment ready for development.")
|
|
86
|
+
print_info("Environment context: " + env.describe())
|
|
87
|
+
return 0
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""``xgic payload env`` — product-aware env status and credential regenerate.
|
|
2
|
+
|
|
3
|
+
Nested under the ``payload`` domain group so it does not clash with the
|
|
4
|
+
generic ``xgic env`` command in ``xgic.cli.dev``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from xgic.cli.app import CommandContext
|
|
13
|
+
from xgic.cli.payload.config import (
|
|
14
|
+
get_payload_project_name,
|
|
15
|
+
make_payload_docker_controller,
|
|
16
|
+
)
|
|
17
|
+
from xgic.cli.payload.env_helpers import ENV_FILE, perform_env_regenerate
|
|
18
|
+
from xgic.cli.utils.output import print_info, print_success
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def run_payload_env(ctx: CommandContext) -> int:
|
|
22
|
+
"""Inspect Payload CMS env status or regenerate credentials."""
|
|
23
|
+
if getattr(ctx.args, "regenerate", False):
|
|
24
|
+
return perform_env_regenerate(
|
|
25
|
+
dry_run=bool(getattr(ctx.args, "dry_run", False)),
|
|
26
|
+
yes=bool(getattr(ctx.args, "yes", False)),
|
|
27
|
+
env_file=Path(getattr(ctx.args, "env_file", None) or ENV_FILE),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
docker = make_payload_docker_controller(ctx.env)
|
|
31
|
+
env_file_exists = ENV_FILE.exists()
|
|
32
|
+
services_ok = docker.services_running()
|
|
33
|
+
payload_project = get_payload_project_name()
|
|
34
|
+
use_json = bool(getattr(ctx.args, "json", False))
|
|
35
|
+
|
|
36
|
+
if use_json:
|
|
37
|
+
print(
|
|
38
|
+
json.dumps(
|
|
39
|
+
{
|
|
40
|
+
"env_file_exists": env_file_exists,
|
|
41
|
+
"env_file": str(ENV_FILE),
|
|
42
|
+
"services_running": services_ok,
|
|
43
|
+
"payload_project": payload_project,
|
|
44
|
+
"environment": ctx.env.describe(),
|
|
45
|
+
},
|
|
46
|
+
indent=2,
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
return 0
|
|
50
|
+
|
|
51
|
+
print_info("Payload CMS development environment status:")
|
|
52
|
+
if env_file_exists:
|
|
53
|
+
print_success(f".env file exists at {ENV_FILE}")
|
|
54
|
+
else:
|
|
55
|
+
print_info(
|
|
56
|
+
f".env file not found at {ENV_FILE} "
|
|
57
|
+
"(use: xgic payload env --regenerate --yes)"
|
|
58
|
+
)
|
|
59
|
+
if services_ok:
|
|
60
|
+
print_success("Compose services: appear to be running")
|
|
61
|
+
else:
|
|
62
|
+
print_info("Compose services: not detected as running")
|
|
63
|
+
print_info(f"Configured Payload CMS project: {payload_project}")
|
|
64
|
+
print_info("Environment context: " + ctx.env.describe())
|
|
65
|
+
return 0
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""``xgic payload reset`` — fast targeted project + DB volume reset."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from xgic.cli.app import CommandContext
|
|
9
|
+
from xgic.cli.payload.config import (
|
|
10
|
+
get_db_config,
|
|
11
|
+
get_db_profile,
|
|
12
|
+
get_payload_project_name,
|
|
13
|
+
make_payload_docker_controller,
|
|
14
|
+
)
|
|
15
|
+
from xgic.cli.payload.env_helpers import perform_env_regenerate
|
|
16
|
+
from xgic.cli.payload.project import ensure_payload_project
|
|
17
|
+
from xgic.cli.utils.output import print_info, print_success, print_warning
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def run_reset(ctx: CommandContext) -> int:
|
|
21
|
+
"""Delete generated project folder and reset the active DB volume.
|
|
22
|
+
|
|
23
|
+
Credentials in ``.env`` are left alone unless ``--rotate-credentials``.
|
|
24
|
+
"""
|
|
25
|
+
dry_run = bool(getattr(ctx.args, "dry_run", False))
|
|
26
|
+
yes = bool(getattr(ctx.args, "yes", False))
|
|
27
|
+
rotate = bool(getattr(ctx.args, "rotate_credentials", False))
|
|
28
|
+
|
|
29
|
+
docker = make_payload_docker_controller(ctx.env)
|
|
30
|
+
payload_project = get_payload_project_name()
|
|
31
|
+
project_path = Path(payload_project)
|
|
32
|
+
db_service = get_db_profile()
|
|
33
|
+
db_volume = docker.db_volume_name(db_service)
|
|
34
|
+
|
|
35
|
+
print_info("Planned actions for reset:")
|
|
36
|
+
print_info(f" - Delete directory: {project_path}")
|
|
37
|
+
print_info(f" - Remove Docker volume: {db_volume}")
|
|
38
|
+
if rotate:
|
|
39
|
+
print_warning(" - ALSO rotate database credentials (DANGEROUS)")
|
|
40
|
+
|
|
41
|
+
if dry_run:
|
|
42
|
+
print_success("Dry run complete. No changes were made.")
|
|
43
|
+
return 0
|
|
44
|
+
|
|
45
|
+
if not yes:
|
|
46
|
+
print_warning(
|
|
47
|
+
"This operation is destructive. Re-run with --yes to proceed."
|
|
48
|
+
)
|
|
49
|
+
return 1
|
|
50
|
+
|
|
51
|
+
print_info("Performing reset...")
|
|
52
|
+
|
|
53
|
+
if project_path.exists():
|
|
54
|
+
shutil.rmtree(project_path)
|
|
55
|
+
print_success(f"Deleted project directory: {project_path}")
|
|
56
|
+
else:
|
|
57
|
+
print_info(f"Project directory {project_path} did not exist.")
|
|
58
|
+
|
|
59
|
+
docker.rm_service(db_service, force=True, stop=True, remove_volumes=False)
|
|
60
|
+
|
|
61
|
+
if docker.remove_volume(db_volume):
|
|
62
|
+
print_success(f"Removed volume: {db_volume}")
|
|
63
|
+
else:
|
|
64
|
+
print_warning(
|
|
65
|
+
f"Could not remove volume {db_volume} (may not exist or in use)"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
db_name, db_user = get_db_config()
|
|
69
|
+
try:
|
|
70
|
+
docker.up(services=[db_service], profile=db_service)
|
|
71
|
+
print_info(f"{db_service.capitalize()} service recreated.")
|
|
72
|
+
|
|
73
|
+
if db_service == "postgres":
|
|
74
|
+
sql = f"CREATE DATABASE IF NOT EXISTS {db_name} OWNER {db_user};"
|
|
75
|
+
docker.exec(
|
|
76
|
+
"postgres",
|
|
77
|
+
"sh",
|
|
78
|
+
"-c",
|
|
79
|
+
f'psql -U {db_user} -d postgres -c "{sql}" 2>/dev/null || true',
|
|
80
|
+
check=False,
|
|
81
|
+
)
|
|
82
|
+
print_success(f"Ensured database '{db_name}' exists.")
|
|
83
|
+
else:
|
|
84
|
+
print_info(
|
|
85
|
+
"MongoDB service recreated. DB will be initialized by the app "
|
|
86
|
+
"on first use."
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
ensure_payload_project()
|
|
90
|
+
except Exception as e:
|
|
91
|
+
print_warning(
|
|
92
|
+
f"Issue recreating {db_service} or DB: {e}. "
|
|
93
|
+
"Manual `xgic up --profile …` may be needed."
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if rotate:
|
|
97
|
+
print_info("Rotating credentials (--rotate-credentials)...")
|
|
98
|
+
rc = perform_env_regenerate(yes=True)
|
|
99
|
+
if rc == 0:
|
|
100
|
+
print_success("Credentials rotated in .env.")
|
|
101
|
+
else:
|
|
102
|
+
print_warning("Credential rotation had issues (check .env).")
|
|
103
|
+
|
|
104
|
+
print_success(
|
|
105
|
+
"Reset complete. Project ensured. Next: `xgic payload dev` "
|
|
106
|
+
"(or `xgic up --profile …`)."
|
|
107
|
+
)
|
|
108
|
+
return 0
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""``xgic payload schema`` — generate create-payload-config JSON schema."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from xgic.cli.app import CommandContext
|
|
10
|
+
from xgic.cli.utils.output import print_info, print_success, print_warning
|
|
11
|
+
|
|
12
|
+
GENERATOR = Path(".devcontainer/config/generate_schema.py")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def run_schema(ctx: CommandContext) -> int:
|
|
16
|
+
"""Generate (or refresh) the create-payload-config schema when present."""
|
|
17
|
+
script = Path(getattr(ctx.args, "generator", None) or GENERATOR)
|
|
18
|
+
if not script.exists():
|
|
19
|
+
print_warning(f"Generator not found: {script}")
|
|
20
|
+
print_info(
|
|
21
|
+
"This command expects a Payload CMS Dev Containers template "
|
|
22
|
+
"with .devcontainer/config/generate_schema.py"
|
|
23
|
+
)
|
|
24
|
+
return 1
|
|
25
|
+
|
|
26
|
+
print_info("Generating create-payload-config JSON schema...")
|
|
27
|
+
try:
|
|
28
|
+
subprocess.check_call([sys.executable, str(script)])
|
|
29
|
+
print_success(
|
|
30
|
+
"Schema written. IntelliSense updated for create-payload-config.json"
|
|
31
|
+
)
|
|
32
|
+
return 0
|
|
33
|
+
except subprocess.CalledProcessError as e:
|
|
34
|
+
print_warning(f"Generator exited with code {e.returncode}")
|
|
35
|
+
return e.returncode or 1
|
|
36
|
+
except Exception as e:
|
|
37
|
+
print_warning(f"Failed to run generator: {e}")
|
|
38
|
+
return 1
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""``xgic payload setup`` — ensure Payload CMS project directory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from xgic.cli.app import CommandContext
|
|
6
|
+
from xgic.cli.payload.project import ensure_payload_project
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_setup_payloadcms(ctx: CommandContext) -> int:
|
|
10
|
+
"""Idempotent Payload CMS project ensure."""
|
|
11
|
+
quiet = bool(getattr(ctx.args, "quiet", False))
|
|
12
|
+
return ensure_payload_project(quiet=quiet)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Payload CMS product defaults and config readers.
|
|
2
|
+
|
|
3
|
+
Used with ``xgic.cli.dev.DockerComposeController`` for the public Payload CMS
|
|
4
|
+
Dev Containers template. Core and dev-cli stay free of these product names.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from xgic.cli.core.environment import EnvironmentContext
|
|
14
|
+
from xgic.cli.dev.docker import DockerComposeController
|
|
15
|
+
|
|
16
|
+
DEFAULT_COMPOSE_PROJECT = "xgic-payload-cms-dev-containers"
|
|
17
|
+
DEFAULT_PRIMARY_SERVICE = "xgic-payload-cms-dev-containers"
|
|
18
|
+
DEFAULT_CONFIG_FILE = Path(".devcontainer/create-payload-config.json")
|
|
19
|
+
DEFAULT_COMPOSE_FILE = ".devcontainer/docker-compose.yml"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_payload_project_name(
|
|
23
|
+
config_file: Path = DEFAULT_CONFIG_FILE,
|
|
24
|
+
) -> str:
|
|
25
|
+
"""Return the name of the generated Payload CMS project folder."""
|
|
26
|
+
if config_file.exists():
|
|
27
|
+
try:
|
|
28
|
+
with open(config_file, encoding="utf-8") as f:
|
|
29
|
+
data: dict[str, Any] = json.load(f)
|
|
30
|
+
if name := data.get("projectName"):
|
|
31
|
+
return str(name)
|
|
32
|
+
except (json.JSONDecodeError, OSError):
|
|
33
|
+
pass
|
|
34
|
+
return "my-payload-cms"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_db_config(
|
|
38
|
+
config_file: Path = DEFAULT_CONFIG_FILE,
|
|
39
|
+
) -> tuple[str, str]:
|
|
40
|
+
"""Return (db_name, db_user) from create-payload-config.json."""
|
|
41
|
+
default_db = "payload_db"
|
|
42
|
+
default_user = "payload"
|
|
43
|
+
if not config_file.exists():
|
|
44
|
+
return default_db, default_user
|
|
45
|
+
try:
|
|
46
|
+
with config_file.open(encoding="utf-8") as f:
|
|
47
|
+
cfg: dict[str, Any] = json.load(f)
|
|
48
|
+
db_name = cfg.get("dbName") or default_db
|
|
49
|
+
db_user = cfg.get("dbUser") or default_user
|
|
50
|
+
db_uri = cfg.get("dbUri") or ""
|
|
51
|
+
if db_uri and (db_name == default_db or db_user == default_user):
|
|
52
|
+
try:
|
|
53
|
+
if "://" in db_uri:
|
|
54
|
+
after = db_uri.split("://", 1)[1]
|
|
55
|
+
if "@" in after and db_user == default_user:
|
|
56
|
+
creds = after.split("@", 1)[0]
|
|
57
|
+
if ":" in creds:
|
|
58
|
+
db_user = creds.split(":", 1)[0] or db_user
|
|
59
|
+
if "/" in after and db_name == default_db:
|
|
60
|
+
after_host = after.split("@", 1)[-1]
|
|
61
|
+
path = after_host.split("/", 1)[-1].split("?")[0]
|
|
62
|
+
if path:
|
|
63
|
+
db_name = path or db_name
|
|
64
|
+
except Exception:
|
|
65
|
+
pass
|
|
66
|
+
return db_name, db_user
|
|
67
|
+
except Exception:
|
|
68
|
+
return default_db, default_user
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_db_profile(config_file: Path = DEFAULT_CONFIG_FILE) -> str:
|
|
72
|
+
"""Return compose profile for the active DB adapter (postgres|mongodb)."""
|
|
73
|
+
if not config_file.exists():
|
|
74
|
+
return "postgres"
|
|
75
|
+
try:
|
|
76
|
+
with config_file.open(encoding="utf-8") as f:
|
|
77
|
+
cfg: dict[str, Any] = json.load(f)
|
|
78
|
+
adapter = str(cfg.get("dbAdapter", "postgres")).lower()
|
|
79
|
+
if adapter == "mongodb":
|
|
80
|
+
return "mongodb"
|
|
81
|
+
return "postgres"
|
|
82
|
+
except Exception:
|
|
83
|
+
return "postgres"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def make_payload_docker_controller(
|
|
87
|
+
env: EnvironmentContext,
|
|
88
|
+
) -> DockerComposeController:
|
|
89
|
+
"""Build a Compose controller with Payload CMS template defaults."""
|
|
90
|
+
return DockerComposeController(
|
|
91
|
+
env=env,
|
|
92
|
+
compose_file=DEFAULT_COMPOSE_FILE,
|
|
93
|
+
project_name=DEFAULT_COMPOSE_PROJECT,
|
|
94
|
+
primary_service=DEFAULT_PRIMARY_SERVICE,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def db_ready(
|
|
99
|
+
docker: DockerComposeController,
|
|
100
|
+
*,
|
|
101
|
+
config_file: Path = DEFAULT_CONFIG_FILE,
|
|
102
|
+
) -> bool:
|
|
103
|
+
"""Return True if the active DB service accepts connections."""
|
|
104
|
+
service = get_db_profile(config_file)
|
|
105
|
+
if service == "mongodb":
|
|
106
|
+
try:
|
|
107
|
+
result = docker._run_compose( # noqa: SLF001 — intentional thin probe
|
|
108
|
+
"exec",
|
|
109
|
+
"-T",
|
|
110
|
+
service,
|
|
111
|
+
"mongosh",
|
|
112
|
+
"--quiet",
|
|
113
|
+
"--eval",
|
|
114
|
+
"db.runCommand({ping: 1})",
|
|
115
|
+
capture_output=True,
|
|
116
|
+
check=False,
|
|
117
|
+
)
|
|
118
|
+
return result.returncode == 0
|
|
119
|
+
except Exception:
|
|
120
|
+
return False
|
|
121
|
+
|
|
122
|
+
_, db_user = get_db_config(config_file)
|
|
123
|
+
try:
|
|
124
|
+
result = docker._run_compose( # noqa: SLF001
|
|
125
|
+
"exec",
|
|
126
|
+
"-T",
|
|
127
|
+
"postgres",
|
|
128
|
+
"pg_isready",
|
|
129
|
+
"-U",
|
|
130
|
+
db_user,
|
|
131
|
+
capture_output=True,
|
|
132
|
+
check=False,
|
|
133
|
+
)
|
|
134
|
+
return result.returncode == 0
|
|
135
|
+
except Exception:
|
|
136
|
+
return False
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Payload CMS product env file generation (credentials + secrets)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import secrets
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from xgic.cli.payload.config import DEFAULT_CONFIG_FILE, get_db_config
|
|
10
|
+
from xgic.cli.utils.output import print_info, print_success, print_warning
|
|
11
|
+
|
|
12
|
+
ENV_FILE = Path(".devcontainer/.env")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def generate_fresh_env_content(
|
|
16
|
+
*,
|
|
17
|
+
config_file: Path = DEFAULT_CONFIG_FILE,
|
|
18
|
+
) -> str:
|
|
19
|
+
"""Pure: return .env content with fresh secrets + db from config."""
|
|
20
|
+
db_name, db_user = get_db_config(config_file)
|
|
21
|
+
payload_secret = secrets.token_hex(32)
|
|
22
|
+
|
|
23
|
+
adapter = "postgres"
|
|
24
|
+
if config_file.exists():
|
|
25
|
+
try:
|
|
26
|
+
with config_file.open(encoding="utf-8") as f:
|
|
27
|
+
cfg = json.load(f)
|
|
28
|
+
adapter = str(cfg.get("dbAdapter", "postgres")).lower()
|
|
29
|
+
except Exception:
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
if adapter == "mongodb":
|
|
33
|
+
mongo_pass = secrets.token_hex(16)
|
|
34
|
+
return f"""MONGO_INITDB_ROOT_USERNAME={db_user}
|
|
35
|
+
MONGO_INITDB_ROOT_PASSWORD={mongo_pass}
|
|
36
|
+
MONGO_INITDB_DATABASE={db_name}
|
|
37
|
+
PAYLOAD_SECRET={payload_secret}
|
|
38
|
+
DATABASE_URI=mongodb://{db_user}:{mongo_pass}@mongodb:27017/{db_name}?authSource=admin
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
pg_pass = secrets.token_hex(16)
|
|
42
|
+
return f"""POSTGRES_USER={db_user}
|
|
43
|
+
POSTGRES_PASSWORD={pg_pass}
|
|
44
|
+
POSTGRES_DB={db_name}
|
|
45
|
+
PAYLOAD_SECRET={payload_secret}
|
|
46
|
+
DATABASE_URI=postgres://{db_user}:{pg_pass}@postgres:5432/{db_name}
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def perform_env_regenerate(
|
|
51
|
+
*,
|
|
52
|
+
dry_run: bool = False,
|
|
53
|
+
yes: bool = False,
|
|
54
|
+
env_file: Path = ENV_FILE,
|
|
55
|
+
config_file: Path = DEFAULT_CONFIG_FILE,
|
|
56
|
+
) -> int:
|
|
57
|
+
"""Regenerate .env with fresh credentials (guarded by --yes / dry-run)."""
|
|
58
|
+
if dry_run:
|
|
59
|
+
content = generate_fresh_env_content(config_file=config_file)
|
|
60
|
+
print_info("Dry run: would write fresh credentials to .env")
|
|
61
|
+
print_info(f" (content length: {len(content)} chars)")
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
if not yes:
|
|
65
|
+
print_warning("This will overwrite .env with new random credentials.")
|
|
66
|
+
print_warning("Re-run with --yes to proceed.")
|
|
67
|
+
return 1
|
|
68
|
+
|
|
69
|
+
content = generate_fresh_env_content(config_file=config_file)
|
|
70
|
+
try:
|
|
71
|
+
env_file.parent.mkdir(parents=True, exist_ok=True)
|
|
72
|
+
with env_file.open("w", encoding="utf-8") as f:
|
|
73
|
+
f.write(content)
|
|
74
|
+
db_name, db_user = get_db_config(config_file)
|
|
75
|
+
adapter = "postgres"
|
|
76
|
+
if config_file.exists():
|
|
77
|
+
try:
|
|
78
|
+
with config_file.open(encoding="utf-8") as f:
|
|
79
|
+
cfg = json.load(f)
|
|
80
|
+
adapter = str(cfg.get("dbAdapter", "postgres")).lower()
|
|
81
|
+
except Exception:
|
|
82
|
+
pass
|
|
83
|
+
print_success(f"Generated fresh credentials in {env_file}")
|
|
84
|
+
if adapter == "mongodb":
|
|
85
|
+
print_info(f" (MONGO DB for {db_name})")
|
|
86
|
+
else:
|
|
87
|
+
print_info(f" (POSTGRES_DB={db_name}, POSTGRES_USER={db_user})")
|
|
88
|
+
return 0
|
|
89
|
+
except Exception as e:
|
|
90
|
+
print_warning(f"Failed to write {env_file}: {e}")
|
|
91
|
+
return 1
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Register ``xgic.cli.payload`` subcommands on the core ``xgic`` CLI.
|
|
2
|
+
|
|
3
|
+
All product commands live under the ``payload`` group for domain ownership::
|
|
4
|
+
|
|
5
|
+
xgic payload dev
|
|
6
|
+
xgic payload setup
|
|
7
|
+
xgic payload env
|
|
8
|
+
xgic payload schema
|
|
9
|
+
xgic payload reset
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
|
|
16
|
+
from xgic.cli.payload.commands.dev import run_dev
|
|
17
|
+
from xgic.cli.payload.commands.payload_env import run_payload_env
|
|
18
|
+
from xgic.cli.payload.commands.reset import run_reset
|
|
19
|
+
from xgic.cli.payload.commands.schema import run_schema
|
|
20
|
+
from xgic.cli.payload.commands.setup import run_setup_payloadcms
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def register(
|
|
24
|
+
subparsers: argparse._SubParsersAction[argparse.ArgumentParser],
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Entry point: ``xgic.cli.commands`` → Payload CMS product commands."""
|
|
27
|
+
payload = subparsers.add_parser(
|
|
28
|
+
"payload",
|
|
29
|
+
help="Payload CMS product commands",
|
|
30
|
+
)
|
|
31
|
+
payload_sub = payload.add_subparsers(
|
|
32
|
+
dest="payload_command",
|
|
33
|
+
help="Payload CMS action",
|
|
34
|
+
metavar="ACTION",
|
|
35
|
+
required=True,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# Smart daily command (maps from transitional `xde dev`)
|
|
39
|
+
dev = payload_sub.add_parser(
|
|
40
|
+
"dev",
|
|
41
|
+
help="Start Payload CMS app dev server (smart: up + db check + pnpm dev)",
|
|
42
|
+
)
|
|
43
|
+
dev.set_defaults(func=run_dev)
|
|
44
|
+
|
|
45
|
+
# Ensure project directory
|
|
46
|
+
setup = payload_sub.add_parser(
|
|
47
|
+
"setup",
|
|
48
|
+
help="Ensure Payload CMS project exists (idempotent)",
|
|
49
|
+
)
|
|
50
|
+
setup.add_argument(
|
|
51
|
+
"--quiet",
|
|
52
|
+
action="store_true",
|
|
53
|
+
help="Suppress non-error output",
|
|
54
|
+
)
|
|
55
|
+
setup.set_defaults(func=run_setup_payloadcms)
|
|
56
|
+
|
|
57
|
+
# Product env (distinct from generic `xgic env` in xgic.cli.dev)
|
|
58
|
+
penv = payload_sub.add_parser(
|
|
59
|
+
"env",
|
|
60
|
+
help="Payload CMS env status and credential regenerate",
|
|
61
|
+
)
|
|
62
|
+
penv.add_argument(
|
|
63
|
+
"--json",
|
|
64
|
+
action="store_true",
|
|
65
|
+
help="Output status as JSON",
|
|
66
|
+
)
|
|
67
|
+
penv.add_argument(
|
|
68
|
+
"--regenerate",
|
|
69
|
+
action="store_true",
|
|
70
|
+
help="Write fresh credentials to .devcontainer/.env",
|
|
71
|
+
)
|
|
72
|
+
penv.add_argument(
|
|
73
|
+
"--yes",
|
|
74
|
+
action="store_true",
|
|
75
|
+
help="Confirm regenerate without prompt",
|
|
76
|
+
)
|
|
77
|
+
penv.add_argument(
|
|
78
|
+
"--dry-run",
|
|
79
|
+
action="store_true",
|
|
80
|
+
help="Preview regenerate without writing",
|
|
81
|
+
)
|
|
82
|
+
penv.add_argument(
|
|
83
|
+
"--env-file",
|
|
84
|
+
metavar="PATH",
|
|
85
|
+
help="Override path to .env (default .devcontainer/.env)",
|
|
86
|
+
)
|
|
87
|
+
penv.set_defaults(func=run_payload_env)
|
|
88
|
+
|
|
89
|
+
# Schema generator for create-payload-config
|
|
90
|
+
schema = payload_sub.add_parser(
|
|
91
|
+
"schema",
|
|
92
|
+
help="Generate create-payload-config JSON schema (template helper)",
|
|
93
|
+
)
|
|
94
|
+
schema.add_argument(
|
|
95
|
+
"--generator",
|
|
96
|
+
metavar="PATH",
|
|
97
|
+
help="Override path to generate_schema.py",
|
|
98
|
+
)
|
|
99
|
+
schema.set_defaults(func=run_schema)
|
|
100
|
+
|
|
101
|
+
# Targeted reset (project dir + DB volume)
|
|
102
|
+
reset = payload_sub.add_parser(
|
|
103
|
+
"reset",
|
|
104
|
+
help="Fast targeted reset (project folder + active DB volume)",
|
|
105
|
+
)
|
|
106
|
+
reset.add_argument(
|
|
107
|
+
"--yes",
|
|
108
|
+
action="store_true",
|
|
109
|
+
help="Skip confirmation and proceed",
|
|
110
|
+
)
|
|
111
|
+
reset.add_argument(
|
|
112
|
+
"--dry-run",
|
|
113
|
+
action="store_true",
|
|
114
|
+
help="Show planned actions without making changes",
|
|
115
|
+
)
|
|
116
|
+
reset.add_argument(
|
|
117
|
+
"--rotate-credentials",
|
|
118
|
+
action="store_true",
|
|
119
|
+
help="Also regenerate .devcontainer/.env credentials",
|
|
120
|
+
)
|
|
121
|
+
reset.set_defaults(func=run_reset)
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Payload CMS project setup / ensure helpers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import subprocess
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from xgic.cli.payload.config import DEFAULT_CONFIG_FILE
|
|
14
|
+
from xgic.cli.utils.output import print_info, print_success, print_warning
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def load_create_payload_config(
|
|
18
|
+
config_path: Path = DEFAULT_CONFIG_FILE,
|
|
19
|
+
) -> dict[str, Any]:
|
|
20
|
+
"""Load create-payload-config.json (or sensible defaults)."""
|
|
21
|
+
defaults: dict[str, Any] = {
|
|
22
|
+
"projectName": "my-payload-cms",
|
|
23
|
+
"template": "website",
|
|
24
|
+
"dbAdapter": "postgres",
|
|
25
|
+
"agent": "none",
|
|
26
|
+
"dbUri": "",
|
|
27
|
+
}
|
|
28
|
+
if not config_path.exists():
|
|
29
|
+
return defaults
|
|
30
|
+
try:
|
|
31
|
+
with config_path.open(encoding="utf-8") as f:
|
|
32
|
+
data: dict[str, Any] = json.load(f)
|
|
33
|
+
for k, v in data.items():
|
|
34
|
+
if v is not None:
|
|
35
|
+
defaults[k] = v
|
|
36
|
+
return defaults
|
|
37
|
+
except (json.JSONDecodeError, OSError):
|
|
38
|
+
return defaults
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get_project_name(config: dict[str, Any]) -> str:
|
|
42
|
+
"""Extract projectName with safe default."""
|
|
43
|
+
name = config.get("projectName")
|
|
44
|
+
if isinstance(name, str) and name.strip():
|
|
45
|
+
return name.strip()
|
|
46
|
+
return "my-payload-cms"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def is_payload_project_complete(project_dir: Path) -> bool:
|
|
50
|
+
"""Return True if project_dir looks like a finished Payload CMS app."""
|
|
51
|
+
if not project_dir.is_dir():
|
|
52
|
+
return False
|
|
53
|
+
candidates = [
|
|
54
|
+
project_dir / "payload.config.ts",
|
|
55
|
+
project_dir / "payload.config.js",
|
|
56
|
+
project_dir / "src" / "payload.config.ts",
|
|
57
|
+
project_dir / "src" / "payload.config.js",
|
|
58
|
+
]
|
|
59
|
+
return any(p.exists() for p in candidates)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def build_create_payload_command(
|
|
63
|
+
project_name: str,
|
|
64
|
+
*,
|
|
65
|
+
template: str = "website",
|
|
66
|
+
db_adapter: str = "postgres",
|
|
67
|
+
db_connection_string: str | None = None,
|
|
68
|
+
agent: str = "none",
|
|
69
|
+
) -> list[str]:
|
|
70
|
+
"""Return the argv list for a non-interactive create-payload-app run."""
|
|
71
|
+
cmd = [
|
|
72
|
+
"pnpx",
|
|
73
|
+
"create-payload-app@latest",
|
|
74
|
+
project_name,
|
|
75
|
+
"-t",
|
|
76
|
+
template,
|
|
77
|
+
"--use-pnpm",
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
if db_connection_string:
|
|
81
|
+
cmd.extend(
|
|
82
|
+
["--db", db_adapter, "--db-connection-string", db_connection_string]
|
|
83
|
+
)
|
|
84
|
+
else:
|
|
85
|
+
cmd.extend(["--db", db_adapter, "--db-accept-recommended"])
|
|
86
|
+
|
|
87
|
+
if agent and str(agent).lower() not in ("", "none"):
|
|
88
|
+
cmd.extend(["--agent", str(agent)])
|
|
89
|
+
else:
|
|
90
|
+
cmd.append("--no-agent")
|
|
91
|
+
|
|
92
|
+
return cmd
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def resolve_db_connection_string(
|
|
96
|
+
json_db_uri: str, live_db_uri: str
|
|
97
|
+
) -> str | None:
|
|
98
|
+
"""Prefer live env DB URI over config JSON."""
|
|
99
|
+
return live_db_uri or json_db_uri or None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def compute_synced_project_env_content(
|
|
103
|
+
original_content: str, live_db_uri: str, live_payload_secret: str
|
|
104
|
+
) -> str:
|
|
105
|
+
"""Return .env content with live DATABASE_URL / PAYLOAD_SECRET."""
|
|
106
|
+
content = original_content
|
|
107
|
+
if live_db_uri:
|
|
108
|
+
content = re.sub(
|
|
109
|
+
r"^DATABASE_URL=.*$",
|
|
110
|
+
f"DATABASE_URL={live_db_uri}",
|
|
111
|
+
content,
|
|
112
|
+
flags=re.MULTILINE,
|
|
113
|
+
)
|
|
114
|
+
if live_payload_secret:
|
|
115
|
+
content = re.sub(
|
|
116
|
+
r"^PAYLOAD_SECRET=.*$",
|
|
117
|
+
f"PAYLOAD_SECRET={live_payload_secret}",
|
|
118
|
+
content,
|
|
119
|
+
flags=re.MULTILINE,
|
|
120
|
+
)
|
|
121
|
+
return content
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _sync_live_env_into_project(
|
|
125
|
+
project_dir: Path, live_db_uri: str, live_payload_secret: str
|
|
126
|
+
) -> None:
|
|
127
|
+
"""Best-effort sync of live credentials into the generated project's .env."""
|
|
128
|
+
gen_env = project_dir / ".env"
|
|
129
|
+
if not gen_env.is_file():
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
content = gen_env.read_text(encoding="utf-8")
|
|
134
|
+
new_content = compute_synced_project_env_content(
|
|
135
|
+
content, live_db_uri, live_payload_secret
|
|
136
|
+
)
|
|
137
|
+
if new_content != content:
|
|
138
|
+
gen_env.write_text(new_content, encoding="utf-8")
|
|
139
|
+
except Exception:
|
|
140
|
+
pass
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def ensure_payload_project(*, quiet: bool = False) -> int:
|
|
144
|
+
"""Ensure the Payload CMS project directory exists and is usable."""
|
|
145
|
+
cfg = load_create_payload_config()
|
|
146
|
+
project_name = get_project_name(cfg)
|
|
147
|
+
project_dir = Path(project_name)
|
|
148
|
+
|
|
149
|
+
if is_payload_project_complete(project_dir):
|
|
150
|
+
return 0
|
|
151
|
+
|
|
152
|
+
if project_dir.exists() and not quiet:
|
|
153
|
+
print_warning(
|
|
154
|
+
f"Directory '{project_name}' exists but does not appear to be "
|
|
155
|
+
"a complete Payload CMS project. Creation may overwrite or fail."
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
template = str(cfg.get("template") or "website")
|
|
159
|
+
db_adapter = str(cfg.get("dbAdapter") or "postgres")
|
|
160
|
+
json_db_uri = str(cfg.get("dbUri") or "")
|
|
161
|
+
agent = str(cfg.get("agent") or "none")
|
|
162
|
+
|
|
163
|
+
live_db_uri = os.environ.get("DATABASE_URI", "")
|
|
164
|
+
live_secret = os.environ.get("PAYLOAD_SECRET", "")
|
|
165
|
+
|
|
166
|
+
db_uri_for_cli: str | None = resolve_db_connection_string(
|
|
167
|
+
json_db_uri, live_db_uri
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
with contextlib.suppress(Exception):
|
|
171
|
+
subprocess.run(
|
|
172
|
+
["corepack", "pnpm", "approve-builds", "@swc/core"],
|
|
173
|
+
check=False,
|
|
174
|
+
capture_output=True,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
cmd = build_create_payload_command(
|
|
178
|
+
project_name,
|
|
179
|
+
template=template,
|
|
180
|
+
db_adapter=db_adapter,
|
|
181
|
+
db_connection_string=db_uri_for_cli,
|
|
182
|
+
agent=agent,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
if not quiet:
|
|
186
|
+
print_info(
|
|
187
|
+
f"Starting Payload CMS project creation for '{project_name}' "
|
|
188
|
+
f"(template: {template}, db: {db_adapter})..."
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
result = subprocess.run(cmd, check=False)
|
|
193
|
+
except FileNotFoundError as e:
|
|
194
|
+
print_warning(f"Required tool not found for project creation: {e}")
|
|
195
|
+
return 1
|
|
196
|
+
|
|
197
|
+
if result.returncode == 0:
|
|
198
|
+
if not quiet:
|
|
199
|
+
print_success("Payload CMS project created successfully.")
|
|
200
|
+
if project_dir.is_dir():
|
|
201
|
+
_sync_live_env_into_project(project_dir, live_db_uri, live_secret)
|
|
202
|
+
return 0
|
|
203
|
+
|
|
204
|
+
if not quiet:
|
|
205
|
+
print_warning(
|
|
206
|
+
f"create-payload-app exited with status {result.returncode}."
|
|
207
|
+
)
|
|
208
|
+
print_info(
|
|
209
|
+
"This is often harmless. Check the project directory. "
|
|
210
|
+
"Re-run with the Payload CMS CLI module when available."
|
|
211
|
+
)
|
|
212
|
+
return 0
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xgic-payload-cms-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: XGIC CLI Payload CMS module - product commands and helpers (xgic.cli.payload).
|
|
5
|
+
Project-URL: Homepage, https://github.com/xgic/payload-cms-cli
|
|
6
|
+
Project-URL: Repository, https://github.com/xgic/payload-cms-cli
|
|
7
|
+
Project-URL: Issues, https://github.com/xgic/payload-cms-cli/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/xgic/payload-cms-cli#readme
|
|
9
|
+
Project-URL: Changelog, https://github.com/xgic/payload-cms-cli/releases
|
|
10
|
+
Author: XGIC
|
|
11
|
+
License: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Keywords: cli,orchestration,payload-cms,xgic
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.14
|
|
25
|
+
Requires-Dist: rich>=13.7
|
|
26
|
+
Requires-Dist: xgic-cli>=0.2.0
|
|
27
|
+
Requires-Dist: xgic-dev-cli>=0.2.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest>=8.0.0; extra == 'test'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# XGIC Payload CMS CLI
|
|
37
|
+
|
|
38
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
39
|
+
|
|
40
|
+
**XGIC Payload CMS CLI** (`xgic.cli.payload`) provides **Payload CMS–specific** helpers and **`xgic payload …` subcommands** for the modular [XGIC CLI](https://github.com/xgic/cli).
|
|
41
|
+
|
|
42
|
+
Architecture: [ADR-0005](https://github.com/xgic/ai/blob/main/docs/adr/0005-modular-xgic-cli-and-retirement-of-xde.md).
|
|
43
|
+
|
|
44
|
+
**Publishing to PyPI:** [python-package-release.md](https://github.com/xgic/ai/blob/main/docs/python-package-release.md)
|
|
45
|
+
(publish **after** `xgic-cli` and `xgic-dev-cli` for stack releases). Tags: `vX.Y.ZrcN` → TestPyPI; `vX.Y.Z` → PyPI.
|
|
46
|
+
|
|
47
|
+
| Package | Role |
|
|
48
|
+
|---------|------|
|
|
49
|
+
| [xgic/cli](https://github.com/xgic/cli) | Thin core framework (`xgic`) |
|
|
50
|
+
| [xgic/dev-cli](https://github.com/xgic/dev-cli) | Dev Container / Compose + generic lifecycle |
|
|
51
|
+
| **This repo** | Payload CMS product module (`xgic.cli.payload`) |
|
|
52
|
+
|
|
53
|
+
## Status
|
|
54
|
+
|
|
55
|
+
**0.2.0 — B4 product commands.** Library helpers + nested `xgic payload` command group. Transitional in-tree `xde` may still ship until hard cutover (B5).
|
|
56
|
+
|
|
57
|
+
## Requirements
|
|
58
|
+
|
|
59
|
+
- Python **3.14+**
|
|
60
|
+
- `xgic-cli` ≥ 0.2.0
|
|
61
|
+
- `xgic-dev-cli` ≥ 0.2.0
|
|
62
|
+
|
|
63
|
+
## Install (development)
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python -m pip install -e ../cli
|
|
67
|
+
python -m pip install -e ../dev-cli
|
|
68
|
+
python -m pip install -e ".[dev]"
|
|
69
|
+
xgic payload --help
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Console commands
|
|
73
|
+
|
|
74
|
+
All product commands are nested under **`xgic payload`** (domain ownership; no clash with generic lifecycle).
|
|
75
|
+
|
|
76
|
+
| Command | Purpose |
|
|
77
|
+
|---------|---------|
|
|
78
|
+
| `xgic payload dev` | Smart start: compose up if needed, DB check, `pnpm dev` |
|
|
79
|
+
| `xgic payload setup [--quiet]` | Ensure Payload CMS project directory |
|
|
80
|
+
| `xgic payload env [--json]` | Product env status (project name, .env, services) |
|
|
81
|
+
| `xgic payload env --regenerate --yes` | Fresh credentials in `.devcontainer/.env` |
|
|
82
|
+
| `xgic payload schema` | Run template schema generator when present |
|
|
83
|
+
| `xgic payload reset` | Fast targeted reset (project folder + DB volume) |
|
|
84
|
+
|
|
85
|
+
**Note:** Generic lifecycle (`xgic up` / `down` / `check` / `env`) lives in **dev-cli**.
|
|
86
|
+
Use `xgic payload env` for Payload CMS credentials and product status.
|
|
87
|
+
|
|
88
|
+
### Command map (transitional `xde` → XGIC CLI)
|
|
89
|
+
|
|
90
|
+
| Today (`xde`) | Target |
|
|
91
|
+
|---------------|--------|
|
|
92
|
+
| `xde dev` | `xgic payload dev` |
|
|
93
|
+
| `xde setup payloadcms` | `xgic payload setup` |
|
|
94
|
+
| `xde schema` | `xgic payload schema` |
|
|
95
|
+
| `xde env --regenerate` | `xgic payload env --regenerate --yes` |
|
|
96
|
+
| `xde reset` | `xgic payload reset` |
|
|
97
|
+
| `xde up` / `down` / … | `xgic up` / `down` / … (dev-cli) |
|
|
98
|
+
|
|
99
|
+
## Library API
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from xgic.cli.payload import (
|
|
103
|
+
ensure_payload_project,
|
|
104
|
+
generate_fresh_env_content,
|
|
105
|
+
make_payload_docker_controller,
|
|
106
|
+
get_payload_project_name,
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
113
|
+
Copyright form: `Copyright 2026 XGIC`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
xgic/cli/payload/__init__.py,sha256=04HBEfBv1336cp3qvErfPRzgWsB0WKD833j7B1WtcDs,980
|
|
2
|
+
xgic/cli/payload/config.py,sha256=agxzSwuBrdHZvMER_25mkIHNlVBGJUwyl773GJvwXzk,4532
|
|
3
|
+
xgic/cli/payload/env_helpers.py,sha256=7J0n5_7Z7BQnZnHQVVWrz70yOkqaEI5c_9xjlgplJK0,3033
|
|
4
|
+
xgic/cli/payload/plugin.py,sha256=vYRxfNtzX_jD8XWyjxPSX-gfq9tnE-jwEiYUPqqxNLI,3499
|
|
5
|
+
xgic/cli/payload/project.py,sha256=qwzcTypmod0N_58SEOXsZA48p-X8QY8Lefsd-liEijQ,6265
|
|
6
|
+
xgic/cli/payload/commands/__init__.py,sha256=2XjZS1iYhUw5QO7JrG0lCaeLd-66HFW5_jSyb_soYS8,53
|
|
7
|
+
xgic/cli/payload/commands/dev.py,sha256=yznAHsJh70Vw-RHDyNNSYDuTN8--YhdXPKUWtQzIGME,3019
|
|
8
|
+
xgic/cli/payload/commands/payload_env.py,sha256=IBTCTIcd7Q6Krg5z-nps6Ymvq4NdUKORsUpurbvCQgI,2232
|
|
9
|
+
xgic/cli/payload/commands/reset.py,sha256=0vgU18nNrC6he5bpIqyDl0LkjsVSvRuIttREtihltG0,3576
|
|
10
|
+
xgic/cli/payload/commands/schema.py,sha256=wLK3QLOrUCdkKxDOoFO3q2l-Fv1behsV69nhtwU4Sq0,1320
|
|
11
|
+
xgic/cli/payload/commands/setup.py,sha256=YbgjhZYc4u1kGAOu1WwFcOFbAuT3y9U-zbusAAZyGoc,412
|
|
12
|
+
xgic_payload_cms_cli-0.2.0.dist-info/METADATA,sha256=q_GADmO6pmYvdPm0m0hZTbCZHCh3gkTeiIwi-WWTp0w,4344
|
|
13
|
+
xgic_payload_cms_cli-0.2.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
14
|
+
xgic_payload_cms_cli-0.2.0.dist-info/entry_points.txt,sha256=5nTFyPIAAgwc8PZyc_wRu9gfYq6CCwlVi1oCSKBC02Q,63
|
|
15
|
+
xgic_payload_cms_cli-0.2.0.dist-info/licenses/LICENSE,sha256=zR7vJ5cGf_9LgWHYDAugptsXPsV0_78I9kvVnf7VRk0,11335
|
|
16
|
+
xgic_payload_cms_cli-0.2.0.dist-info/licenses/NOTICE,sha256=KcqsVZjszSfr06TJjV7mdutBiCXlvqtlLhnI4Pj8Jzs,212
|
|
17
|
+
xgic_payload_cms_cli-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 XGIC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|