diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d7192c..2dce690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.3.0 + * add ability to find dart files in a directory + ## 0.2.1 * bump deps diff --git a/README.md b/README.md index d7defff..3cb747f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ results need to be incorporated. To extract messages, run the `extract_to_arb.dart` program. pub run intl_generator:extract_to_arb --output-dir=target/directory - my_program.dart more_of_my_program.dart + my_program.dart more_of_my_program.dart my/target/programs/directory This will produce a file `intl_messages.arb` with the messages from all of these programs. This is an [ARB][ARB] format file which can be used for input to @@ -32,7 +32,7 @@ locale. ``` pub run intl_generator:generate_from_arb --generated-file-prefix= - + ``` This will generate Dart libraries, one per locale, which contain the diff --git a/bin/extract_to_arb.dart b/bin/extract_to_arb.dart index c7a81cf..7bba8ad 100644 --- a/bin/extract_to_arb.dart +++ b/bin/extract_to_arb.dart @@ -17,7 +17,7 @@ import 'package:intl_generator/src/arb_generation.dart'; import 'package:intl_generator/src/directory_utils.dart'; import 'package:path/path.dart' as path; -main(List args) { +Future main(List args) async { var targetDir; var outputFilename; String? sourcesListFile; @@ -92,7 +92,8 @@ main(List args) { allMessages["@@last_modified"] = new DateTime.now().toIso8601String(); } - var dartFiles = args.where((x) => x.endsWith(".dart")).toList(); + final List dartFiles = await findDartFilesInDirectories(args); + dartFiles.addAll(args.where((String file) => file.endsWith(".dart"))); dartFiles.addAll(linesFromFile(sourcesListFile)); for (var arg in dartFiles) { var messages = extraction.parseFile(new File(arg), transformer); diff --git a/bin/generate_from_arb.dart b/bin/generate_from_arb.dart index 8ca15d8..5dc1ce7 100644 --- a/bin/generate_from_arb.dart +++ b/bin/generate_from_arb.dart @@ -35,7 +35,7 @@ late Map> messages; const jsonDecoder = const JsonCodec(); -main(List args) { +Future main(List args) async { var targetDir; var parser = new ArgParser(); var extraction = new MessageExtraction(); @@ -86,7 +86,8 @@ main(List args) { "don't need to be specified for messages."); parser.parse(args); - var dartFiles = args.where((x) => x.endsWith("dart")).toList(); + final List dartFiles = await findDartFilesInDirectories(args); + dartFiles.addAll(args.where((String file) => file.endsWith(".dart"))); var jsonFiles = args.where((x) => x.endsWith(".arb")).toList(); dartFiles.addAll(linesFromFile(sourcesListFile)); jsonFiles.addAll(linesFromFile(translationsListFile)); diff --git a/lib/src/directory_utils.dart b/lib/src/directory_utils.dart index a0bd86e..72467f6 100644 --- a/lib/src/directory_utils.dart +++ b/lib/src/directory_utils.dart @@ -30,3 +30,32 @@ String _relativeToBase(String base, String filename) { return filename; } } + +List _findDirectories(List paths) { + final List directories = []; + for (final String path in paths) { + if (FileSystemEntity.typeSync(path) == FileSystemEntityType.directory) { + directories.add(Directory(path)); + } + } + return directories; +} + +Future> findDartFilesInDirectories( + List paths, +) async { + final List directories = _findDirectories(paths); + final List dartFiles = []; + + for (final Directory directory in directories) { + final List entities = + await directory.list(recursive: true).toList(); + final Iterable files = entities.where(_isDartFile); + dartFiles.addAll(files.map((FileSystemEntity file) => file.path)); + } + return dartFiles; +} + +bool _isDartFile(FileSystemEntity entity) { + return entity is File && entity.path.endsWith(".dart"); +} diff --git a/pubspec.yaml b/pubspec.yaml index bb61e1e..9d42a79 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: intl_generator -version: 0.2.1 +version: 0.3.0 description: >- Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and