calculateThemeImportPath function

String calculateThemeImportPath(
  1. String destinationPath,
  2. String themePath
)

Implementation

String calculateThemeImportPath(String destinationPath, String themePath) {
  final destDir = path.dirname(destinationPath);
  final themeDir = path.dirname(themePath);
  final relativePath = path.relative(themeDir, from: destDir);
  final normalizedPath = path.normalize(relativePath).replaceAll('\\', '/');

  if (normalizedPath == '.' || normalizedPath.isEmpty) {
    return './theme.dart';
  }

  if (normalizedPath.startsWith('..')) {
    return '$normalizedPath/theme.dart';
  }

  return './$normalizedPath/theme.dart';
}