makeRunnerDir function

Directory makeRunnerDir(
  1. String origin, [
  2. String? dirPath
])

Make the runner directory and return the Directory object. Handles cases where origin or dirPath ends with '/runner' or '/runner/'.

Implementation

Directory makeRunnerDir(String origin, [String? dirPath]) {
  final basePath = dirPath ?? origin;

  // Normalize the path to remove any trailing slashes
  final normalizedPath = basePath.replaceAll(RegExp(r'[/\\]+$'), '');

  // Check if the path already ends with 'runner'
  final runnerDirPath =
      normalizedPath.endsWith('/runner')
          ? normalizedPath
          : '$normalizedPath/runner';

  return Directory(runnerDirPath);
}