Alexander ef5f5ba0e6
fix(cli): install all 7 skills via uipro init, not just the orchestrator (#362) (#387)
* fix(cli): install all 7 skills via uipro init, not just the orchestrator

`uipro init` rendered only the orchestrator (ui-ux-pro-max) and never
delivered the 6 sibling skills (banner-design, brand, design,
design-system, slides, ui-styling), so users got 1 of 7 skills (#362).

- sync-assets.mjs: bundle the 6 sub-skills into cli/assets/skills/ as
  static copies (source of truth: .claude/skills/), with sync + check
  coverage. Excludes ui-styling/canvas-fonts (~5.8MB of TTF) and
  __pycache__/.pyc cruft — a skill registers from its SKILL.md, not its
  fonts — so the bundle adds ~0.9MB, not ~6.6MB.
- template.ts: after rendering the orchestrator, install each bundled
  sub-skill as a sibling. The skills parent is derived from the
  platform's skillPath (skills/ for most, prompts/ for copilot,
  steering/ for kiro) rather than hardcoded.
- uninstall.ts: remove the sub-skills too.

Verified: check:assets in sync, tsc passes, and a per-platform install
harness delivers all 7 skills to the correct parent dir with no fonts.

Closes #362

* fix(cli): filter excluded files from target side of check:assets

check:assets filtered sourceFiles with isExcludedAssetFile but not
targetFiles, so a stray cli/assets/scripts/__pycache__/*.pyc (generated
by a local Python run) was reported as an "extra asset file" and failed
the gate. Apply the same predicate to targetFiles in both the
dirsToSync and sub-skill loops.

Verified: check:assets now passes with __pycache__/*.pyc present in the
target tree; typecheck passes.

* fix(cli): uninstall from each platform's real skills dir, not hardcoded skills/

removeSkillDir() hardcoded <folder>/skills/<name>, but the installer
places skills under each platform config's skillPath parent — copilot in
.github/prompts/, kiro in .kiro/steering/. So uninstall left those
platforms' skills (orchestrator + sub-skills) behind.

Derive the install parent from loadPlatformConfig(aiType).folderStructure
(same source the installer uses), and keep the legacy <folder>/skills/
cleanup (incl. .shared/) for older installs. Deduped via a Set.

Verified: typecheck passes; an install+uninstall harness removes all 7
skills with zero leftovers for claude (.claude/skills), copilot
(.github/prompts) and kiro (.kiro/steering).

* fix(cli): re-sync bundled sub-skills after #385 stripped ckm- names

#385 merged to main and removed the ckm- prefix from the six
.claude/skills/*/SKILL.md name fields. This branch's bundled copies
under cli/assets/skills/ still carried the old ckm- names, so after the
PR merges with main the source no longer matched the bundle and the
check-asset-sync CI gate failed (stale asset file: skills/*/SKILL.md).

Merge main and regenerate the bundle so cli/assets/skills matches the
current .claude/skills source of truth. check:assets and typecheck pass.
2026-06-25 17:33:23 +07:00

309 lines
8.6 KiB
Python

#!/usr/bin/env python3
"""
shadcn/ui Component Installer
Add shadcn/ui components to project with automatic dependency handling.
Wraps shadcn CLI for programmatic component installation.
"""
import argparse
import json
import subprocess
import sys
from pathlib import Path
from typing import List, Optional
class ShadcnInstaller:
"""Handle shadcn/ui component installation."""
def __init__(self, project_root: Optional[Path] = None, dry_run: bool = False):
"""
Initialize installer.
Args:
project_root: Project root directory (default: current directory)
dry_run: If True, show actions without executing
"""
self.project_root = project_root or Path.cwd()
self.dry_run = dry_run
self.components_json = self.project_root / "components.json"
def check_shadcn_config(self) -> bool:
"""
Check if shadcn is initialized in project.
Returns:
True if components.json exists
"""
return self.components_json.exists()
def get_installed_components(self) -> List[str]:
"""
Get list of already installed components.
Returns:
List of installed component names
"""
if not self.check_shadcn_config():
return []
try:
with open(self.components_json) as f:
config = json.load(f)
components_dir = self.project_root / config.get("aliases", {}).get(
"components", "components"
).replace("@/", "")
ui_dir = components_dir / "ui"
if not ui_dir.exists():
return []
return [f.stem for f in ui_dir.glob("*.tsx") if f.is_file()]
except (json.JSONDecodeError, KeyError, OSError):
return []
def _get_shadcn_version(self) -> str:
"""Read shadcn version from project package.json; fall back to a pinned default."""
pkg_json = self.project_root / "package.json"
if pkg_json.exists():
try:
pkg = json.loads(pkg_json.read_text())
for section in ("dependencies", "devDependencies"):
version = pkg.get(section, {}).get("shadcn")
if version:
return version.lstrip("^~>=<").split()[0]
except (json.JSONDecodeError, KeyError):
pass
return "2.3.0" # pinned fallback; update when newer stable release is needed
def add_components(
self, components: List[str], overwrite: bool = False
) -> tuple[bool, str]:
"""
Add shadcn/ui components.
Args:
components: List of component names to add
overwrite: If True, overwrite existing components
Returns:
Tuple of (success, message)
"""
if not components:
return False, "No components specified"
if not self.check_shadcn_config():
return (
False,
"shadcn not initialized. Run 'npx shadcn@latest init' first",
)
# Check which components already exist
installed = self.get_installed_components()
already_installed = [c for c in components if c in installed]
if already_installed and not overwrite:
return (
False,
f"Components already installed: {', '.join(already_installed)}. "
"Use --overwrite to reinstall",
)
# Build command
shadcn_version = self._get_shadcn_version()
cmd = ["npx", f"shadcn@{shadcn_version}", "add"] + components
if overwrite:
cmd.append("--overwrite")
if self.dry_run:
return True, f"Would run: {' '.join(cmd)}"
# Execute command
try:
result = subprocess.run(
cmd,
cwd=self.project_root,
capture_output=True,
text=True,
check=True,
)
success_msg = f"Successfully added components: {', '.join(components)}"
if result.stdout:
success_msg += f"\n\nOutput:\n{result.stdout}"
return True, success_msg
except subprocess.CalledProcessError as e:
error_msg = f"Failed to add components: {e.stderr or e.stdout or str(e)}"
return False, error_msg
except FileNotFoundError:
return False, "npx not found. Ensure Node.js is installed"
def add_all_components(self, overwrite: bool = False) -> tuple[bool, str]:
"""
Add all available shadcn/ui components.
Args:
overwrite: If True, overwrite existing components
Returns:
Tuple of (success, message)
"""
if not self.check_shadcn_config():
return (
False,
"shadcn not initialized. Run 'npx shadcn@latest init' first",
)
shadcn_version = self._get_shadcn_version()
cmd = ["npx", f"shadcn@{shadcn_version}", "add", "--all"]
if overwrite:
cmd.append("--overwrite")
if self.dry_run:
return True, f"Would run: {' '.join(cmd)}"
try:
result = subprocess.run(
cmd,
cwd=self.project_root,
capture_output=True,
text=True,
check=True,
)
success_msg = "Successfully added all components"
if result.stdout:
success_msg += f"\n\nOutput:\n{result.stdout}"
return True, success_msg
except subprocess.CalledProcessError as e:
error_msg = f"Failed to add all components: {e.stderr or e.stdout or str(e)}"
return False, error_msg
except FileNotFoundError:
return False, "npx not found. Ensure Node.js is installed"
def list_installed(self) -> tuple[bool, str]:
"""
List installed components.
Returns:
Tuple of (success, message with component list)
"""
if not self.check_shadcn_config():
return False, "shadcn not initialized"
installed = self.get_installed_components()
if not installed:
return True, "No components installed"
return True, f"Installed components:\n" + "\n".join(f" - {c}" for c in sorted(installed))
def main():
"""CLI entry point."""
parser = argparse.ArgumentParser(
description="Add shadcn/ui components to your project",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Add single component
python shadcn_add.py button
# Add multiple components
python shadcn_add.py button card dialog
# Add all components
python shadcn_add.py --all
# Overwrite existing components
python shadcn_add.py button --overwrite
# Dry run (show what would be done)
python shadcn_add.py button card --dry-run
# List installed components
python shadcn_add.py --list
""",
)
parser.add_argument(
"components",
nargs="*",
help="Component names to add (e.g., button, card, dialog)",
)
parser.add_argument(
"--all",
action="store_true",
help="Add all available components",
)
parser.add_argument(
"--overwrite",
action="store_true",
help="Overwrite existing components",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Show what would be done without executing",
)
parser.add_argument(
"--list",
action="store_true",
help="List installed components",
)
parser.add_argument(
"--project-root",
type=Path,
help="Project root directory (default: current directory)",
)
args = parser.parse_args()
# Initialize installer
installer = ShadcnInstaller(
project_root=args.project_root,
dry_run=args.dry_run,
)
# Handle list command
if args.list:
success, message = installer.list_installed()
print(message)
sys.exit(0 if success else 1)
# Handle add all command
if args.all:
success, message = installer.add_all_components(overwrite=args.overwrite)
print(message)
sys.exit(0 if success else 1)
# Handle add specific components
if not args.components:
parser.print_help()
sys.exit(1)
success, message = installer.add_components(
args.components,
overwrite=args.overwrite,
)
print(message)
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()