updateAppPubspec static method
Implementation
static Future<void> updateAppPubspec(
String appDir,
String appName,
bool verbose,
) async {
final pubspecFile = File(path.join(appDir, Constants.pubspecFileName));
if (!pubspecFile.existsSync()) {
if (verbose) {
stdout
.writeln('${Constants.errorMessage} pubspec.yaml not found in app');
}
return;
}
String content = await pubspecFile.readAsString();
// Replace the entire content with our template content
final root = CopyUtils.findTemplatePath();
final templatePath = path.join(root, 'templates',
Constants.baseKitAppTemplate, Constants.pubspecFileName);
final templateFile = File(templatePath);
if (templateFile.existsSync()) {
content = await templateFile.readAsString();
// Update project name
content = content.replaceAll('name: base_kit_app', 'name: $appName');
// Update description
content = content.replaceAll(
'description: "Flutter app template with base structure"',
'description: "A Flutter app generated with Flutter Base Kit."',
);
}
await pubspecFile.writeAsString(content);
if (verbose) {
stdout.writeln('${Constants.updateMessage} Updated app pubspec.yaml');
}
}