summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-22 11:41:49 -0400
committerxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-22 11:41:49 -0400
commitdfe4c033dd1922a63c8393ab467e9aa58fa757e4 (patch)
treee6e518f4becdf0edd1e5f6fefd060b5c9060f010 /scripts
parentc02343e68874efd57c2e312cb6b7e4f02222e43a (diff)
downloaddecky-lsfg-vk-dfe4c033dd1922a63c8393ab467e9aa58fa757e4.tar.gz
decky-lsfg-vk-dfe4c033dd1922a63c8393ab467e9aa58fa757e4.zip
refactor: update configuration handling to use object-based API
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generate_ts_schema.py135
1 files changed, 135 insertions, 0 deletions
diff --git a/scripts/generate_ts_schema.py b/scripts/generate_ts_schema.py
new file mode 100644
index 0000000..dcdddf2
--- /dev/null
+++ b/scripts/generate_ts_schema.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python3
+"""
+Generate TypeScript schema from Python shared_config.py
+
+This script reads the canonical schema from shared_config.py and generates
+the corresponding TypeScript files, ensuring single source of truth.
+"""
+
+import sys
+from pathlib import Path
+
+# Add project root to path to import shared_config
+project_root = Path(__file__).parent.parent
+sys.path.insert(0, str(project_root))
+
+from shared_config import CONFIG_SCHEMA_DEF, ConfigFieldType
+
+
+def generate_typescript_schema():
+ """Generate generatedConfigSchema.ts from Python schema"""
+
+ # Generate enum
+ enum_lines = [
+ "// src/config/generatedConfigSchema.ts",
+ "// Configuration field type enum - matches Python",
+ "export enum ConfigFieldType {",
+ " BOOLEAN = \"boolean\",",
+ " INTEGER = \"integer\",",
+ " FLOAT = \"float\",",
+ " STRING = \"string\"",
+ "}",
+ "",
+ "// Configuration field definition",
+ "export interface ConfigField {",
+ " name: string;",
+ " fieldType: ConfigFieldType;",
+ " default: boolean | number | string;",
+ " description: string;",
+ "}",
+ "",
+ "// Configuration schema - auto-generated from Python",
+ "export const CONFIG_SCHEMA: Record<string, ConfigField> = {"
+ ]
+
+ # Generate schema entries
+ schema_entries = []
+ interface_fields = []
+ defaults_fields = []
+ field_types = []
+
+ for field_name, field_def in CONFIG_SCHEMA_DEF.items():
+ # Schema entry
+ default_value = field_def["default"]
+ if isinstance(default_value, str):
+ default_str = f'"{default_value}"'
+ elif isinstance(default_value, bool):
+ default_str = "true" if default_value else "false"
+ else:
+ default_str = str(default_value)
+
+ schema_entries.append(f' {field_name}: {{')
+ schema_entries.append(f' name: "{field_def["name"]}",')
+ schema_entries.append(f' fieldType: ConfigFieldType.{field_def["fieldType"].upper()},')
+ schema_entries.append(f' default: {default_str},')
+ schema_entries.append(f' description: "{field_def["description"]}"')
+ schema_entries.append(' },')
+
+ # Interface field
+ if field_def["fieldType"] == ConfigFieldType.BOOLEAN:
+ ts_type = "boolean"
+ elif field_def["fieldType"] == ConfigFieldType.INTEGER:
+ ts_type = "number"
+ elif field_def["fieldType"] == ConfigFieldType.FLOAT:
+ ts_type = "number"
+ elif field_def["fieldType"] == ConfigFieldType.STRING:
+ ts_type = "string"
+ else:
+ ts_type = "any"
+
+ interface_fields.append(f' {field_name}: {ts_type};')
+ defaults_fields.append(f' {field_name}: {default_str},')
+ field_types.append(f' {field_name}: ConfigFieldType.{field_def["fieldType"].upper()},')
+
+ # Complete the file
+ all_lines = enum_lines + schema_entries + [
+ "};",
+ "",
+ "// Type-safe configuration data structure",
+ "export interface ConfigurationData {",
+ ] + interface_fields + [
+ "}",
+ "",
+ "// Helper functions",
+ "export function getFieldNames(): string[] {",
+ " return Object.keys(CONFIG_SCHEMA);",
+ "}",
+ "",
+ "export function getDefaults(): ConfigurationData {",
+ " return {",
+ ] + defaults_fields + [
+ " };",
+ "}",
+ "",
+ "export function getFieldTypes(): Record<string, ConfigFieldType> {",
+ " return {",
+ ] + field_types + [
+ " };",
+ "}",
+ "",
+ ""
+ ]
+
+ return "\n".join(all_lines)
+
+
+def main():
+ """Main function to generate TypeScript schema"""
+ try:
+ # Generate the TypeScript content
+ ts_content = generate_typescript_schema()
+
+ # Write to the target file
+ target_file = project_root / "src" / "config" / "generatedConfigSchema.ts"
+ target_file.write_text(ts_content)
+
+ print(f"✅ Generated {target_file} from shared_config.py")
+ print(f" Fields: {len(CONFIG_SCHEMA_DEF)}")
+
+ except Exception as e:
+ print(f"❌ Error generating TypeScript schema: {e}")
+ sys.exit(1)
+
+
+if __name__ == "__main__":
+ main()