Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor nextcloud package exports #869

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell/dart_flutter.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
autofocus
expando
gapless
lerp
pubspec
Expand Down
1 change: 0 additions & 1 deletion packages/neon/neon/lib/models.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export 'package:neon/src/models/account.dart' hide Credentials, LoginQRcode;
export 'package:neon/src/models/app_ids.dart';
export 'package:neon/src/models/app_implementation.dart';
export 'package:neon/src/models/notifications_interface.dart';
1 change: 0 additions & 1 deletion packages/neon/neon/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/bloc/result_builder.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart';
import 'package:neon/src/models/push_notification.dart';
Expand Down
1 change: 1 addition & 0 deletions packages/neon/neon/lib/src/blocs/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/settings/models/storage.dart';
import 'package:neon/src/utils/account_options.dart';
import 'package:neon/src/utils/global_options.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:rxdart/rxdart.dart';

const _keyAccounts = 'accounts';
Expand Down
1 change: 0 additions & 1 deletion packages/neon/neon/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart';
import 'package:neon/src/settings/models/options_collection.dart';
Expand Down
1 change: 1 addition & 0 deletions packages/neon/neon/lib/src/blocs/next_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/utils/global_options.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:rxdart/rxdart.dart';

@internal
Expand Down
6 changes: 0 additions & 6 deletions packages/neon/neon/lib/src/models/app_ids.dart

This file was deleted.

1 change: 1 addition & 0 deletions packages/neon/neon/lib/src/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:neon/src/widgets/app_bar.dart';
import 'package:neon/src/widgets/drawer.dart';
import 'package:neon/src/widgets/error.dart';
import 'package:neon/src/widgets/unified_search_results.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';

@internal
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/settings/models/storage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:meta/meta.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:nextcloud/ids.dart';
import 'package:shared_preferences/shared_preferences.dart';

@internal
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/widgets/cached_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:neon/nextcloud.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/widgets/error.dart';
import 'package:neon/src/widgets/linear_progress_indicator.dart';
import 'package:nextcloud/nextcloud.dart';

typedef CacheReviver = FutureOr<Uint8List?> Function(CacheManager cacheManager);
typedef ImageDownloader = FutureOr<Uint8List> Function();
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_files/lib/routes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/nextcloud.dart';
import 'package:neon/utils.dart';
import 'package:neon_files/neon_files.dart';

Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_news/lib/routes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/nextcloud.dart';
import 'package:neon/utils.dart';
import 'package:neon_news/neon_news.dart';

Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_notes/lib/routes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/nextcloud.dart';
import 'package:neon/utils.dart';
import 'package:neon_notes/neon_notes.dart';

Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_notifications/lib/routes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/nextcloud.dart';
import 'package:neon/utils.dart';
import 'package:neon_notifications/neon_notifications.dart';

Expand Down
62 changes: 62 additions & 0 deletions packages/nextcloud/bin/generate_exports.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// ignore_for_file: depend_on_referenced_packages
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:path/path.dart' as p;

