execute method

Future<AnalysisResult> execute(
  1. String projectPath
)

Implementation

Future<AnalysisResult> execute(String projectPath) async {
  try {
    _state.startAnalysis();

    // Find asset directories
    _state.setTask('Reading project configuration...');
    final assetPaths = await _fileService.findAssetPaths(projectPath);
    if (assetPaths.isEmpty) {
      throw AssetOptException('No asset directories found in pubspec.yaml');
    }

    // Scan for assets
    _state.setTask('Scanning asset directories...');
    final scanResult = await _fileService.scanAssets(assetPaths);
    final totalFiles = scanResult.assets.length;

    // Get detailed image info for each asset
    _state.setTask('Analyzing assets...');
    final assetDetails = <AssetDetail>[];
    var processed = 0;

    for (final asset in scanResult.assets) {
      final file = File(asset.path);
      final imageInfo = await _imageService.getImageInfo(file);

      assetDetails.add(AssetDetail(
        info: asset,
        imageInfo: imageInfo,
        issues: _analyzeAssetIssues(asset, imageInfo),
      ));

      processed++;
      _state.updateProgress(
        'Analyzing ${path_util.basename(asset.path)}',
        processed,
        totalFiles,
      );
    }

    _state.setTask('Finalizing analysis...');
    final result = AnalysisResult(
      assets: assetDetails,
      scanErrors: scanResult.errors,
      analyzedAt: DateTime.now(),
      projectRoot: projectPath,
    );

    _state.completeAnalysis(result);
    return result;
  } catch (e) {
    _state.failAnalysis(e.toString());
    rethrow;
  }
}