Skip to content

Commit

Permalink
feat: add version command (#150)
Browse files Browse the repository at this point in the history
* feat: add version command

* refactor: replace  to
  • Loading branch information
wasabeef authored Oct 28, 2021
1 parent e2cd36c commit 48b4e15
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
16 changes: 13 additions & 3 deletions packages/command/bin/flutter_gen_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> args) {
final parser = ArgParser();
parser.addOption(
'config',
abbr: 'c',
defaultsTo: 'pubspec.yaml',
help: 'Set the path of pubspec.yaml.',
defaultsTo: 'pubspec.yaml',
);

parser.addFlag(
Expand All @@ -20,12 +21,21 @@ void main(List<String> 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) {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/lib/flutter_generator.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,6 +25,7 @@ class FlutterGenerator {
final String fontsName;

Future<void> build() async {
stdout.writeln(flutterGenVersion);
Config config;
try {
config = await loadPubspecConfig(pubspecFile);
Expand Down Expand Up @@ -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) {
Expand All @@ -66,17 +66,17 @@ 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) {
final generated = generateFonts(formatter, flutter.fonts);
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.');
}
}
3 changes: 1 addition & 2 deletions packages/core/lib/settings/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class Config {
}

Future<Config> loadPubspecConfig(File pubspecFile) async {
// ignore: avoid_print
print('FlutterGen Loading ... '
stdout.writeln('FlutterGen Loading ... '
'${normalize(join(
basename(pubspecFile.parent.path),
basename(pubspecFile.path),
Expand Down
3 changes: 3 additions & 0 deletions packages/core/lib/utils/version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flutter_gen_core/version.gen.dart';

String flutterGenVersion = 'FlutterGen v$packageVersion';
2 changes: 2 additions & 0 deletions packages/core/lib/version.gen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// DO NOT MODIFY BY HAND, Generated by version_gen
String packageVersion = '4.0.1';
7 changes: 7 additions & 0 deletions packages/core/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions packages/core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'

0 comments on commit 48b4e15

Please sign in to comment.