updateUiElements function

void updateUiElements(
  1. String name,
  2. String tsPath
)

Implementation

void updateUiElements(String name, String tsPath) {
  final schemaName = '${toCamelCase(name)}Component';
  final file = File('$tsPath/components/uiElements.ts');
  if (!file.existsSync()) {
    print(
        "⚠️ Could not find uiElements.ts at ${file.path}. Please add {type: '$schemaName'} manually.");
    return;
  }

  final content = file.readAsStringSync();
  if (content.contains("{type: '$schemaName'}")) {
    return;
  }

  // Insert before the last closing bracket of the `of` array
  final newContent =
      content.replaceFirst('  ],', "    {type: '$schemaName'},\n  ],");
  file.writeAsStringSync(newContent);
  print('✅ Updated uiElements.ts');
}