updatePubspec function

void updatePubspec()

Implementation

void updatePubspec() {
  print('Updating pubspec.yaml...');
  final pubspecFile = File('pubspec.yaml');

  if (!pubspecFile.existsSync()) {
    print('Error: pubspec.yaml not found!');
    return;
  }

  try {
    // Read the original content
    final content = pubspecFile.readAsStringSync();

    // Remove all comments and clean gaps
    final cleanedContent = _removeCommentsAndGaps(content);

    // Parse the cleaned YAML content
    final editor = YamlEditor(cleanedContent);

    // Define the assets configuration
    const flutterConfig = {
      'assets': [
        'assets/images/',
        'assets/icons/',
        'assets/audios/',
        'assets/fonts/',
        'assets/translations/',
      ]
    };

    // Add or update the `flutter` section
    editor.update(['flutter'], flutterConfig);

    // Write the updated content back to the file
    pubspecFile.writeAsStringSync(editor.toString());
    print('pubspec.yaml updated successfully!');
  } catch (e) {
    print('Error updating pubspec.yaml: $e');
  }
}