A Dart package that provides a simple way to manuplate the pubspec.yaml file at runtime.
- Add dependencies to the
pubspec.yaml
file. - Add dev dependencies to the
pubspec.yaml
file. - Add key value pairs to the
pubspec.yaml
file. - Get the value of a key from the
pubspec.yaml
file. - Remove key value pairs from the
pubspec.yaml
file. - Save changes to the
pubspec.yaml
file. - Run
pub get
command. - Parse the
pubspec.yaml
file using Parser
A simple usage example:
import 'package:pubspec_runtime/pubspec_runtime.dart';
void main() async {
final pubspecEditor = PubspecEditor();
print("Dependencies:");
print(pubspecEditor.dependencies.list);
print("Dev Dependencies:");
print(pubspecEditor.devDependencies.list);
print("Adding a dependency...");
pubspecEditor.dependencies
.add(Dependency(name: 'http', version: '^0.13.3', isDev: false));
print("Adding a dev dependency...");
pubspecEditor.devDependencies
.add(Dependency(name: 'http', version: '^0.13.3', isDev: true));
print("Add a key value pair to the `pubspec.yaml` file.");
pubspecEditor.add("author", "John Doe");
print("Get the value of a key from the `pubspec.yaml` file.");
print(pubspecEditor.get("author"));
print("Remove a key value pair from the `pubspec.yaml` file.");
pubspecEditor.remove("author");
print("Updated Dependencies:");
print(pubspecEditor.dependencies.list);
print("Saving changes...");
pubspecEditor.save();
print("Changes saved successfully!");
print("Running pub get...");
runPubGet()
.then((value) => print(
"Pub get executed successfully with exit code: ${value.exitCode}"))
.catchError(
(error) => print("Error occurred while executing pub get: $error"));
}
Simple usage of the parser:
import "package:pubspec_runtime/pubspec_runtime.dart";
void main() {
final Parser parser = Parser();
final String filePath =
"/media/raman/Projects/dart_libs/runtime_yaml/pubspec.yaml";
final Map<String, dynamic> content = parser.parseFile(filePath);
print(content);
}
PubspecEditor
class is the main class that provides the functionality to manipulate thepubspec.yaml
file.dependencies
property is an instance of theDependencyManager
class that provides the functionality to manipulate the dependencies in thepubspec.yaml
file.devDependencies
property is an instance of theDependencyManager
class that provides the functionality to manipulate the dev dependencies in thepubspec.yaml
file.parser
property is an instance of theParser
class that provides the functionality to parse thepubspec.yaml
file.add
function is used to add a key value pair to thepubspec.yaml
file.get
function is used to get the value of a key from thepubspec.yaml
file.remove
function is used to remove a key value pair from thepubspec.yaml
file.save
function is used to save the changes to thepubspec.yaml
file.runPubGet
function is used to run thepub get
command.exists
function is used to check if a key exists in thepubspec.yaml
file.
Dependency
class is a simple class that represents a dependency in thepubspec.yaml
file.name
property is the name of the dependency.version
property is the version of the dependency.isDev
property is a boolean value that indicates whether the dependency is a dev dependency or not.
DependencyManager
class is a class that provides the functionality to manage dependencies as objects.add
function is used to add a dependency to thepubspec.yaml
file.remove
function is used to remove a dependency from thepubspec.yaml
file.list
property is used to get the list of dependencies in thepubspec.yaml
file.
Parser
class is a class that provides the functionality to parse thepubspec.yaml
file.parseFile
function is used to parse thepubspec.yaml
file and return the content as a map.parse
function is used to parse the content of thepubspec.yaml
file and return it as a map.mapToYamlString
function is used to convert a map to a YAML string.
MIT License
- Feel free to contribute to this project by creating a pull request or raising an issue.
- If you find any issues with the package, please raise an issue on the GitHub repository.