model static method

FileModel model(
  1. String? name,
  2. String command,
  3. bool wrapperFolder, {
  4. String? on,
  5. String? folderName,
})

Implementation

static FileModel model(String? name, String command, bool wrapperFolder,
    {String? on, String? folderName}) {
  if (on != null && on != '') {
    on = replaceAsExpected(path: on).replaceAll('\\\\', '\\');
    var current = Directory('lib');
    final list = current.listSync(recursive: true, followLinks: false);
    final contains = list.firstWhere((element) {
      if (element is File) {
        return false;
      }

      return '${element.path}${p.separator}'.contains('$on${p.separator}');
    }, orElse: () {
      return list.firstWhere((element) {
        //Fix erro ao encontrar arquivo com nome
        if (element is File) {
          return false;
        }
        return element.path.contains(on!);
      }, orElse: () {
        throw CliException(LocaleKeys.error_folder_not_found.trArgs([on]));
      });
    });

    return FileModel(
      name: name,
      path: Structure.getPathWithName(
        contains.path,
        ReCase(name!).snakeCase,
        createWithWrappedFolder: wrapperFolder,
        folderName: folderName,
      ),
      commandName: command,
    );
  }
  return FileModel(
    name: name,
    path: Structure.getPathWithName(
      _paths[command],
      ReCase(name!).snakeCase,
      createWithWrappedFolder: wrapperFolder,
      folderName: folderName,
    ),
    commandName: command,
  );
}