Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve main entry path relative to project directory #123

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/globe_cli/lib/src/utils/logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ sealed class BuildLogEvent {
return BuildLogs([], done: true);
case ErrorResponse(error: final error):
return BuildLogsError(error: '[${error.code}]: ${error.message}');
default:
throw Exception('Unknown response type');
}
}
BuildLogEventType get type;
Expand Down
22 changes: 12 additions & 10 deletions packages/globe_cli/lib/src/utils/prompts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,26 @@ Future<List<Project>> selectProjects(
return selections.map((e) => projectsBySlug[e]!).toList();
}

/// Asynchronously finds the main entry point of a Dart project.
/// Asynchronously finds the main entry points of a Dart project.
/// Returns a list of entry points relative to [rootDir].
Future<List<String>> findMainEntryPoint(Directory rootDir) async {
final dartFiles = rootDir.list(recursive: true).where((entity) {
if (entity is! File) return false;
final entryPoints = <String>[];

await for (final entity in rootDir.list(recursive: true)) {
if (entity is! File) continue;

final relativePath = p.relative(entity.path, from: rootDir.path);
final segments = p.split(relativePath);

return p.extension(entity.path) == '.dart' &&
!<String>['.dart_tool', '.fvm', 'test'].any(segments.contains) &&
!p.basename(entity.path).startsWith('test_');
});
final entryPoints = <String>[];
if (p.extension(entity.path) != '.dart' ||
['.dart_tool', '.fvm', 'test'].any(segments.contains) ||
p.basename(entity.path).startsWith('test_')) {
continue;
}

await for (final (entity as File) in dartFiles) {
final contents = await entity.readAsString();
if (RegExp(r'\bmain\s*\([^)]*\)').hasMatch(contents)) {
entryPoints.add(p.relative(entity.path));
entryPoints.add(relativePath);
}
}

Expand Down
Loading