void main() {
final files =
Directory('lib/src/api').listSync().cast<File>().where((final file) => file.path.endsWith('.openapi.dart'));

final idStatements = <String>[];
final exportStatements = <String>[
"export 'ids.dart';",
"export 'src/client.dart';",
"export 'webdav.dart';",
];

for (final file in files) {
final basename = p.basename(file.path);
final id = basename.substring(0, basename.length - 13);
final variablePrefix = toDartName(id);
final classPrefix = toDartName(id, uppercaseFirstCharacter: true);

idStatements.add(" static const $variablePrefix = '$id';");
exportStatements.add("export '$id.dart';");

final exports = ["export 'src/api/$id.openapi.dart';"];
if (File('lib/src/helpers/$id.dart').existsSync()) {
exports.add("export 'src/helpers/$id.dart';");
}

File('lib/$id.dart').writeAsStringSync('''
import 'package:nextcloud/src/api/$id.openapi.dart';
import 'package:nextcloud/src/client.dart';

${exports.join('\n')}

// ignore: public_member_api_docs
extension ${classPrefix}Extension on NextcloudClient {
static final _$variablePrefix = Expando<${classPrefix}Client>();
provokateurin marked this conversation as resolved.
Show resolved Hide resolved

/// Client for the $id APIs
${classPrefix}Client get $variablePrefix => _$variablePrefix[this] ??= ${classPrefix}Client.fromClient(this);
}
''');
}

File('lib/ids.dart').writeAsStringSync('''
// ignore_for_file: public_member_api_docs

final class AppIDs {
${idStatements.join('\n')}
}
''');

File('lib/nextcloud.dart').writeAsStringSync('''
export 'package:dynamite_runtime/http_client.dart' show CookieJar, DynamiteApiException, DynamiteRawResponse, DynamiteResponse;

${exportStatements.sorted((final a, final b) => a.compareTo(b)).join('\n')}
''');
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/comments.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/comments.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/comments.openapi.dart';

// ignore: public_member_api_docs
extension CommentsExtension on NextcloudClient {
static final _comments = Expando<CommentsClient>();

/// Client for the comments APIs
CommentsClient get comments => _comments[this] ??= CommentsClient.fromClient(this);
}
13 changes: 13 additions & 0 deletions packages/nextcloud/lib/core.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:nextcloud/src/api/core.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/core.openapi.dart';
export 'src/helpers/core.dart';

// ignore: public_member_api_docs
extension CoreExtension on NextcloudClient {
static final _core = Expando<CoreClient>();

/// Client for the core APIs
CoreClient get core => _core[this] ??= CoreClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/dashboard.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/dashboard.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/dashboard.openapi.dart';

// ignore: public_member_api_docs
extension DashboardExtension on NextcloudClient {
static final _dashboard = Expando<DashboardClient>();

/// Client for the dashboard APIs
DashboardClient get dashboard => _dashboard[this] ??= DashboardClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/dav.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/dav.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/dav.openapi.dart';

// ignore: public_member_api_docs
extension DavExtension on NextcloudClient {
static final _dav = Expando<DavClient>();

/// Client for the dav APIs
DavClient get dav => _dav[this] ??= DavClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/files.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/files.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/files.openapi.dart';

// ignore: public_member_api_docs
extension FilesExtension on NextcloudClient {
static final _files = Expando<FilesClient>();

/// Client for the files APIs
FilesClient get files => _files[this] ??= FilesClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/files_external.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/files_external.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/files_external.openapi.dart';

// ignore: public_member_api_docs
extension FilesExternalExtension on NextcloudClient {
static final _filesExternal = Expando<FilesExternalClient>();

/// Client for the files_external APIs
FilesExternalClient get filesExternal => _filesExternal[this] ??= FilesExternalClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/files_reminders.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/files_reminders.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/files_reminders.openapi.dart';

// ignore: public_member_api_docs
extension FilesRemindersExtension on NextcloudClient {
static final _filesReminders = Expando<FilesRemindersClient>();

/// Client for the files_reminders APIs
FilesRemindersClient get filesReminders => _filesReminders[this] ??= FilesRemindersClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/files_sharing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/files_sharing.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/files_sharing.openapi.dart';

// ignore: public_member_api_docs
extension FilesSharingExtension on NextcloudClient {
static final _filesSharing = Expando<FilesSharingClient>();

/// Client for the files_sharing APIs
FilesSharingClient get filesSharing => _filesSharing[this] ??= FilesSharingClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/files_trashbin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/files_trashbin.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/files_trashbin.openapi.dart';

// ignore: public_member_api_docs
extension FilesTrashbinExtension on NextcloudClient {
static final _filesTrashbin = Expando<FilesTrashbinClient>();

/// Client for the files_trashbin APIs
FilesTrashbinClient get filesTrashbin => _filesTrashbin[this] ??= FilesTrashbinClient.fromClient(this);
}
12 changes: 12 additions & 0 deletions packages/nextcloud/lib/files_versions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nextcloud/src/api/files_versions.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/files_versions.openapi.dart';

// ignore: public_member_api_docs
extension FilesVersionsExtension on NextcloudClient {
static final _filesVersions = Expando<FilesVersionsClient>();

/// Client for the files_versions APIs
FilesVersionsClient get filesVersions => _filesVersions[this] ??= FilesVersionsClient.fromClient(this);
}
25 changes: 25 additions & 0 deletions packages/nextcloud/lib/ids.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ignore_for_file: public_member_api_docs

final class AppIDs {
static const filesSharing = 'files_sharing';
static const filesVersions = 'files_versions';
static const files = 'files';
static const updatenotification = 'updatenotification';
static const dashboard = 'dashboard';
static const uppush = 'uppush';
static const settings = 'settings';
static const dav = 'dav';
static const userStatus = 'user_status';
static const notifications = 'notifications';
static const notes = 'notes';
static const news = 'news';
static const core = 'core';
static const filesTrashbin = 'files_trashbin';
static const comments = 'comments';
static const sharebymail = 'sharebymail';
static const filesExternal = 'files_external';
static const filesReminders = 'files_reminders';
static const provisioningApi = 'provisioning_api';
static const theming = 'theming';
static const weatherStatus = 'weather_status';
}
13 changes: 13 additions & 0 deletions packages/nextcloud/lib/news.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:nextcloud/src/api/news.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/news.openapi.dart';
export 'src/helpers/news.dart';

// ignore: public_member_api_docs
extension NewsExtension on NextcloudClient {
static final _news = Expando<NewsClient>();

/// Client for the news APIs
NewsClient get news => _news[this] ??= NewsClient.fromClient(this);
}
Loading