- Initialize Flutter 3.38 project with all platforms - Add build-time version generation from pubspec.yaml - Print version to console on app startup - Create CHANGELOG.md following Keep a Changelog format - Update .gitignore for Flutter + generated files - Basic app scaffold with Material 3 theming 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
51 lines
1.4 KiB
Dart
51 lines
1.4 KiB
Dart
#!/usr/bin/env dart
|
|
/// Generates lib/version.g.dart from pubspec.yaml
|
|
///
|
|
/// Run before building: `dart run tool/generate_version.dart`
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:yaml/yaml.dart';
|
|
|
|
void main() {
|
|
final pubspecFile = File('pubspec.yaml');
|
|
if (!pubspecFile.existsSync()) {
|
|
stderr.writeln('Error: pubspec.yaml not found');
|
|
exit(1);
|
|
}
|
|
|
|
final pubspec = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
|
|
|
|
final name = pubspec['name'] as String;
|
|
final description = pubspec['description'] as String;
|
|
final versionString = pubspec['version'] as String;
|
|
|
|
// Parse version: "0.1.0+1" -> version="0.1.0", buildNumber=1
|
|
final versionParts = versionString.split('+');
|
|
final version = versionParts[0];
|
|
final buildNumber = versionParts.length > 1 ? int.parse(versionParts[1]) : 0;
|
|
|
|
final output = '''
|
|
// GENERATED FILE - DO NOT EDIT
|
|
// Generated by: dart run tool/generate_version.dart
|
|
|
|
/// Application version information from pubspec.yaml
|
|
class AppVersion {
|
|
AppVersion._();
|
|
|
|
static const String name = '$name';
|
|
static const String description = '$description';
|
|
static const String version = '$version';
|
|
static const int buildNumber = $buildNumber;
|
|
static const String fullVersion = '$version+$buildNumber';
|
|
}
|
|
''';
|
|
|
|
final outputFile = File('lib/version.g.dart');
|
|
outputFile.writeAsStringSync(output);
|
|
|
|
print('Generated lib/version.g.dart');
|
|
print(' name: $name');
|
|
print(' version: $version+$buildNumber');
|
|
}
|