copyBaseFiles method

Future<void> copyBaseFiles()

Implementation

Future<void> copyBaseFiles() async {
  final filesToCopy = baseFilesDir
      .list()
      .where((event) => event is File)
      .where((event) {
        final baseName = path.basename(event.path);

        return baseName.endsWith(".js") || baseName.endsWith(".css") || baseName.endsWith(".png");
      })
      .where((event) => !event.path.contains("base/base.html"))
      .cast<File>();

  await for (final file in filesToCopy) {
    final shouldFileBeExcluded = _config.destinationFilesExclude?.contains(file.path.replaceAll(baseFilesDir.absolute.path, "").replaceAll("\\", "/"));

    if (!(shouldFileBeExcluded ?? true)) {
      await file.copy(path.join(destinationDir.absolute.path, path.basename(file.path)));
    }
  }

  for (final includePath in _config.destinationFilesInclude ?? <String>[]) {
    final file = File(path.join(baseFilesDir.absolute.path, path.relative(Utils.makeRelativePath(includePath))));

    if (!file.existsSync()) {
      return;
    }

    final copyFile = File(path.join(destinationDir.absolute.path, path.relative(Utils.makeRelativePath(includePath))));

    await copyFile.create(recursive: true);

    await file.copy(path.join(destinationDir.absolute.path, path.relative(Utils.makeRelativePath(includePath))));
  }
}