diff --git a/bin/commands.dart b/bin/commands.dart index 99fb544..f6042d8 100644 --- a/bin/commands.dart +++ b/bin/commands.dart @@ -13,6 +13,7 @@ import 'projects.dart'; abstract class Commands { static final clean = ProjectCommand(['clean'], parallel: true); static final link = GlobalCommand( + ['link'], (command, projects) => linkDependencies(command: command, projects: projects), ); @@ -54,7 +55,7 @@ abstract class Commands { }; /// Check if we should continue after this line is received - static bool shouldKill(Project project, ProjectCommand command, String line) { + static bool shouldKill(Project project, Command command, String line) { if (project.engine == Engine.fvm) { final flutterVersionNotInstalledMatch = RegExp(r'Flutter SDK: SDK Version : (.+?) is not installed\.') diff --git a/bin/link.dart b/bin/link.dart index 0cf915d..381bd40 100644 --- a/bin/link.dart +++ b/bin/link.dart @@ -7,7 +7,6 @@ import 'package:puby/project.dart'; import 'package:puby/pub.dart'; import 'package:puby/time.dart'; -import 'commands.dart'; import 'projects.dart'; final _pubCache = SystemCache(); @@ -23,11 +22,11 @@ Future linkDependencies({ for (final project in projects) { unawaited( resolutionQueue.add(() async { - final resolved = project.resolveWithCommand(Commands.pubGetOffline); + final resolved = project.resolveWithCommand(command); if (resolved.exclude) return; final flutterVersionOverride = - await resolved.getFlutterVersionOverride(Commands.pubGetOffline); + await resolved.getFlutterVersionOverride(command); final entry = Entrypoint(resolved.path, _pubCache); try { diff --git a/bin/projects.dart b/bin/projects.dart index e42a746..659c88f 100644 --- a/bin/projects.dart +++ b/bin/projects.dart @@ -68,7 +68,7 @@ List findProjects() { } extension ProjectExtension on Project { - Engine _resolveEngine(ProjectCommand command) { + Engine _resolveEngine(Command command) { final isCleanCommand = command.args[0] == 'clean'; final isTestCoverageCommand = command.args.length >= 2 && command.args[0] == 'test' && @@ -96,13 +96,12 @@ extension ProjectExtension on Project { return newEngine; } - bool _defaultExclude(ProjectCommand command) { + bool _defaultExclude(Command command) { final isPubGetInFlutterExample = engine.isFlutter && example && command.args.length >= 2 && command.args[0] == 'pub' && command.args[1] == 'get'; - final isOffline = command.args.contains('--offline'); final bool skip; final String? message; @@ -113,9 +112,8 @@ extension ProjectExtension on Project { } else if (path.startsWith('build/') || path.contains('/build/')) { message = 'Skipping project in build folder: $path'; skip = true; - } else if (isPubGetInFlutterExample && !isOffline) { + } else if (isPubGetInFlutterExample) { // Skip flutter pub get in example projects since flutter does it anyways - // Do not skip if this is an offline pub command message = 'Skipping flutter example project: $path'; skip = true; } else { @@ -129,7 +127,7 @@ extension ProjectExtension on Project { return skip; } - bool _explicitExclude(ProjectCommand command) { + bool _explicitExclude(Command command) { final argString = command.args.join(' '); final skip = config.excludes.any(argString.startsWith); @@ -140,13 +138,13 @@ extension ProjectExtension on Project { return skip; } - Project resolveWithCommand(ProjectCommand command) { + Project resolveWithCommand(Command command) { final resolvedEngine = _resolveEngine(command); final exclude = _defaultExclude(command) || _explicitExclude(command); return copyWith(engine: resolvedEngine, exclude: exclude); } - Future getFlutterVersionOverride(ProjectCommand command) async { + Future getFlutterVersionOverride(Command command) async { if (engine != Engine.fvm || command.noFvm) return null; try { diff --git a/lib/command.dart b/lib/command.dart index 7eb44b2..1a05d8d 100644 --- a/lib/command.dart +++ b/lib/command.dart @@ -12,8 +12,11 @@ abstract class Command { /// If fvm support should be disabled bool get noFvm => _noFvm; + /// If output from this command should be displayed + final bool silent; + /// Constructor - Command(List args) { + Command(List args, {required this.silent}) { addArgs(args); } @@ -35,17 +38,12 @@ class ProjectCommand extends Command { /// Whether to run the command in all projects in parallel final bool parallel; - /// Whether to run the command silently - /// - /// Right now this is the same as [parallel] - bool get silent => parallel; - /// Constructor ProjectCommand( super.args, { this.raw = false, this.parallel = false, - }); + }) : super(silent: parallel); } /// A command to run in the working directory @@ -55,7 +53,7 @@ class GlobalCommand extends Command { _run; /// Constructor - GlobalCommand(this._run) : super([]); + GlobalCommand(super.args, this._run) : super(silent: false); /// Run the command Future run({required List projects}) => _run(this, projects); diff --git a/test/link_test.dart b/test/link_test.dart index a527c54..6808a49 100644 --- a/test/link_test.dart +++ b/test/link_test.dart @@ -23,6 +23,17 @@ void main() { // flutter expectLine(stdout, ['flutter_puby_test', 'Resolved dependencies for']); expectLine(stdout, ['flutter_puby_test', 'flutter pub get --offline']); + // The link should run in the example app + expectLine( + stdout, + ['flutter_puby_test/example', 'Resolved dependencies for'], + ); + // The pub get should NOT run in the example app + expectLine( + stdout, + ['flutter_puby_test/example', 'flutter pub get --offline'], + matches: false, + ); // fvm expectLine(stdout, ['fvm_puby_test', 'Resolved dependencies for']); diff --git a/test/test_utils.dart b/test/test_utils.dart index 0b64eb9..45f78e7 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -15,13 +15,13 @@ Future testCommand( ); } -void expectLine(dynamic stdout, List matchers) { +void expectLine(dynamic stdout, List matchers, {bool matches = true}) { final lines = (stdout as String).split('\n'); expect( lines.any( (line) => matchers.fold(true, (prev, next) => prev && line.contains(next)), ), - isTrue, + matches, ); }