-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[puppy] Introduce a package for misc Dart CLI tools
First tool: for_all_package_dirs to recursively run a command in every directory that contains pubspec.yaml
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
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,41 @@ | ||
name: package:puppy | ||
|
||
permissions: read-all | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/puppy.yml' | ||
- 'pkgs/puppy/**' | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/puppy.yml' | ||
- 'pkgs/puppy/**' | ||
schedule: | ||
- cron: '0 0 * * 0' # weekly | ||
|
||
defaults: | ||
run: | ||
working-directory: pkgs/puppy | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
sdk: [3.6, dev] | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 | ||
with: | ||
sdk: ${{ matrix.sdk }} | ||
|
||
- run: dart pub get | ||
- run: dart analyze --fatal-infos | ||
- run: dart format --output=none --set-exit-if-changed . | ||
if: ${{ matrix.sdk == 'dev' }} | ||
# TODO: enable when there are tests! | ||
#- run: dart test |
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,11 @@ | ||
Activate locally using: | ||
|
||
```console | ||
cd <puppy pkg path> | ||
dart pub global activate --source=path . | ||
``` | ||
|
||
### Tools | ||
|
||
- `for_all_package_dirs`: runs a command in every directory containing | ||
`pubspec.yaml`. |
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 @@ | ||
include: package:dart_flutter_team_lints/analysis_options.yaml |
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,49 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:io/ansi.dart'; | ||
import 'package:io/io.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
if (args.isEmpty) { | ||
print('Need something to execute!'); | ||
exitCode = ExitCode.usage.code; | ||
return; | ||
} | ||
|
||
final exe = args.first; | ||
final extraArgs = args.skip(1).toList(); | ||
|
||
final exits = <String, int>{}; | ||
|
||
Future<void> inspectDirectory(Directory dir) async { | ||
final pubspecs = dir | ||
.listSync() | ||
.whereType<File>() | ||
.where((element) => element.uri.pathSegments.last == 'pubspec.yaml') | ||
.toList(); | ||
|
||
if (pubspecs.isNotEmpty) { | ||
print(green.wrap(dir.path)); | ||
final proc = await Process.start( | ||
exe, | ||
extraArgs, | ||
mode: ProcessStartMode.inheritStdio, | ||
workingDirectory: dir.path, | ||
); | ||
|
||
// TODO(kevmoo): display a summary of results on completion | ||
exits[dir.path] = await proc.exitCode; | ||
} | ||
|
||
for (var subDir in dir.listSync().whereType<Directory>().where((element) => | ||
!element.uri.pathSegments.any((element) => element.startsWith('.')))) { | ||
await inspectDirectory(subDir); | ||
} | ||
} | ||
|
||
await inspectDirectory(Directory.current); | ||
} |
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,14 @@ | ||
name: puppy | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ^3.6.0 | ||
|
||
dependencies: | ||
io: ^1.0.5 | ||
|
||
dev_dependencies: | ||
dart_flutter_team_lints: ^3.0.0 | ||
|
||
executables: | ||
for_all_package_dirs: |