-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Deps command to sidekick_core and CleanCommand to template (#85)
* Add repository.findAllPackages() * Add deps command to core * Remove deps command from template * Add CleanCommand This is a great example how to create a custom command that should be extensible * Ignore hidden folders when searching for packages Otherwise it catches synthetic_package in .dart-tools/ * Exit with exitCode 1 if deps fails * Ignore build directories
- Loading branch information
Showing
7 changed files
with
123 additions
and
59 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
sidekick/cli_template/bricks/package/__brick__/lib/src/commands/clean_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:sidekick_core/sidekick_core.dart'; | ||
|
||
class CleanCommand extends Command { | ||
@override | ||
final String description = 'Cleans the project'; | ||
|
||
@override | ||
final String name = 'clean'; | ||
|
||
@override | ||
Future<void> run() async { | ||
{{#hasMainProject}}flutter(['clean'], workingDirectory: mainProject?.root);{{/hasMainProject}} | ||
// TODO Please add your own project clean logic here | ||
|
||
print('✔️Cleaned project'); | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
sidekick/cli_template/bricks/package/__brick__/lib/src/commands/deps_command.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:sidekick_core/sidekick_core.dart'; | ||
|
||
/// Downloads dependencies of all Flutter/Dart packages in the repository | ||
class DepsCommand extends Command { | ||
@override | ||
final String description = 'Gets dependencies for all packages'; | ||
|
||
@override | ||
final String name = 'deps'; | ||
|
||
/// packages whose dependencies should not be loaded | ||
final List<DartPackage> exclude; | ||
|
||
DepsCommand({this.exclude = const []}) { | ||
argParser.addOption( | ||
'package', | ||
abbr: 'p', | ||
); | ||
} | ||
|
||
@override | ||
Future<void> run() async { | ||
final String? packageName = argResults?['package'] as String?; | ||
|
||
final List<DartPackage> allPackages = repository.findAllPackages(); | ||
|
||
if (packageName != null) { | ||
final package = | ||
allPackages.where((it) => it.name == packageName).firstOrNull; | ||
if (package == null) { | ||
throw "Package with name $packageName not found in repository " | ||
"${repository.root.path}"; | ||
} | ||
// only get deps for selected package | ||
_getDependencies(package); | ||
return; | ||
} | ||
|
||
final errorBuffer = StringBuffer(); | ||
for (final package in allPackages) { | ||
try { | ||
_getDependencies(package); | ||
} catch (e, stack) { | ||
print('Error while getting dependencies for ${package.name} ' | ||
'(${package.root.path})'); | ||
errorBuffer.writeln("${package.name}: $e\n$stack"); | ||
} | ||
} | ||
final errorText = errorBuffer.toString(); | ||
if (errorText.isNotEmpty) { | ||
printerr("\n\nErrors while getting dependencies:"); | ||
printerr(errorText); | ||
exitCode = 1; | ||
} | ||
} | ||
|
||
void _getDependencies(DartPackage package) { | ||
print(yellow('=== package ${package.name} ===')); | ||
final int exitCode; | ||
if (package.isFlutterPackage) { | ||
exitCode = flutter(['packages', 'get'], workingDirectory: package.root); | ||
} else { | ||
exitCode = dart(['pub', 'get'], workingDirectory: package.root); | ||
} | ||
if (exitCode != 0) { | ||
throw "Failed to get dependencies for package ${package.root.path}"; | ||
} | ||
print("\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters