Skip to content

Commit

Permalink
Use dart run messages again
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Oct 25, 2024
1 parent ddf0f9d commit b18c968
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:
- name: Regenerate and run example
working-directory: pkgs/messages/example
run: |
dart run messages_builder
dart run messages
git diff --exit-code
dart run
5 changes: 2 additions & 3 deletions pkgs/messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ The `builder` to generate the named methods and data files from the input `arb`
The logic for serializing `arb` message files into data files.

## Example
Add `package:messages` and `package:messages_builder` to your dependencies:
Add `package:messages` to your dependencies:
```bash
dart pub add messages
dart pub add dev:messages_builder
```

Given translation message files in two languages:
Expand Down Expand Up @@ -68,7 +67,7 @@ This translated file was created by a translator given the reference `en.arb`.
```
you can then run

`dart run messages_builder`
`dart run messages`

This will generate both code to call your messages, as well as data files which will be shipped with your application. You can then use these generated files by importing the generated files:

Expand Down
31 changes: 31 additions & 0 deletions pkgs/messages/bin/messages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024, 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';

Future<void> main(List<String> args) async {
final runBuilder = await Process.run('dart', ['run', 'messages_builder']);
stdout.write(runBuilder.stdout as String);

final runBuilderStdErr = runBuilder.stderr as String;
final messagesBuilderNotInDeps =
runBuilderStdErr.contains('Could not find package `messages_builder`');
if (messagesBuilderNotInDeps) {
print('Adding `package:messages_builder` to dev dependencies...');
final addBuilder = await runDart(['pub', 'add', 'dev:messages_builder']);
if (addBuilder.exitCode == 0) {
print('Re-running message generation');
await runDart(['run', 'messages_builder']);
}
} else {
stderr.write(runBuilderStdErr);
}
}

Future<ProcessResult> runDart(List<String> arguments) async {
final processResult = await Process.run('dart', arguments);
stdout.write(processResult.stdout as String);
stderr.write(processResult.stderr as String);
return processResult;
}
7 changes: 0 additions & 7 deletions pkgs/messages/example/pubspec_overrides.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit b18c968

Please sign in to comment.