36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""Generate the frontend category alias artifact from the backend source of truth."""
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from core.type_utils import CATEGORY_MAP
|
|
|
|
OUTPUT_PATH = PROJECT_ROOT / "web" / "resolver" / "utils" / "category_aliases.generated.js"
|
|
|
|
|
|
def main() -> None:
|
|
payload = json.dumps(CATEGORY_MAP, ensure_ascii=False, indent=4, sort_keys=True)
|
|
content = (
|
|
"// Generated by tools/generate_category_aliases.py. Do not edit manually.\n"
|
|
"export function normalizeCategoryToken(category) {\n"
|
|
" return String(category || '')\n"
|
|
" .trim()\n"
|
|
" .toLowerCase()\n"
|
|
" .replace(/[/\\\\\\s-]+/g, '_')\n"
|
|
" .replace(/_+/g, '_')\n"
|
|
" .replace(/^_|_$/g, '');\n"
|
|
"}\n\n"
|
|
"export const CATEGORY_ALIASES = Object.freeze(\n"
|
|
f"{payload}\n"
|
|
");\n"
|
|
)
|
|
OUTPUT_PATH.write_text(content, encoding="utf-8", newline="\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|