findTemplatesPath static method

Future<String> findTemplatesPath({
  1. void onProgress(
    1. String message
    )?,
})

Implementation

static Future<String> findTemplatesPath({
  void Function(String message)? onProgress,
}) async {
  final String scriptPath = Platform.script.toFilePath();
  final String scriptDir = p.dirname(scriptPath);

  final List<String> possiblePaths = <String>[
    p.join(scriptDir, '..', '..', 'templates'),
    p.join(Directory.current.path, '..', 'templates'),
    p.join(Directory.current.path, 'templates'),
  ];

  for (final String path in possiblePaths) {
    final String normalizedPath = p.normalize(path);
    if (Directory(normalizedPath).existsSync()) {
      verbose('Found local templates at: $normalizedPath');
      return normalizedPath;
    }
  }

  onProgress?.call('Downloading templates from GitHub...');
  return await TemplateDownloader.ensureTemplates(onProgress: onProgress);
}