run method

Future<void> run({
  1. required String dirPath,
  2. required FarConfig farConfig,
})

Implementation

Future<void> run({required String dirPath, required FarConfig farConfig}) async {
  currentDirPath = dirPath;
  if (farConfig.enable == false) {
    logSkipping("$platform settings enable is false");
    return;
  }

  final name = farConfig.appName ?? '';
  if (name.isEmpty) {
    log("Flutter app name is empty.");
    return;
  }

  // 读取 `pubspec.yaml` 获取原始名称
  final pubspecFile = File('$currentDirPath/$keyPubspecFileName');
  final originalName = await _getOriginalName(pubspecFile);
  if (originalName.isEmpty) {
    log("Flutter original name in pubspec.yaml is empty.");
    return;
  }

  // 匹配规则:处理 import/export 的单双引号
  final patterns = [
    "import 'package:$originalName/",
    "import \"package:$originalName/",
    "export 'package:$originalName/",
    "export \"package:$originalName/",
  ];

  // 替换 Dart 文件中的包名
  await _update_packageNameInDirectories(['$currentDirPath/lib', '$currentDirPath/test'], patterns, originalName, name);

  // 更新 `pubspec.yaml` 中的名称
  await _update_pubspecName(pubspecFile, name);

  log("Flutter -> name update completed. ✅");
}