defaultTemplateDirectoryPath method

Future<String> defaultTemplateDirectoryPath()

Gets default template directory path

Implementation

Future<String> defaultTemplateDirectoryPath() async {
  // If running not inside dart vm - exit
  if (!Platform.script.hasAbsolutePath) {
    throw GenerateTemplatesUnreachableException(
      'script entry has no absolute path',
    );
  }

  final defaultDirPath = p.join(
    p.dirname(p.joinAll(Platform.script.pathSegments)),
    p.normalize(templatesRelativeToExecutableDirectory),
  );

  final dir = Directory(defaultDirPath);
  if (!dir.existsSync()) {
    dir.createSync(recursive: true);
  }
  // copy template files from package to executable dir
  await copyTemplatesToScriptPath(defaultDirPath);
  return defaultDirPath;
}