createFolderStructure method

Future<bool> createFolderStructure(
  1. FolderStructure structure,
  2. String projectPath
)

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;
  }
}