ConfigEditor class

Configuration file editing utilities for CLI commands.

Provides safe YAML editing for pubspec.yaml, code injection into Dart files, and config file creation.

Usage

// Add dependency
ConfigEditor.addDependencyToPubspec(
  pubspecPath: 'pubspec.yaml',
  name: 'http',
  version: '^1.0.0',
);

// Add import to Dart file
ConfigEditor.addImportToFile(
  filePath: 'lib/main.dart',
  importStatement: "import 'package:http/http.dart';",
);

Constructors

ConfigEditor()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

addDependencyToPubspec({required String pubspecPath, required String name, required String version}) → void
Add or update a dependency in pubspec.yaml.
addDevDependencyToPubspec({required String pubspecPath, required String name, required String version}) → void
Add a dev dependency to pubspec.yaml under the dev_dependencies map.
addImportToFile({required String filePath, required String importStatement}) → void
Add an import statement to a Dart file if not already present.
addPathDependencyToPubspec({required String pubspecPath, required String name, required String path}) → void
Add or update a path-based dependency in pubspec.yaml.
appendPubspecListEntry({required String pubspecPath, required List<String> keyPath, required String value}) → void
Append value to the YAML list living at keyPath inside pubspecPath, creating the list if it does not yet exist.
createConfigFile({required String path, required String content}) → void
Create a config file with the given content.
insertCodeAfterPattern({required String filePath, required Pattern pattern, required String code}) → void
Insert code after the first occurrence of a pattern in a file.
insertCodeBeforePattern({required String filePath, required Pattern pattern, required String code}) → void
Insert code before the first occurrence of a pattern in a file.
removeDependencyFromPubspec({required String pubspecPath, required String name}) → void
Remove a dependency from pubspec.yaml.
updatePubspecValue({required String pubspecPath, required List<String> keyPath, required dynamic value}) → void
Update a nested value in pubspec.yaml.