getRef function

Future<List<DocComponent>> getRef({
  1. required String ref,
  2. required Directory dartRoot,
  3. required Directory gitRoot,
  4. required bool cache,
})

Implementation

Future<List<DocComponent>> getRef({
  required String ref,
  required Directory dartRoot,
  required Directory gitRoot,
  required bool cache,
}) async {
  // Check if ref is a local file path
  final file = File(ref);
  if (file.existsSync()) {
    logger.info('Reading API documentation from local file: $ref');
    final content = await file.readAsString();
    return parseDocComponentsFile(content);
  }

  // Handle git refs
  if (cache) {
    final cache = Cache();

    if (cache.hasApiFile(gitRoot.path, ref)) {
      logger.success('Using cached API documentation for $ref');
      final cachedContent = await cache.retrieveApiFile(gitRoot.path, ref);
      if (cachedContent != null) {
        return parseDocComponentsFile(cachedContent);
      }
    } else {
      logger.info("Cache miss for $ref");
    }
  } else {
    logger.info("Cache is disabled for $ref");
  }

  // Generate the API documentation for the ref
  return generateDocs(
    gitRef: ref,
    out: null,
    dartRoot: dartRoot,
    gitRoot: gitRoot,
    shouldCache: cache,
  );
}