createFolderStructure method
Implementation
Future<bool> createFolderStructure(
FolderStructure structure,
String projectPath,
) async {
try {
_cliHelper.printSection('\nš Creating folder structure...');
_cliHelper.printInfo(' Architecture: ${structure.pattern}');
final libPath = '$projectPath/lib';
final libDir = Directory(libPath);
if (!libDir.existsSync()) {
_cliHelper.printError(' ā lib/ directory not found!');
return false;
}
var createdCount = 0;
var skippedCount = 0;
for (var i = 0; i < structure.folders.length; i++) {
final folder = structure.folders[i];
final folderPath = '$libPath/$folder';
final dir = Directory(folderPath);
if (dir.existsSync()) {
_cliHelper.printWarning(' ā $folder (already exists)');
skippedCount++;
} else {
await dir.create(recursive: true);
_cliHelper.printSuccess(' ā Created: $folder');
final gitkeepFile = File('$folderPath/.gitkeep');
await gitkeepFile.writeAsString('', flush: true);
createdCount++;
}
_cliHelper.showProgress(i + 1, structure.folders.length);
}
print('');
_cliHelper.printSuccess('\n ā Folder structure created successfully!');
_cliHelper.printInfo(
' Summary: $createdCount created, $skippedCount already existed',
);
await _createArchitectureReadme(structure, libPath);
return true;
} catch (e) {
_cliHelper.printError(' ā Error creating folders: $e');
return false;
}
}