pubspec_extract
2.2.1, released 4 weeks ago by nfet.net
Extracts Dart pubspec.yaml file and generates pubspec.dart at build time
What it does
Extracts metadata and dependencies from pubspec.yaml and outputs a Dart file containing a class with these values. It can be run as a standalone command-line tool or integrated using build_runner.
AI-written summary of version 2.2.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to access app version, name, or description inside your Dart code
- You want to automate reading pubspec configuration during compilation
Skip it when
- You need dynamic runtime reading of external YAML assets without code generation
Strengths
- Supports both command-line usage and build_runner integration
- Highly configurable extraction of specific top-level keys
Weaknesses
- Requires regeneration when pubspec.yaml changes if not using build_runner
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 7
Add pubspec_extract as a dev dependency and run via dart run or build_runner.
import 'pubspec.dart';
void main() {
print(Pubspec.name);
print(Pubspec.description);
print(Pubspec.version);
}Alternatives
Packages that do the same job and could replace pubspec_extract.
- json_serializable
Automatically generate code for converting Dart classes to and from JSON.
94Compare - checked_yaml
Provides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.
79Compare - mason
Dart template generator for quick file creation
89Compare - envied
Explicitly reads environment variables into a dart file from a .env file.
86Compare
Works with
Packages commonly used together with pubspec_extract: ones it builds on, ones built on it, and its own family.
- yamlpubspec_extract depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverpubspec_extract depends on itVersions and version constraints implementing pub's versioning policy.
- dart_stylepubspec_extract depends on itProvides an API and CLI to format Dart source code automatically.
- argspubspec_extract depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- loggingpubspec_extract depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- buildpubspec_extract depends on itPackage for authoring build_runner compatible code generators.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.