UNPKG

@zebrains/velund-python

Version:

Python-генератор для системы UI-компонентов Velund

24 lines (21 loc) 978 B
import fs from 'fs'; import path from 'path'; export function generateComponent(component, outDir) { const componentDir = path.join(outDir, 'components'); fs.mkdirSync(componentDir, { recursive: true }); const className = `${component.name}Component`; const fileName = `${className}.py`; const hasPrepare = component.prepare ? 'True' : 'False'; const compPy = `from typing import Any, Dict, Callable, Awaitable from .TemplateComponent import TemplateComponent import PrepareRegistry class ${className}(TemplateComponent): def __init__(self): super().__init__(${JSON.stringify(component.name)}, ${JSON.stringify(component.template)}, ${hasPrepare}) @staticmethod def register_prepare(fn: Callable[[Dict[str, Any]], Awaitable[Dict[str, Any]]]): PrepareRegistry.register(${JSON.stringify(component.name)}, fn) `; fs.writeFileSync(path.join(componentDir, fileName), compPy, 'utf-8'); } //# sourceMappingURL=Component.js.map