From 48b4e15a3fee8c8c679c6986c56f2fc51bdb062c Mon Sep 17 00:00:00 2001 From: Daichi Furiya Date: Fri, 29 Oct 2021 01:47:37 +0900 Subject: [PATCH] feat: add version command (#150) * feat: add version command * refactor: replace to --- packages/command/bin/flutter_gen_command.dart | 16 +++++++++++++--- packages/core/lib/flutter_generator.dart | 12 ++++++------ packages/core/lib/settings/config.dart | 3 +-- packages/core/lib/utils/version.dart | 3 +++ packages/core/lib/version.gen.dart | 2 ++ packages/core/pubspec.lock | 7 +++++++ packages/core/pubspec.yaml | 4 ++++ 7 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 packages/core/lib/utils/version.dart create mode 100644 packages/core/lib/version.gen.dart diff --git a/packages/command/bin/flutter_gen_command.dart b/packages/command/bin/flutter_gen_command.dart index 9389f17b..acf12b64 100644 --- a/packages/command/bin/flutter_gen_command.dart +++ b/packages/command/bin/flutter_gen_command.dart @@ -3,14 +3,15 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:flutter_gen_core/flutter_generator.dart'; import 'package:flutter_gen_core/utils/cast.dart'; +import 'package:flutter_gen_core/utils/version.dart'; void main(List args) { final parser = ArgParser(); parser.addOption( 'config', abbr: 'c', - defaultsTo: 'pubspec.yaml', help: 'Set the path of pubspec.yaml.', + defaultsTo: 'pubspec.yaml', ); parser.addFlag( @@ -20,12 +21,21 @@ void main(List args) { defaultsTo: false, ); + parser.addFlag( + 'version', + abbr: 'v', + help: 'FlutterGen version', + defaultsTo: false, + ); + ArgResults results; try { results = parser.parse(args); if (results.wasParsed('help')) { - // ignore: avoid_print - print(parser.usage); + stdout.writeln(parser.usage); + return; + } else if (results.wasParsed('version')) { + stdout.writeln(flutterGenVersion); return; } } on FormatException catch (e) { diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index 3106644a..3fa3d760 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -1,8 +1,7 @@ -// ignore_for_file: avoid_print - import 'dart:io'; import 'package:dart_style/dart_style.dart'; +import 'package:flutter_gen_core/utils/version.dart'; import 'package:path/path.dart'; import 'generators/assets_generator.dart'; @@ -26,6 +25,7 @@ class FlutterGenerator { final String fontsName; Future build() async { + stdout.writeln(flutterGenVersion); Config config; try { config = await loadPubspecConfig(pubspecFile); @@ -55,7 +55,7 @@ class FlutterGenerator { final colors = File(normalize(join(pubspecFile.parent.path, output, colorsName))); writeAsString(generated, file: colors); - print('Generated: ${colors.absolute.path}'); + stdout.writeln('Generated: ${colors.absolute.path}'); } if (flutterGen.assets.enabled && flutter.assets.isNotEmpty) { @@ -66,7 +66,7 @@ class FlutterGenerator { final assets = File(normalize(join(pubspecFile.parent.path, output, assetsName))); writeAsString(generated, file: assets); - print('Generated: ${assets.absolute.path}'); + stdout.writeln('Generated: ${assets.absolute.path}'); } if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) { @@ -74,9 +74,9 @@ class FlutterGenerator { final fonts = File(normalize(join(pubspecFile.parent.path, output, fontsName))); writeAsString(generated, file: fonts); - print('Generated: ${fonts.absolute.path}'); + stdout.writeln('Generated: ${fonts.absolute.path}'); } - print('FlutterGen finished.'); + stdout.writeln('FlutterGen finished.'); } } diff --git a/packages/core/lib/settings/config.dart b/packages/core/lib/settings/config.dart index 6bc3421a..93af8b42 100644 --- a/packages/core/lib/settings/config.dart +++ b/packages/core/lib/settings/config.dart @@ -13,8 +13,7 @@ class Config { } Future loadPubspecConfig(File pubspecFile) async { - // ignore: avoid_print - print('FlutterGen Loading ... ' + stdout.writeln('FlutterGen Loading ... ' '${normalize(join( basename(pubspecFile.parent.path), basename(pubspecFile.path), diff --git a/packages/core/lib/utils/version.dart b/packages/core/lib/utils/version.dart new file mode 100644 index 00000000..f6223aa8 --- /dev/null +++ b/packages/core/lib/utils/version.dart @@ -0,0 +1,3 @@ +import 'package:flutter_gen_core/version.gen.dart'; + +String flutterGenVersion = 'FlutterGen v$packageVersion'; diff --git a/packages/core/lib/version.gen.dart b/packages/core/lib/version.gen.dart new file mode 100644 index 00000000..f9891781 --- /dev/null +++ b/packages/core/lib/version.gen.dart @@ -0,0 +1,2 @@ +/// DO NOT MODIFY BY HAND, Generated by version_gen +String packageVersion = '4.0.1'; diff --git a/packages/core/pubspec.lock b/packages/core/pubspec.lock index be7d55d8..7830d694 100644 --- a/packages/core/pubspec.lock +++ b/packages/core/pubspec.lock @@ -491,6 +491,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + version_gen: + dependency: "direct dev" + description: + name: version_gen + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" vm_service: dependency: transitive description: diff --git a/packages/core/pubspec.yaml b/packages/core/pubspec.yaml index a9bdcabb..df8f1a24 100644 --- a/packages/core/pubspec.yaml +++ b/packages/core/pubspec.yaml @@ -10,6 +10,9 @@ issue_tracker: https://github.com/FlutterGen/flutter_gen/issues environment: sdk: '>=2.12.0 <3.0.0' +version_gen: + path: lib/ + dependencies: path: '>=1.8.0 <2.0.0' yaml: '>=3.0.0 <4.0.0' @@ -31,3 +34,4 @@ dev_dependencies: flutter_lints: '>=1.0.4 <2.0.0' build_runner: '>=2.0.0 <3.0.0' json_serializable: '>=5.0.0 <6.0.0' + version_gen: '>=1.0.1 <2.0.0'