generateFolder function

void generateFolder(
  1. String name
)

Generates a set of directories for a given project structure.

This function creates the main directories used in a typical Flutter project architecture, including 'themes', 'core', 'utils', and a custom 'packages' directory. Each directory is created recursively, ensuring that all parent directories exist. After creating these directories, it also initializes a new package in the 'packages' directory using Flutter's CLI tools, specifically tailored for repository packages.

Additionally, this function calls subFolder to create more specific subdirectories within the project structure based on the provided name.

Errors during directory creation are caught and logged, indicating if a directory already exists.

Parameters:

  • name : The base name used for creating specific subdirectories and naming the custom package within the 'packages' directory.

Example usage: generateFolder("my_project");

Implementation

void generateFolder(String name) {
  // Create three additional directories: themes, core, and utils
  Directory themes = Directory('example/lib/themes');
  Directory core = Directory('example/lib/core');
  Directory utils = Directory('example/lib/utils');

  // Create the themes directory and generate a file inside it
  themes
      .create(recursive: true)
      .then((value) => generateFile(value.path))
      .catchError((error) => print('Folder $error already exists'));

  // Create the core directory and generate a file inside it
  core
      .create(recursive: true)
      .then((value) => generateFile(value.path))
      .catchError((error) => print('Folder $error already exists'));

  // Create the utils directory and generate a file inside it
  utils
      .create(recursive: true)
      .then((value) => generateFile(value.path))
      .catchError((error) => print('Folder $error already exists'));

  final runner = ProcessRunner();

  // Create the packages directory and initialize a new package
  generateRepository(name, runner);

  // Call the subFolder function with the given name
  subFolder('lib/$name');
}