feat(cli): Add sync-tokens and setup-storybook commands

This commit is contained in:
DSS
2025-12-10 13:35:27 -03:00
parent 9c666430f5
commit 448ef886c9

View File

@@ -20,6 +20,9 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
try:
from dss.analyze.project_analyzer import run_project_analysis, export_project_context
from dss.project.manager import ProjectManager
from dss import StorybookScanner, StoryGenerator, ThemeGenerator
from dss.project.figma import FigmaProjectSync
except ImportError as e:
print(f"Error: Could not import DSS modules. Make sure dss-mvp1 is in the PYTHONPATH.", file=sys.stderr)
print(f"Import error: {e}", file=sys.stderr)
@@ -59,6 +62,65 @@ def main():
help="The path to the project directory."
)
# =========================================================================
# 'add-figma-file' command
# =========================================================================
add_figma_parser = subparsers.add_parser(
"add-figma-file",
help="Link a Figma file to a DSS project."
)
add_figma_parser.add_argument(
"--project-path",
required=True,
help="The path to the DSS project directory."
)
add_figma_parser.add_argument(
"--file-key",
required=True,
help="The file key of the Figma file (from the URL)."
)
add_figma_parser.add_argument(
"--file-name",
required=True,
help="A human-readable name for the Figma file."
)
# =========================================================================
# 'setup-storybook' command
# =========================================================================
storybook_parser = subparsers.add_parser(
"setup-storybook",
help="Scan, generate, or configure Storybook for a project."
)
storybook_parser.add_argument(
"--project-path",
required=True,
help="The path to the DSS project directory."
)
storybook_parser.add_argument(
"--action",
required=True,
choices=["scan", "generate", "configure"],
help="The Storybook action to perform."
)
# =========================================================================
# 'sync-tokens' command
# =========================================================================
sync_parser = subparsers.add_parser(
"sync-tokens",
help="Synchronize design tokens from the linked Figma file(s)."
)
sync_parser.add_argument(
"--project-path",
required=True,
help="The path to the DSS project directory."
)
sync_parser.add_argument(
"--figma-token",
help="Your Figma personal access token. If not provided, it will try to use the FIGMA_TOKEN environment variable."
)
args = parser.parse_args()
# --- Command Dispatch ---
@@ -84,6 +146,52 @@ def main():
# Print the full context to stdout
print(json.dumps(result, indent=2))
elif args.command == "add-figma-file":
manager = ProjectManager()
try:
project = manager.load(project_path)
except FileNotFoundError:
print(f"Error: No 'ds.config.json' found at {project_path}. Is this a valid DSS project?", file=sys.stderr)
sys.exit(1)
manager.add_figma_file(
project=project,
file_key=args.file_key,
file_name=args.file_name
)
print(f"Successfully added Figma file '{args.file_name}' to project '{project.config.name}'.")
elif args.command == "setup-storybook":
action = args.action
print(f"Running Storybook setup with action: {action}...")
if action == "scan":
scanner = StorybookScanner(project_path)
result = scanner.scan()
print(json.dumps(result, indent=2))
elif action == "generate":
generator = StoryGenerator(project_path)
result = generator.generate()
print(f"Successfully generated {len(result)} new stories.")
elif action == "configure":
theme_gen = ThemeGenerator(project_path)
result = theme_gen.generate()
print(f"Storybook theme configured at {result.get('theme_file')}")
print("Storybook setup complete.")
elif args.command == "sync-tokens":
manager = ProjectManager()
try:
project = manager.load(project_path)
except FileNotFoundError:
print(f"Error: No 'ds.config.json' found at {project_path}. Is this a valid DSS project?", file=sys.stderr)
sys.exit(1)
print("Synchronizing tokens from Figma...")
manager.sync(project, figma_token=args.figma_token)
print("Token synchronization complete.")
except Exception as e:
print(json.dumps({"success": False, "error": str(e)}), file=sys.stderr)
sys.exit(1)