process method

  1. @override
Future<Map<String, dynamic>> process()
override

Internal method used by dash_agent to convert the shared DataSource to json format that can be sent on the web

Note: Ideally, this method is not supposed to be overriden by the child objects and should not be altered. It is called automatically by the framework.

Implementation

@override
Future<Map<String, dynamic>> process() async {
  if (!directory.existsSync()) {
    throw Exception('Directory does not exist');
  }

  List<Map<String, dynamic>> files = [];

  for (var file in directory.listSync(recursive: true)) {
    if (file is File) {
      if (regex != null && !regex!.hasMatch(file.path)) {
        continue;
      }

      String content = await file.readAsString();

      files.add({
        'id': hashCode.toString(),
        'type': 'file_object',
        'content': content,
        ...(includePaths
            ? {'path': p.relative(file.path, from: relativeTo)}
            : {}),
      });
    }
  }

  return {
    'id': hashCode.toString(),
    'type': 'directory_files',
    'files': files,
    'version': minCliVersion
  };
}