Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version command #150

Merged
merged 3 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'