updatePubspec static method
Implementation
static Future<void> updatePubspec(
String projectDir,
String templateName,
String projectName,
bool verbose,
) async {
final pubspecFile = File(path.join(projectDir, Constants.pubspecFileName));
if (!pubspecFile.existsSync()) {
if (verbose) {
stdout.writeln('${Constants.errorMessage} pubspec.yaml not found');
}
return;
}
String content = await pubspecFile.readAsString();
// Update project name
content = content.replaceAll('name: base_kit_app', 'name: $projectName');
// Update description
content = content.replaceAll(
'description: "A new Flutter project."',
'description: "A Flutter project generated with Flutter Base Kit."',
);
// Write updated content first
await pubspecFile.writeAsString(content);
// Add flutter_base_kit dependency if not exists
await _addFlutterBaseKitDependency(pubspecFile, verbose);
if (verbose) {
stdout.writeln('${Constants.updateMessage} Updated pubspec.yaml');
}
}