Extracts Dart pubspec.yaml file and generate pubspec.dart at build time.
Add the pubspec_extract
dev dependency
dart pub add --dev pubspec_extract
then run:
dart run pubspec_extract
run:
dart pub global activate pubspec_extract
the executable will be compiled and available at $HOME/.pub-cache/bin
or %APPDATA%\Pub\Cache\bin
. You can run it using:
dart pub global run pubspec_extract
Add the build_runner
dev dependency
dart pub add --dev build_runner
Build the pubspec.dart
file
dart run build_runner build
Builder options are configured in your pubspec.yaml:
pubspec_extract:
class_name: Pubspec
source: pubspec.yaml
destination: lib/pubspec.dart
format: true
map_list: false
Then in your application, you can import pubspec.dart
:
import 'pubspec.dart'; // May not exist but it's okay!
void main() {
print(Pubspec.name);
print(Pubspec.description);
print(Pubspec.version);
}