recreatePubspec static method

Future<void> recreatePubspec()

  1. Recreate Pubspec

Implementation

static Future<void> recreatePubspec() async {
  try {
    final pubspecFile = File(_pubspecPath);

    if (pubspecFile.existsSync()) {
      pubspecFile.deleteSync();
      print('🗑️ Deleted old pubspec.yaml');
    } else {
      throw Exception('pubspec.yaml not found');
    }

    final result = await Process.run('flutter', [
      'create',
      '.',
      '-e',
    ], runInShell: true);

    if (result.exitCode == 0) {
      print('✅ New pubspec.yaml created successfully!');
    } else {
      print('❌ Failed to recreate pubspec.yaml\n${result.stderr}');
    }
  } catch (e) {
    throw Exception('❌ Error while recreating pubspec: $e');
  }
}