Files
yoyos.sh/tools/penpot/serve.py
T
Johan Sandoval bf0d1efa2c
Mirror to Gitea / mirror (push) Skipped
Penpot design workflow: baseline export, importer plugin, tokens
- tools/penpot/capture.mjs captures every page at 390 and 1440 px as
  editable layers (text, boxes, images) grouped by section
- tools/penpot/plugin: Penpot plugin that rebuilds the captures as
  native boards; serve.py hosts it locally; preview.html shows the result
- tools/penpot/tokens.mjs exports colours and fonts as design tokens
- design/README.md documents the design -> hand-off -> code loop
2026-10-08 19:40:41 +00:00

39 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Serve the Penpot importer plugin + captured baseline locally, with CORS.
python3 tools/penpot/serve.py # then in Penpot: Plugins → install
# http://localhost:4402/manifest.json
"""
import http.server
import os
from pathlib import Path
ROOT = Path(__file__).resolve().parent
REPO = ROOT.parent.parent
PORT = int(os.environ.get('PORT', 4402))
class Handler(http.server.SimpleHTTPRequestHandler):
def translate_path(self, path):
path = path.split('?', 1)[0]
if path.startswith('/baseline/'):
return str(REPO / 'design' / path.lstrip('/'))
return str(ROOT / 'plugin' / path.lstrip('/'))
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Private-Network', 'true')
self.send_header('Cache-Control', 'no-store')
super().end_headers()
def do_OPTIONS(self):
self.send_response(204)
self.send_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
self.send_header('Access-Control-Allow-Headers', '*')
self.end_headers()
if __name__ == '__main__':
print(f'Penpot plugin: http://localhost:{PORT}/manifest.json')
http.server.ThreadingHTTPServer(('127.0.0.1', PORT), Handler).serve_forever()