diff --git a/example/.fvmrc b/example/.fvmrc new file mode 100644 index 0000000..5c7f58e --- /dev/null +++ b/example/.fvmrc @@ -0,0 +1,3 @@ +{ + "flutter": "3.24.5" +} \ No newline at end of file diff --git a/example/.gitignore b/example/.gitignore index a8e938c..d5da9ef 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -45,3 +45,6 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +# FVM Version Cache +.fvm/ \ No newline at end of file diff --git a/example/lib/app.dart b/example/lib/app.dart index 2f5334a..3f1633b 100644 --- a/example/lib/app.dart +++ b/example/lib/app.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -24,14 +24,17 @@ */ import 'package:flutter/material.dart'; -import 'package:news_app/di/dependency_injector.dart'; +import 'package:news_app/app.di.pine.dart'; import 'package:news_app/pages/home_page.dart'; +import 'package:pine_annotations/pine_annotations.dart'; +@SeedContainer() class App extends StatelessWidget { const App({super.key}); @override - Widget build(BuildContext context) => DependencyInjector( + Widget build(BuildContext context) => PineSeeded( + onNewsBlocInit: (_, bloc) => bloc.fetchNews(), child: MaterialApp( debugShowCheckedModeBanner: false, title: 'News App', diff --git a/example/lib/blocs/news/news_bloc.dart b/example/lib/blocs/news/news_bloc.dart index 000f342..e7491f3 100644 --- a/example/lib/blocs/news/news_bloc.dart +++ b/example/lib/blocs/news/news_bloc.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -27,10 +27,12 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:news_app/models/article.dart'; import 'package:news_app/repositories/news_repository.dart'; +import 'package:pine_annotations/pine_annotations.dart'; part 'news_event.dart'; part 'news_state.dart'; +@Seed() class NewsBloc extends Bloc { final NewsRepository newsRepository; diff --git a/example/lib/blocs/news/news_event.dart b/example/lib/blocs/news/news_event.dart index 5913026..4328622 100644 --- a/example/lib/blocs/news/news_event.dart +++ b/example/lib/blocs/news/news_event.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/blocs/news/news_state.dart b/example/lib/blocs/news/news_state.dart index a611fcd..aad5bf4 100644 --- a/example/lib/blocs/news/news_state.dart +++ b/example/lib/blocs/news/news_state.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/di/dependency_injector.dart b/example/lib/di/dependency_injector.dart deleted file mode 100644 index 1c98ba8..0000000 --- a/example/lib/di/dependency_injector.dart +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023 MyLittleSuite - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:news_app/blocs/news/news_bloc.dart'; -import 'package:news_app/models/article.dart'; -import 'package:news_app/repositories/mappers/article_mapper.dart'; -import 'package:news_app/repositories/news_repository.dart'; -import 'package:news_app/services/news_service.dart'; -import 'package:news_app/services/responses/article_dto.dart'; -import 'package:pine/pine.dart'; -import 'package:provider/provider.dart'; -import 'package:provider/single_child_widget.dart'; - -part 'blocs.dart'; -part 'mappers.dart'; -part 'providers.dart'; -part 'repositories.dart'; - -class DependencyInjector extends StatelessWidget { - final Widget child; - - const DependencyInjector({ - super.key, - required this.child, - }); - - @override - Widget build(BuildContext context) => DependencyInjectorHelper( - blocs: _blocs, - providers: _providers, - repositories: _repositories, - mappers: _mappers, - child: child, - ); -} diff --git a/example/lib/di/mappers.dart b/example/lib/di/mappers.dart deleted file mode 100644 index 6e54786..0000000 --- a/example/lib/di/mappers.dart +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2023 MyLittleSuite - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -part of 'dependency_injector.dart'; - -final List _mappers = [ - Provider>( - create: (_) => const ArticleMapper(), - ), -]; diff --git a/example/lib/di/providers.dart b/example/lib/di/providers.dart deleted file mode 100644 index 259ccee..0000000 --- a/example/lib/di/providers.dart +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023 MyLittleSuite - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -part of 'dependency_injector.dart'; - -final List _providers = [ - Provider( - create: (_) => Dio(), - ), - Provider( - create: (context) => NewsService( - context.read(), - baseUrl: 'https://newsapi.org/v2/', - ), - ), -]; diff --git a/example/lib/di/repositories.dart b/example/lib/di/repositories.dart deleted file mode 100644 index 5b342d5..0000000 --- a/example/lib/di/repositories.dart +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2023 MyLittleSuite - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -part of 'dependency_injector.dart'; - -final List _repositories = [ - RepositoryProvider( - create: (context) => NewsRepositoryImpl( - newsService: context.read(), - mapper: context.read(), - ), - ), -]; diff --git a/example/lib/main.dart b/example/lib/main.dart index f8c7ec4..406ca01 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/models/article.dart b/example/lib/models/article.dart index 092388e..61d5418 100644 --- a/example/lib/models/article.dart +++ b/example/lib/models/article.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index 768f1e9..7e95421 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/pages/webview_page.dart b/example/lib/pages/webview_page.dart index 5a4a502..8b28e6e 100644 --- a/example/lib/pages/webview_page.dart +++ b/example/lib/pages/webview_page.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/repositories/mappers/article_mapper.dart b/example/lib/repositories/mappers/article_mapper.dart index 6a1e0f4..3b0fbbf 100644 --- a/example/lib/repositories/mappers/article_mapper.dart +++ b/example/lib/repositories/mappers/article_mapper.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -26,9 +26,10 @@ import 'package:news_app/models/article.dart'; import 'package:news_app/services/responses/article_dto.dart'; import 'package:pine/pine.dart'; +import 'package:pine_annotations/pine_annotations.dart'; +@Seed(singleton: false) class ArticleMapper extends DTOMapper { - const ArticleMapper(); @override diff --git a/example/lib/repositories/news_repository.dart b/example/lib/repositories/news_repository.dart index b91fe3c..6a1547c 100644 --- a/example/lib/repositories/news_repository.dart +++ b/example/lib/repositories/news_repository.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -27,11 +27,13 @@ import 'package:news_app/models/article.dart'; import 'package:news_app/services/news_service.dart'; import 'package:news_app/services/responses/article_dto.dart'; import 'package:pine/pine.dart'; +import 'package:pine_annotations/pine_annotations.dart'; abstract class NewsRepository { Future> get news; } +@Seed() class NewsRepositoryImpl extends NewsRepository { final NewsService newsService; final DTOMapper mapper; diff --git a/example/lib/services/dio.dart b/example/lib/services/dio.dart new file mode 100644 index 0000000..4ed034e --- /dev/null +++ b/example/lib/services/dio.dart @@ -0,0 +1,32 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:dio/io.dart'; +import 'package:pine_annotations/pine_annotations.dart'; + +@Seed() +class Dio extends DioForNative {} diff --git a/example/lib/services/news_service.dart b/example/lib/services/news_service.dart index 2fc3cbc..07bb2d7 100644 --- a/example/lib/services/news_service.dart +++ b/example/lib/services/news_service.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -23,20 +23,25 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -import 'package:dio/dio.dart'; +import 'package:dio/dio.dart' hide Headers, Dio; +import 'package:news_app/services/dio.dart'; import 'package:news_app/services/responses/everything_response.dart'; -import 'package:retrofit/retrofit.dart' as retrofit; +import 'package:pine_annotations/pine_annotations.dart'; +import 'package:retrofit/retrofit.dart'; part 'news_service.g.dart'; -@retrofit.RestApi() +@RestApi() +@Seed(constructorParams: { + 'baseUrl': 'https://newsapi.org/v2/', +}) abstract class NewsService { factory NewsService(Dio dio, {String? baseUrl}) => _NewsService(dio, baseUrl: baseUrl); - @retrofit.GET('everything') - @retrofit.Headers({'Authorization': 'Bearer '}) + @GET('everything') + @Headers({'Authorization': 'Bearer '}) Future articles({ - @retrofit.Query('q') String query = 'italy', + @Query('q') String query = 'italy', }); } diff --git a/example/lib/services/news_service.g.dart b/example/lib/services/news_service.g.dart deleted file mode 100644 index 9f9ecff..0000000 --- a/example/lib/services/news_service.g.dart +++ /dev/null @@ -1,57 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'news_service.dart'; - -// ************************************************************************** -// RetrofitGenerator -// ************************************************************************** - -// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers - -class _NewsService implements NewsService { - _NewsService( - this._dio, { - this.baseUrl, - }); - - final Dio _dio; - - String? baseUrl; - - @override - Future articles({query = 'italy'}) async { - const _extra = {}; - final queryParameters = {r'q': query}; - final _headers = {r'Authorization': 'Bearer '}; - _headers.removeWhere((k, v) => v == null); - final _data = {}; - final _result = await _dio - .fetch>(_setStreamType(Options( - method: 'GET', - headers: _headers, - extra: _extra, - ) - .compose( - _dio.options, - 'everything', - queryParameters: queryParameters, - data: _data, - ) - .copyWith(baseUrl: baseUrl ?? _dio.options.baseUrl))); - final value = EverythingResponse.fromJson(_result.data!); - return value; - } - - RequestOptions _setStreamType(RequestOptions requestOptions) { - if (T != dynamic && - !(requestOptions.responseType == ResponseType.bytes || - requestOptions.responseType == ResponseType.stream)) { - if (T == String) { - requestOptions.responseType = ResponseType.plain; - } else { - requestOptions.responseType = ResponseType.json; - } - } - return requestOptions; - } -} diff --git a/example/lib/services/responses/article_dto.dart b/example/lib/services/responses/article_dto.dart index 2b9927c..600d7ef 100644 --- a/example/lib/services/responses/article_dto.dart +++ b/example/lib/services/responses/article_dto.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/services/responses/everything_response.dart b/example/lib/services/responses/everything_response.dart index 1f5e9aa..92ee854 100644 --- a/example/lib/services/responses/everything_response.dart +++ b/example/lib/services/responses/everything_response.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/lib/widgets/article_widget.dart b/example/lib/widgets/article_widget.dart index 84c24be..534b31b 100644 --- a/example/lib/widgets/article_widget.dart +++ b/example/lib/widgets/article_widget.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..2a2bd5d 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import webview_flutter_wkwebview func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin")) } diff --git a/example/pubspec.lock b/example/pubspec.lock index 75103d2..4cb9284 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,26 +5,31 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a + sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834 url: "https://pub.dev" source: hosted - version: "61.0.0" + version: "72.0.0" + _macros: + dependency: transitive + description: dart + source: sdk + version: "0.3.2" analyzer: dependency: transitive description: name: analyzer - sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 + sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139 url: "https://pub.dev" source: hosted - version: "5.13.0" + version: "6.7.0" args: dependency: transitive description: name: args - sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 url: "https://pub.dev" source: hosted - version: "2.4.2" + version: "2.6.0" async: dependency: transitive description: @@ -37,18 +42,18 @@ packages: dependency: transitive description: name: bloc - sha256: "3820f15f502372d979121de1f6b97bfcf1630ebff8fe1d52fb2b0bfa49be5b49" + sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e" url: "https://pub.dev" source: hosted - version: "8.1.2" + version: "8.1.4" bloc_test: dependency: "direct dev" description: name: bloc_test - sha256: "02f04270be5abae8df171143e61a0058a7acbce5dcac887612e89bb40cca4c33" + sha256: "165a6ec950d9252ebe36dc5335f2e6eb13055f33d56db0eeb7642768849b43d2" url: "https://pub.dev" source: hosted - version: "9.1.5" + version: "9.1.7" boolean_selector: dependency: transitive description: @@ -77,34 +82,34 @@ packages: dependency: transitive description: name: build_daemon - sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" + sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9" url: "https://pub.dev" source: hosted - version: "4.0.1" + version: "4.0.2" build_resolvers: dependency: transitive description: name: build_resolvers - sha256: "64e12b0521812d1684b1917bc80945625391cb9bdd4312536b1d69dcb6133ed8" + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" url: "https://pub.dev" source: hosted - version: "2.4.1" + version: "2.4.2" build_runner: dependency: "direct dev" description: name: build_runner - sha256: "10c6bcdbf9d049a0b666702cf1cee4ddfdc38f02a19d35ae392863b47519848b" + sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d" url: "https://pub.dev" source: hosted - version: "2.4.6" + version: "2.4.13" build_runner_core: dependency: transitive description: name: build_runner_core - sha256: c9e32d21dd6626b5c163d48b037ce906bbe428bc23ab77bcd77bb21e593b6185 + sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0 url: "https://pub.dev" source: hosted - version: "7.2.11" + version: "7.3.2" built_collection: dependency: transitive description: @@ -117,10 +122,10 @@ packages: dependency: transitive description: name: built_value - sha256: "723b4021e903217dfc445ec4cf5b42e27975aece1fc4ebbc1ca6329c2d9fb54e" + sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb url: "https://pub.dev" source: hosted - version: "8.7.0" + version: "8.9.2" characters: dependency: transitive description: @@ -149,10 +154,10 @@ packages: dependency: transitive description: name: code_builder - sha256: "1be9be30396d7e4c0db42c35ea6ccd7cc6a1e19916b5dc64d6ac216b5544d677" + sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e" url: "https://pub.dev" source: hosted - version: "4.7.0" + version: "4.10.1" collection: dependency: transitive description: @@ -165,34 +170,34 @@ packages: dependency: transitive description: name: convert - sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.1.2" coverage: dependency: transitive description: name: coverage - sha256: ac86d3abab0f165e4b8f561280ff4e066bceaac83c424dd19f1ae2c2fcd12ca9 + sha256: "4b03e11f6d5b8f6e5bb5e9f7889a56fe6c5cbe942da5378ea4d4d7f73ef9dfe5" url: "https://pub.dev" source: hosted - version: "1.7.1" + version: "1.11.0" crypto: dependency: transitive description: name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.6" dart_style: dependency: transitive description: name: dart_style - sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.3.7" diff_match_patch: dependency: transitive description: @@ -205,18 +210,26 @@ packages: dependency: "direct main" description: name: dio - sha256: "417e2a6f9d83ab396ec38ff4ea5da6c254da71e4db765ad737a42af6930140b7" + sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260" + url: "https://pub.dev" + source: hosted + version: "5.7.0" + dio_web_adapter: + dependency: transitive + description: + name: dio_web_adapter + sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8" url: "https://pub.dev" source: hosted - version: "5.3.3" + version: "2.0.0" equatable: dependency: "direct main" description: name: equatable - sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + sha256: "567c64b3cb4cf82397aac55f4f0cbd3ca20d77c6c03bedbc4ceaddc08904aef7" url: "https://pub.dev" source: hosted - version: "2.0.5" + version: "2.0.7" fake_async: dependency: transitive description: @@ -229,18 +242,18 @@ packages: dependency: transitive description: name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 url: "https://pub.dev" source: hosted - version: "7.0.0" + version: "7.0.1" fixnum: dependency: transitive description: name: fixnum - sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" flutter: dependency: "direct main" description: flutter @@ -250,10 +263,10 @@ packages: dependency: "direct main" description: name: flutter_bloc - sha256: e74efb89ee6945bcbce74a5b3a5a3376b088e5f21f55c263fc38cbdc6237faae + sha256: b594505eac31a0518bdcb4b5b79573b8d9117b193cc80cc12e17d639b10aa27a url: "https://pub.dev" source: hosted - version: "8.1.3" + version: "8.1.6" flutter_lints: dependency: "direct dev" description: @@ -271,10 +284,10 @@ packages: dependency: transitive description: name: frontend_server_client - sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "4.0.0" glob: dependency: transitive description: @@ -287,10 +300,10 @@ packages: dependency: transitive description: name: graphs - sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" http_multi_server: dependency: transitive description: @@ -319,50 +332,50 @@ packages: dependency: transitive description: name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.7.1" json_annotation: dependency: transitive description: name: json_annotation - sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" url: "https://pub.dev" source: hosted - version: "4.8.1" + version: "4.9.0" json_serializable: dependency: "direct dev" description: name: json_serializable - sha256: aa1f5a8912615733e0fdc7a02af03308933c93235bdc8d50d0b0c8a8ccb0b969 + sha256: c2fcb3920cf2b6ae6845954186420fca40bc0a8abcc84903b7801f17d7050d7c url: "https://pub.dev" source: hosted - version: "6.7.1" + version: "6.9.0" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" lints: dependency: transitive description: @@ -375,10 +388,18 @@ packages: dependency: transitive description: name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" + url: "https://pub.dev" + source: hosted + version: "0.1.2-main.4" matcher: dependency: transitive description: @@ -391,42 +412,42 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.15.0" mime: dependency: transitive description: name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "2.0.0" mockito: dependency: "direct dev" description: name: mockito - sha256: "7d5b53bcd556c1bc7ffbe4e4d5a19c3e112b7e925e9e172dd7c6ad0630812616" + sha256: "6841eed20a7befac0ce07df8116c8b8233ed1f4486a7647c7fc5a02ae6163917" url: "https://pub.dev" source: hosted - version: "5.4.2" + version: "5.4.4" mocktail: dependency: transitive description: name: mocktail - sha256: bac151b31e4ed78bd59ab89aa4c0928f297b1180186d5daf03734519e5f596c1 + sha256: "890df3f9688106f25755f26b1c60589a92b3ab91a22b8b224947ad041bf172d8" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.0.4" nested: dependency: transitive description: @@ -462,18 +483,32 @@ packages: pine: dependency: "direct main" description: - path: ".." + path: "../packages/pine" + relative: true + source: path + version: "2.0.0" + pine_annotations: + dependency: "direct main" + description: + path: "../packages/pine_annotations" + relative: true + source: path + version: "2.0.0" + pine_generator: + dependency: "direct dev" + description: + path: "../packages/pine_generator" relative: true source: path - version: "1.0.3" + version: "2.0.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" url: "https://pub.dev" source: hosted - version: "2.1.6" + version: "2.1.8" pool: dependency: transitive description: @@ -494,10 +529,10 @@ packages: dependency: "direct main" description: name: provider - sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096" + sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c url: "https://pub.dev" source: hosted - version: "6.1.1" + version: "6.1.2" pub_semver: dependency: transitive description: @@ -510,26 +545,26 @@ packages: dependency: transitive description: name: pubspec_parse - sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 + sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8 url: "https://pub.dev" source: hosted - version: "1.2.3" + version: "1.3.0" retrofit: dependency: "direct main" description: name: retrofit - sha256: "04ed77c82cadb655bb9357e8d0cb9da72ff704749a2d0cfe6540dd1f1f7ca4b9" + sha256: "3c9885ef3dbc5dc4b3fb0a40c972ab52e4dad04d52dac9bba24dfa76cf100451" url: "https://pub.dev" source: hosted - version: "4.0.3" + version: "4.4.1" retrofit_generator: dependency: "direct dev" description: name: retrofit_generator - sha256: "24c148e3c4d5763c580cef1bd703cc13b220dbf585e47d8ab3aa8d1545a8fc5c" + sha256: "8dfc406cdfa171f33cbd21bf5bd8b6763548cc217de19cdeaa07a76727fac4ca" url: "https://pub.dev" source: hosted - version: "8.0.4" + version: "8.2.1" shelf: dependency: transitive description: @@ -550,18 +585,18 @@ packages: dependency: transitive description: name: shelf_static - sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 url: "https://pub.dev" source: hosted - version: "1.1.2" + version: "1.1.3" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67 url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "2.0.1" sky_engine: dependency: transitive description: flutter @@ -571,10 +606,10 @@ packages: dependency: transitive description: name: source_gen - sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.5.0" source_helper: dependency: transitive description: @@ -587,10 +622,10 @@ packages: dependency: transitive description: name: source_map_stack_trace - sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" source_maps: dependency: transitive description: @@ -651,26 +686,26 @@ packages: dependency: transitive description: name: test - sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e" url: "https://pub.dev" source: hosted - version: "1.24.9" + version: "1.25.7" test_api: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.2" test_core: dependency: transitive description: name: test_core - sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696" url: "https://pub.dev" source: hosted - version: "0.5.9" + version: "0.6.4" timing: dependency: transitive description: @@ -691,10 +726,10 @@ packages: dependency: transitive description: name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 url: "https://pub.dev" source: hosted - version: "1.3.2" + version: "1.4.0" vector_math: dependency: transitive description: @@ -707,10 +742,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.5" watcher: dependency: transitive description: @@ -719,14 +754,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" + url: "https://pub.dev" + source: hosted + version: "0.1.6" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "3.0.1" webkit_inspection_protocol: dependency: transitive description: @@ -739,34 +790,34 @@ packages: dependency: "direct main" description: name: webview_flutter - sha256: "42393b4492e629aa3a88618530a4a00de8bb46e50e7b3993fedbfdc5352f0dbf" + sha256: "889a0a678e7c793c308c68739996227c9661590605e70b1f6cf6b9a6634f7aec" url: "https://pub.dev" source: hosted - version: "4.4.2" + version: "4.10.0" webview_flutter_android: dependency: transitive description: name: webview_flutter_android - sha256: "8326ee235f87605a2bfc444a4abc897f4abc78d83f054ba7d3d1074ce82b4fbf" + sha256: "285cedfd9441267f6cca8843458620b5fda1af75b04f5818d0441acda5d7df19" url: "https://pub.dev" source: hosted - version: "3.12.1" + version: "4.1.0" webview_flutter_platform_interface: dependency: transitive description: name: webview_flutter_platform_interface - sha256: "6d9213c65f1060116757a7c473247c60f3f7f332cac33dc417c9e362a9a13e4f" + sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d url: "https://pub.dev" source: hosted - version: "2.6.0" + version: "2.10.0" webview_flutter_wkwebview: dependency: transitive description: name: webview_flutter_wkwebview - sha256: accdaaa49a2aca2dc3c3230907988954cdd23fed0a19525d6c9789d380f4dc76 + sha256: b7e92f129482460951d96ef9a46b49db34bd2e1621685de26e9eaafd9674e7eb url: "https://pub.dev" source: hosted - version: "3.9.4" + version: "3.16.3" yaml: dependency: transitive description: @@ -776,5 +827,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0-0 <4.0.0" - flutter: ">=3.7.0" + dart: ">=3.5.0 <4.0.0" + flutter: ">=3.24.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 3ed264c..2435097 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,12 +4,13 @@ publish_to: 'none' version: 1.0.0+1 environment: - sdk: ">=2.17.6 <4.0.0" + sdk: ">=3.0.0 <4.0.0" + dependencies: flutter: sdk: flutter - pine: - path: ../ + pine: 0.0.1 + pine_annotations: 0.0.1 flutter_bloc: ^8.1.3 provider: ^6.1.1 retrofit: ^4.0.3 @@ -22,9 +23,19 @@ dev_dependencies: sdk: flutter flutter_lints: ^4.0.0 retrofit_generator: ^8.0.4 - build_runner: ^2.4.6 + build_runner: ^2.4.8 json_serializable: ^6.7.1 bloc_test: ^9.1.5 mockito: ^5.4.2 + pine_generator: 0.0.1 + +dependency_overrides: + pine: + path: ../packages/pine + pine_generator: + path: ../packages/pine_generator + pine_annotations: + path: ../packages/pine_annotations + flutter: uses-material-design: true diff --git a/example/test/pages/home_page_test.dart b/example/test/pages/home_page_test.dart index e1d2994..79264b8 100644 --- a/example/test/pages/home_page_test.dart +++ b/example/test/pages/home_page_test.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -30,7 +30,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:news_app/blocs/news/news_bloc.dart'; import 'package:news_app/models/article.dart'; import 'package:news_app/pages/home_page.dart'; -import 'package:pine/di/dependency_injector_helper.dart'; +import 'package:pine/pine.dart'; class MockNewsBloc extends MockBloc implements NewsBloc {} diff --git a/lib/pine.dart b/lib/pine.dart deleted file mode 100644 index 61ca64f..0000000 --- a/lib/pine.dart +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2023 MyLittleSuite - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -library pine; - -export 'di/dependency_injector_helper.dart'; -export 'dto/dto.dart'; -export 'utils/mapper.dart'; -export 'utils/dto_mapper.dart'; diff --git a/packages/pine/.gitignore b/packages/pine/.gitignore new file mode 100644 index 0000000..ac5aa98 --- /dev/null +++ b/packages/pine/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/pine/.metadata b/packages/pine/.metadata new file mode 100644 index 0000000..7025a64 --- /dev/null +++ b/packages/pine/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668" + channel: "stable" + +project_type: package diff --git a/CHANGELOG.md b/packages/pine/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to packages/pine/CHANGELOG.md diff --git a/packages/pine/LICENSE b/packages/pine/LICENSE new file mode 100644 index 0000000..ba75c69 --- /dev/null +++ b/packages/pine/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/README.md b/packages/pine/README.md similarity index 100% rename from README.md rename to packages/pine/README.md diff --git a/analysis_options.yaml b/packages/pine/analysis_options.yaml similarity index 100% rename from analysis_options.yaml rename to packages/pine/analysis_options.yaml diff --git a/packages/pine/lib/pine.dart b/packages/pine/lib/pine.dart new file mode 100644 index 0000000..14d131c --- /dev/null +++ b/packages/pine/lib/pine.dart @@ -0,0 +1,33 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +library; + +export 'src/di/dependency_injector_helper.dart'; +export 'src/dto/dto.dart'; +export 'src/utils/dto_mapper.dart'; +export 'src/utils/mapper.dart'; diff --git a/lib/di/dependency_injector_helper.dart b/packages/pine/lib/src/di/dependency_injector_helper.dart similarity index 96% rename from lib/di/dependency_injector_helper.dart rename to packages/pine/lib/src/di/dependency_injector_helper.dart index 4b8ea7e..46dee3a 100644 --- a/lib/di/dependency_injector_helper.dart +++ b/packages/pine/lib/src/di/dependency_injector_helper.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -23,7 +23,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; diff --git a/lib/dto/dto.dart b/packages/pine/lib/src/dto/dto.dart similarity index 96% rename from lib/dto/dto.dart rename to packages/pine/lib/src/dto/dto.dart index 240efe7..79f0dc4 100644 --- a/lib/dto/dto.dart +++ b/packages/pine/lib/src/dto/dto.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lib/utils/dto_mapper.dart b/packages/pine/lib/src/utils/dto_mapper.dart similarity index 95% rename from lib/utils/dto_mapper.dart rename to packages/pine/lib/src/utils/dto_mapper.dart index ce6c1b4..1f78060 100644 --- a/lib/utils/dto_mapper.dart +++ b/packages/pine/lib/src/utils/dto_mapper.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -23,7 +23,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -import 'package:pine/dto/dto.dart'; +import 'package:pine/src/dto/dto.dart'; abstract class DTOMapper { const DTOMapper(); diff --git a/lib/utils/mapper.dart b/packages/pine/lib/src/utils/mapper.dart similarity index 97% rename from lib/utils/mapper.dart rename to packages/pine/lib/src/utils/mapper.dart index aa0bbf0..aa75b2f 100644 --- a/lib/utils/mapper.dart +++ b/packages/pine/lib/src/utils/mapper.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/pubspec.yaml b/packages/pine/pubspec.yaml similarity index 76% rename from pubspec.yaml rename to packages/pine/pubspec.yaml index d4cf004..918e54f 100644 --- a/pubspec.yaml +++ b/packages/pine/pubspec.yaml @@ -1,22 +1,23 @@ name: pine description: A lightweight architecture helper for your Flutter projects. -version: 1.0.3 +version: 2.0.0 repository: https://github.com/MyLittleSuite/pine issue_tracker: https://github.com/MyLittleSuite/pine/issues homepage: https://www.mylittlesuite.com environment: - sdk: ">=2.17.6 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=1.17.0" dependencies: flutter: sdk: flutter - flutter_bloc: ^8.1.3 - provider: ^6.1.1 + flutter_bloc: ^8.1.6 + provider: ^6.1.2 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^4.0.0 -flutter: \ No newline at end of file + flutter_lints: ^5.0.0 + +flutter: diff --git a/test/dependency_injector_helper_test.dart b/packages/pine/test/dependency_injector_helper_test.dart similarity index 100% rename from test/dependency_injector_helper_test.dart rename to packages/pine/test/dependency_injector_helper_test.dart diff --git a/test/mocks/demo_bloc.dart b/packages/pine/test/mocks/demo_bloc.dart similarity index 100% rename from test/mocks/demo_bloc.dart rename to packages/pine/test/mocks/demo_bloc.dart diff --git a/test/mocks/demo_repository.dart b/packages/pine/test/mocks/demo_repository.dart similarity index 100% rename from test/mocks/demo_repository.dart rename to packages/pine/test/mocks/demo_repository.dart diff --git a/test/mocks/demo_service.dart b/packages/pine/test/mocks/demo_service.dart similarity index 100% rename from test/mocks/demo_service.dart rename to packages/pine/test/mocks/demo_service.dart diff --git a/test/mocks/string_mapper.dart b/packages/pine/test/mocks/string_mapper.dart similarity index 100% rename from test/mocks/string_mapper.dart rename to packages/pine/test/mocks/string_mapper.dart diff --git a/packages/pine_annotations/.gitignore b/packages/pine_annotations/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/packages/pine_annotations/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/packages/pine_annotations/CHANGELOG.md b/packages/pine_annotations/CHANGELOG.md new file mode 100644 index 0000000..effe43c --- /dev/null +++ b/packages/pine_annotations/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/packages/pine_annotations/README.md b/packages/pine_annotations/README.md new file mode 100644 index 0000000..8831761 --- /dev/null +++ b/packages/pine_annotations/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/packages/pine_annotations/analysis_options.yaml b/packages/pine_annotations/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/packages/pine_annotations/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/packages/pine_annotations/lib/pine_annotations.dart b/packages/pine_annotations/lib/pine_annotations.dart new file mode 100644 index 0000000..4d91b70 --- /dev/null +++ b/packages/pine_annotations/lib/pine_annotations.dart @@ -0,0 +1,34 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +/// Support for doing something awesome. +/// +/// More dartdocs go here. +library; + +export 'src/seed.dart'; +export 'src/seed_container.dart'; diff --git a/example/lib/di/blocs.dart b/packages/pine_annotations/lib/src/seed.dart similarity index 81% rename from example/lib/di/blocs.dart rename to packages/pine_annotations/lib/src/seed.dart index 7f43ddb..cd21b6a 100644 --- a/example/lib/di/blocs.dart +++ b/packages/pine_annotations/lib/src/seed.dart @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 MyLittleSuite + * Copyright (c) 2024 MyLittleSuite * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -23,12 +23,14 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -part of 'dependency_injector.dart'; +class Seed { + final bool singleton; + final bool lazy; + final Map? constructorParams; -final List _blocs = [ - BlocProvider( - create: (context) => NewsBloc( - newsRepository: context.read(), - )..fetchNews(), - ), -]; + const Seed({ + this.singleton = true, + this.lazy = true, + this.constructorParams, + }); +} diff --git a/packages/pine_annotations/lib/src/seed_container.dart b/packages/pine_annotations/lib/src/seed_container.dart new file mode 100644 index 0000000..b78e391 --- /dev/null +++ b/packages/pine_annotations/lib/src/seed_container.dart @@ -0,0 +1,30 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +class SeedContainer { + const SeedContainer(); +} diff --git a/packages/pine_annotations/pubspec.yaml b/packages/pine_annotations/pubspec.yaml new file mode 100644 index 0000000..b47cd27 --- /dev/null +++ b/packages/pine_annotations/pubspec.yaml @@ -0,0 +1,15 @@ +name: pine_annotations +description: A set of annotations for pine. +version: 2.0.0 +repository: https://github.com/MyLittleSuite/pine +issue_tracker: https://github.com/MyLittleSuite/pine/issues +homepage: https://www.mylittlesuite.com + +environment: + sdk: ^3.5.4 + +dependencies: + +dev_dependencies: + lints: ^4.0.0 + test: ^1.24.0 diff --git a/packages/pine_annotations/test/pine_annotations_test.dart b/packages/pine_annotations/test/pine_annotations_test.dart new file mode 100644 index 0000000..7a78f07 --- /dev/null +++ b/packages/pine_annotations/test/pine_annotations_test.dart @@ -0,0 +1,42 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:test/test.dart'; + +void main() { + group('A group of tests', () { + final awesome = true; + + setUp(() { + // Additional setup goes here. + }); + + test('First Test', () { + expect(awesome, isTrue); + }); + }); +} diff --git a/packages/pine_generator/.gitignore b/packages/pine_generator/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/packages/pine_generator/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/packages/pine_generator/CHANGELOG.md b/packages/pine_generator/CHANGELOG.md new file mode 100644 index 0000000..effe43c --- /dev/null +++ b/packages/pine_generator/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/packages/pine_generator/README.md b/packages/pine_generator/README.md new file mode 100644 index 0000000..8831761 --- /dev/null +++ b/packages/pine_generator/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/packages/pine_generator/analysis_options.yaml b/packages/pine_generator/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/packages/pine_generator/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/packages/pine_generator/build.yaml b/packages/pine_generator/build.yaml new file mode 100644 index 0000000..f1f1ebb --- /dev/null +++ b/packages/pine_generator/build.yaml @@ -0,0 +1,16 @@ +builders: + pine_analyze: + import: "package:pine_generator/pine_generator.dart" + builder_factories: [ "pineAnalyze" ] + build_extensions: { ".dart": [ ".pine.json" ] } + auto_apply: dependents + build_to: cache + runs_before: + - pine_generator:pine_di + + pine_di: + import: "package:pine_generator/pine_generator.dart" + builder_factories: [ "pineDI" ] + build_extensions: { ".dart": [ ".di.pine.dart" ] } + auto_apply: dependents + build_to: source diff --git a/packages/pine_generator/lib/pine_generator.dart b/packages/pine_generator/lib/pine_generator.dart new file mode 100644 index 0000000..fbf924c --- /dev/null +++ b/packages/pine_generator/lib/pine_generator.dart @@ -0,0 +1,33 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +library; + +export 'src/builders/pine_analyze_builder.dart'; +export 'src/builders/pine_di_builder.dart'; +export 'src/generators/pine_analyze_generator.dart'; +export 'src/generators/pine_di_generator.dart'; diff --git a/packages/pine_generator/lib/src/builders/pine_analyze_builder.dart b/packages/pine_generator/lib/src/builders/pine_analyze_builder.dart new file mode 100644 index 0000000..d5fc5d5 --- /dev/null +++ b/packages/pine_generator/lib/src/builders/pine_analyze_builder.dart @@ -0,0 +1,34 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:build/build.dart'; +import 'package:pine_generator/pine_generator.dart'; + +/// Entry point for the pine generator, analyze phase +Builder pineAnalyze(BuilderOptions options) => PineAnalyzeGenerator( + generatedExtension: '.pine.json', + ); diff --git a/packages/pine_generator/lib/src/builders/pine_di_builder.dart b/packages/pine_generator/lib/src/builders/pine_di_builder.dart new file mode 100644 index 0000000..9dc16fd --- /dev/null +++ b/packages/pine_generator/lib/src/builders/pine_di_builder.dart @@ -0,0 +1,48 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:build/build.dart'; +import 'package:pine_generator/pine_generator.dart'; +import 'package:pine_generator/src/processors/di_container_method_processor.dart'; +import 'package:pine_generator/src/processors/imports_processor.dart'; +import 'package:pine_generator/src/processors/inject_method_processor.dart'; +import 'package:pine_generator/src/processors/injector_class_processor.dart'; +import 'package:pine_generator/src/processors/seed_container_processor.dart'; +import 'package:pine_generator/src/processors/typedefs_processor.dart'; + +/// Entry point for the pine generator, DI phase +Builder pineDI(BuilderOptions options) => PineDIGenerator( + findExtension: '.pine.json', + generatedExtension: '.di.pine.dart', + typedefsProcessor: TypedefsProcessor(), + importsProcessor: ImportsProcessor(), + injectorProcessor: InjectorClassProcessor(), + seedContainerProcessor: SeedContainerProcessor( + diContainerMethodProcessor: DIContainerMethodProcessor(), + injectMethodProcessor: InjectMethodProcessor(), + ), + ); diff --git a/packages/pine_generator/lib/src/extensions/class_element.dart b/packages/pine_generator/lib/src/extensions/class_element.dart new file mode 100644 index 0000000..6248643 --- /dev/null +++ b/packages/pine_generator/lib/src/extensions/class_element.dart @@ -0,0 +1,39 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; + +extension ClassElementExtension on ClassElement { + ConstructorElement? get primaryConstructor => (constructors + ..sort( + (a, b) => a.parameters.length.compareTo(b.parameters.length) * -1)) + .firstOrNull; + + InterfaceType? get parent => + (supertype != null && !supertype!.isDartCoreObject) ? supertype! : null; +} diff --git a/packages/pine_generator/lib/src/extensions/dart_object.dart b/packages/pine_generator/lib/src/extensions/dart_object.dart new file mode 100644 index 0000000..7ca41c8 --- /dev/null +++ b/packages/pine_generator/lib/src/extensions/dart_object.dart @@ -0,0 +1,52 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:analyzer/dart/constant/value.dart'; + +extension DartObjectExtension on DartObject { + bool get isPrimitiveValue => toPrimitiveValue() != null; + + Object? toPrimitiveValue() { + if (isNull) { + return null; + } + if (toBoolValue() != null) { + return toBoolValue(); + } + if (toIntValue() != null) { + return toIntValue(); + } + if (toDoubleValue() != null) { + return toDoubleValue(); + } + if (toStringValue() != null) { + return toStringValue(); + } + + return null; + } +} diff --git a/packages/pine_generator/lib/src/generators/base_generator.dart b/packages/pine_generator/lib/src/generators/base_generator.dart new file mode 100644 index 0000000..f66543a --- /dev/null +++ b/packages/pine_generator/lib/src/generators/base_generator.dart @@ -0,0 +1,93 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'dart:async'; + +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:source_gen/source_gen.dart'; + +class GeneratorContext { + final LibraryReader library; + final BuildStep buildStep; + + GeneratorContext({ + required this.library, + required this.buildStep, + }); +} + +abstract class BaseGenerator extends Builder { + final String generatedExtension; + + BaseGenerator({ + required this.generatedExtension, + }); + + @override + Map> get buildExtensions => { + '.dart': [generatedExtension], + }; + + @override + FutureOr build(BuildStep buildStep) async { + if (!await buildStep.resolver.isLibrary(buildStep.inputId)) { + return; + } + + final generatedValue = await onGenerate( + GeneratorContext( + library: LibraryReader(await buildStep.inputLibrary), + buildStep: buildStep, + ), + ); + + if (generatedValue == null) { + return; + } + + final normalizedOutput = normalizeOutput(generatedValue); + await buildStep.writeAsString( + buildStep.inputId.changeExtension(generatedExtension), + normalizedOutput, + ); + } + + FutureOr onGenerate(GeneratorContext context); + + String normalizeOutput(Object object) { + if (object is Library) { + final emitter = DartEmitter(useNullSafetySyntax: true); + return DartFormatter() + .format(object.accept(emitter).toString()) + .toString(); + } + + return object.toString(); + } +} diff --git a/packages/pine_generator/lib/src/generators/pine_analyze_generator.dart b/packages/pine_generator/lib/src/generators/pine_analyze_generator.dart new file mode 100644 index 0000000..46f940c --- /dev/null +++ b/packages/pine_generator/lib/src/generators/pine_analyze_generator.dart @@ -0,0 +1,67 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'dart:async'; +import 'dart:convert'; + +import 'package:analyzer/dart/element/element.dart'; +import 'package:pine_annotations/pine_annotations.dart'; +import 'package:pine_generator/src/generators/base_generator.dart'; +import 'package:pine_generator/src/models/seeded.dart'; +import 'package:source_gen/source_gen.dart'; + +class PineAnalyzeGenerator extends BaseGenerator { + PineAnalyzeGenerator({ + required super.generatedExtension, + }); + + @override + FutureOr? onGenerate(GeneratorContext context) { + final annotations = context.library.annotatedWith( + TypeChecker.fromRuntime(Seed), + ); + + final seededElements = []; + for (final annotatedElement in annotations) { + final element = annotatedElement.element; + + if (element is! ClassElement) { + throw InvalidGenerationSourceError( + '${element.displayName} is not a class and cannot be annotated with @Seed.', + element: element, + todo: 'Add @Seed to a class.', + ); + } + + seededElements.add( + Seeded.fromAnnotation(element, annotatedElement.annotation), + ); + } + + return seededElements.isNotEmpty ? jsonEncode(seededElements) : null; + } +} diff --git a/packages/pine_generator/lib/src/generators/pine_di_generator.dart b/packages/pine_generator/lib/src/generators/pine_di_generator.dart new file mode 100644 index 0000000..9bc0681 --- /dev/null +++ b/packages/pine_generator/lib/src/generators/pine_di_generator.dart @@ -0,0 +1,129 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'dart:async'; +import 'dart:convert'; + +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:glob/glob.dart'; +import 'package:pine_annotations/pine_annotations.dart'; +import 'package:pine_generator/src/generators/base_generator.dart'; +import 'package:pine_generator/src/models/seeded.dart'; +import 'package:pine_generator/src/processors/injector_class_processor.dart'; +import 'package:pine_generator/src/processors/processor.dart'; +import 'package:pine_generator/src/processors/seed_container_processor.dart'; +import 'package:source_gen/source_gen.dart'; + +class PineDIGenerator extends BaseGenerator { + final String findExtension; + final Processor> typedefsProcessor; + final Processor> importsProcessor; + final Processor seedContainerProcessor; + final Processor injectorProcessor; + + PineDIGenerator({ + required super.generatedExtension, + required this.findExtension, + required this.typedefsProcessor, + required this.importsProcessor, + required this.seedContainerProcessor, + required this.injectorProcessor, + }); + + @override + FutureOr onGenerate(GeneratorContext context) async { + final seedContainerElements = context.library.annotatedWith( + TypeChecker.fromRuntime(SeedContainer), + throwOnUnresolved: false, + ); + if (seedContainerElements.isEmpty) { + return null; + } + + final seededElements = await _readSeededElements(context.buildStep); + if (seededElements == null) { + return null; + } + + final processorContext = ProcessorContext( + plants: seededElements, + ); + + return Library( + (b) => b + ..directives.addAll( + importsProcessor.process(processorContext), + ) + ..body.addAll( + [ + ...typedefsProcessor.process(processorContext), + seedContainerProcessor.process(SeedContainerProcessorContext( + containerName: 'PineSeeded', + plants: seededElements, + )), + ...seededElements.where((element) => element.singleton).map( + (element) => injectorProcessor.process( + InjectorClassProcessorContext( + currentPlant: element, + plants: seededElements, + ), + ), + ), + ], + ), + ); + } + + Future?> _readSeededElements(BuildStep buildStep) async { + final seededElements = []; + await for (final asset in buildStep.findAssets(Glob('**$findExtension'))) { + final jsonResource = jsonDecode(await buildStep.readAsString(asset)); + + final seeded = switch (jsonResource) { + Map() => [Seeded.fromJson(jsonResource)], + List() => jsonResource.map((element) { + if (element is! Map) { + throw UnimplementedError( + 'Unsupported json type: ${element.runtimeType}', + ); + } + + return Seeded.fromJson(element); + }), + _ => throw UnimplementedError( + 'Unsupported json type: ${jsonResource.runtimeType}', + ), + }; + + seededElements.addAll(seeded); + } + + seededElements.sort((first, second) => first.order.compareTo(second.order)); + return seededElements; + } +} diff --git a/packages/pine_generator/lib/src/misc/expressions.dart b/packages/pine_generator/lib/src/misc/expressions.dart new file mode 100644 index 0000000..08e2dc3 --- /dev/null +++ b/packages/pine_generator/lib/src/misc/expressions.dart @@ -0,0 +1,50 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; + +Expression createContextClosure( + String contextRef, + List statements, { + bool trailingComma = false, +}) => + CodeExpression(Block((b) { + b.statements.add(Code('($contextRef) {')); + + for (final statement in statements) { + b.addExpression(statement); + } + + if (trailingComma) { + b.statements.add(Code('},')); + } else { + b.statements.add(Code('}')); + } + })); + +Expression readFromContext(String contextRef) => + refer(contextRef).property('read').call([]); diff --git a/packages/pine_generator/lib/src/misc/utilities.dart b/packages/pine_generator/lib/src/misc/utilities.dart new file mode 100644 index 0000000..94d9ec6 --- /dev/null +++ b/packages/pine_generator/lib/src/misc/utilities.dart @@ -0,0 +1,32 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + + +String inHumanReadable(String displayName) => displayName + .replaceAll('<', 'Of') + .replaceAll('>', '') + .replaceAll(', ', 'And'); diff --git a/packages/pine_generator/lib/src/models/constructor.dart b/packages/pine_generator/lib/src/models/constructor.dart new file mode 100644 index 0000000..f7de885 --- /dev/null +++ b/packages/pine_generator/lib/src/models/constructor.dart @@ -0,0 +1,75 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:analyzer/dart/element/element.dart'; +import 'package:pine_generator/src/models/injectable_field.dart'; + +class Constructor { + final String? name; + final bool isConst; + final bool isFactory; + final List fields; + + Constructor._({ + required this.name, + required this.fields, + this.isConst = false, + this.isFactory = false, + }); + + factory Constructor.fromClassConstructor( + ConstructorElement element, + Map injectValues, + ) { + return Constructor._( + name: element.name.isNotEmpty ? element.name : null, + isConst: element.isConst, + isFactory: element.isFactory, + fields: element.parameters + .map( + (element) => InjectableField.fromParameter(element, injectValues), + ) + .toList(growable: false), + ); + } + + factory Constructor.fromJson(Map json) => Constructor._( + name: json['name'] as String?, + fields: (json['fields'] as List) + .map((e) => InjectableField.fromJson(e as Map)) + .toList(), + isConst: json['isConst'] as bool, + isFactory: json['isFactory'] as bool, + ); + + Map toJson() => { + 'name': name, + 'fields': fields.map((e) => e.toJson()).toList(growable: false), + 'isConst': isConst, + 'isFactory': isFactory, + }; +} diff --git a/packages/pine_generator/lib/src/models/enums/injection_type.dart b/packages/pine_generator/lib/src/models/enums/injection_type.dart new file mode 100644 index 0000000..a1af362 --- /dev/null +++ b/packages/pine_generator/lib/src/models/enums/injection_type.dart @@ -0,0 +1,45 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +enum InjectionType { + blocProvider, + repositoryProvider, + provider; + + static InjectionType fromJsonValue(String raw) => + InjectionType.values.firstWhere((element) => element.name == raw); + + String toJsonValue() => name; + + String get widgetName => switch (this) { + InjectionType.blocProvider => 'BlocProvider', + InjectionType.repositoryProvider => 'RepositoryProvider', + InjectionType.provider => 'Provider', + }; + + String widgetNameOf(String generic) => '$widgetName<$generic>'; +} diff --git a/packages/pine_generator/lib/src/models/enums/seeded_type.dart b/packages/pine_generator/lib/src/models/enums/seeded_type.dart new file mode 100644 index 0000000..67c85a4 --- /dev/null +++ b/packages/pine_generator/lib/src/models/enums/seeded_type.dart @@ -0,0 +1,38 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +enum SeededType { + bloc, + repository, + mapper, + generic; + + static SeededType fromJsonValue(String raw) => + SeededType.values.firstWhere((element) => element.name == raw); + + String toJsonValue() => name; +} diff --git a/packages/pine_generator/lib/src/models/injectable_field.dart b/packages/pine_generator/lib/src/models/injectable_field.dart new file mode 100644 index 0000000..60e8924 --- /dev/null +++ b/packages/pine_generator/lib/src/models/injectable_field.dart @@ -0,0 +1,76 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:analyzer/dart/element/element.dart'; + +class InjectableField { + final String name; + final String type; + final bool named; + final String? import; + final Object? value; + + InjectableField._({ + required this.name, + required this.type, + required this.named, + this.import, + this.value, + }); + + bool get positional => !named; + + factory InjectableField.fromParameter( + ParameterElement element, + Map injectValues, + ) { + return InjectableField._( + name: element.name, + type: element.type.getDisplayString(), + named: element.isNamed, + import: element.type.element?.librarySource?.uri.toString(), + value: injectValues[element.name], + ); + } + + factory InjectableField.fromJson(Map json) => + InjectableField._( + name: json['name'] as String, + type: json['type'] as String, + named: json['named'] as bool, + import: json['import'] as String?, + value: json['value'], + ); + + Map toJson() => { + 'name': name, + 'type': type, + 'named': named, + 'import': import, + 'value': value, + }; +} diff --git a/packages/pine_generator/lib/src/models/interface.dart b/packages/pine_generator/lib/src/models/interface.dart new file mode 100644 index 0000000..29d6460 --- /dev/null +++ b/packages/pine_generator/lib/src/models/interface.dart @@ -0,0 +1,65 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:analyzer/dart/element/type.dart'; +import 'package:pine_generator/src/misc/utilities.dart'; + +class Interface { + final String name; + final String humanReadable; + final String import; + + Interface._({ + required this.name, + required this.humanReadable, + required this.import, + }); + + factory Interface.fromInterface(InterfaceType element) { + return Interface._( + name: element.getDisplayString(), + humanReadable: inHumanReadable(element.getDisplayString()), + import: element.element.librarySource.uri.toString(), + ); + } + + factory Interface.fromJson(Map json) { + return Interface._( + name: json['name'], + humanReadable: json['humanReadable'], + import: json['import'], + ); + } + + Map toJson() { + return { + 'name': name, + 'humanReadable': humanReadable, + 'import': import, + }; + } +} diff --git a/packages/pine_generator/lib/src/models/seeded.dart b/packages/pine_generator/lib/src/models/seeded.dart new file mode 100644 index 0000000..7d85b8c --- /dev/null +++ b/packages/pine_generator/lib/src/models/seeded.dart @@ -0,0 +1,166 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; +import 'package:pine_generator/src/extensions/class_element.dart'; +import 'package:pine_generator/src/extensions/dart_object.dart'; +import 'package:pine_generator/src/misc/utilities.dart'; +import 'package:pine_generator/src/models/constructor.dart'; +import 'package:pine_generator/src/models/enums/injection_type.dart'; +import 'package:pine_generator/src/models/enums/seeded_type.dart'; +import 'package:pine_generator/src/models/interface.dart'; +import 'package:source_gen/source_gen.dart'; + +class Seeded { + final SeededType type; + final bool singleton; + final bool lazy; + final Interface? parent; + final String implementationName; + final String humanReadable; + final String import; + final String onInitFunctionName; + final Constructor? constructor; + final int order; + final InjectionType injection; + + const Seeded._({ + required this.type, + required this.parent, + required this.implementationName, + required this.humanReadable, + required this.singleton, + required this.lazy, + required this.injection, + required this.import, + required this.onInitFunctionName, + this.constructor, + this.order = 0, + }); + + String get constructorName => [implementationName, constructor?.name] + .where((element) => element != null) + .join('.'); + + String get injectorClassName => [ + humanReadable, + InjectionType.provider.widgetName, + ].join(); + + factory Seeded.fromAnnotation( + ClassElement element, + ConstantReader annotation, + ) { + final constructor = element.primaryConstructor; + final constructorParams = + annotation.peek('constructorParams')?.mapValue.map( + (key, value) => MapEntry( + key?.toStringValue(), + value?.toPrimitiveValue(), + ), + ) ?? + {}; + + return Seeded._( + order: constructor?.parameters.length ?? 0, + type: _guessSeededType(element.thisType), + injection: _guessInjectionType(_guessSeededType(element.thisType)), + parent: element.parent != null + ? Interface.fromInterface(element.parent!) + : null, + implementationName: element.displayName, + humanReadable: inHumanReadable(element.displayName), + import: element.librarySource.uri.toString(), + constructor: constructor != null + ? Constructor.fromClassConstructor(constructor, constructorParams) + : null, + singleton: annotation.peek('singleton')?.boolValue ?? false, + lazy: annotation.peek('lazy')?.boolValue ?? false, + onInitFunctionName: [ + 'on', + element.displayName, + 'Init', + ].join(), + ); + } + + factory Seeded.fromJson(Map json) { + return Seeded._( + order: json['order'], + type: SeededType.fromJsonValue(json['type']), + injection: InjectionType.fromJsonValue(json['injection']), + import: json['import'], + parent: + json['parent'] != null ? Interface.fromJson(json['parent']) : null, + implementationName: json['implementationName'], + humanReadable: json['humanReadable'], + singleton: json['singleton'], + lazy: json['lazy'], + constructor: json['constructor'] != null + ? Constructor.fromJson(json['constructor']) + : null, + onInitFunctionName: json['onInitFunctionName'], + ); + } + + Map toJson() { + return { + 'order': order, + 'type': type.toJsonValue(), + 'injection': injection.toJsonValue(), + 'import': import, + 'parent': parent?.toJson(), + 'implementationName': implementationName, + 'humanReadable': humanReadable, + 'singleton': singleton, + 'lazy': lazy, + 'constructor': constructor?.toJson(), + 'onInitFunctionName': onInitFunctionName, + }; + } + + static SeededType _guessSeededType(DartType type) { + final typeName = type.getDisplayString().toLowerCase(); + + if (typeName.contains('bloc')) { + return SeededType.bloc; + } else if (typeName.contains('repository')) { + return SeededType.repository; + } else if (typeName.contains('mapper')) { + return SeededType.mapper; + } + + return SeededType.generic; + } + + static InjectionType _guessInjectionType(SeededType type) => switch (type) { + SeededType.bloc => InjectionType.blocProvider, + SeededType.repository => InjectionType.repositoryProvider, + _ => InjectionType.provider, + }; +} diff --git a/packages/pine_generator/lib/src/processors/di_container_method_processor.dart b/packages/pine_generator/lib/src/processors/di_container_method_processor.dart new file mode 100644 index 0000000..71a3fc4 --- /dev/null +++ b/packages/pine_generator/lib/src/processors/di_container_method_processor.dart @@ -0,0 +1,59 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; +import 'package:pine_generator/src/processors/processor.dart'; + +class DIContainerMethodProcessor extends Processor { + @override + Method process(ProcessorContext context) { + return Method( + (b) => b + ..annotations.add( + refer('override'), + ) + ..returns = refer('Widget') + ..name = 'build' + ..requiredParameters.addAll([ + Parameter( + (b) => b + ..name = context.contextRef + ..type = refer('BuildContext'), + ), + ]) + ..body = Code( + 'return DependencyInjectorHelper(' + 'blocs: ${context.blocsRef},' + 'repositories: ${context.repositoriesRef},' + 'mappers: ${context.mappersRef},' + 'providers: ${context.providersRef},' + 'child: ${context.childWidgetRef},' + ');', + ), + ); + } +} diff --git a/packages/pine_generator/lib/src/processors/imports_processor.dart b/packages/pine_generator/lib/src/processors/imports_processor.dart new file mode 100644 index 0000000..9b7a8cc --- /dev/null +++ b/packages/pine_generator/lib/src/processors/imports_processor.dart @@ -0,0 +1,42 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; +import 'package:pine_generator/src/processors/processor.dart'; + +class ImportsProcessor extends Processor> { + @override + List process(ProcessorContext context) => [ + Directive.import('package:flutter/widgets.dart'), + Directive.import('package:pine/pine.dart'), + Directive.import('package:provider/provider.dart'), + Directive.import('package:flutter_bloc/flutter_bloc.dart'), + ...context.plants + .toSet() + .map((element) => Directive.import(element.import)), + ]; +} diff --git a/packages/pine_generator/lib/src/processors/inject_method_processor.dart b/packages/pine_generator/lib/src/processors/inject_method_processor.dart new file mode 100644 index 0000000..a111048 --- /dev/null +++ b/packages/pine_generator/lib/src/processors/inject_method_processor.dart @@ -0,0 +1,78 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; +import 'package:pine_generator/src/models/enums/injection_type.dart'; +import 'package:pine_generator/src/processors/processor.dart'; + +class InjectMethodProcessorContext extends ProcessorContext { + final String referenceName; + final InjectionType injectionType; + + InjectMethodProcessorContext({ + required this.referenceName, + required this.injectionType, + required super.plants, + }); +} + +class InjectMethodProcessor extends Processor { + @override + Method process(ProcessorContext context) { + if (context is! InjectMethodProcessorContext) { + throw ArgumentError( + 'InjectMethodProcessorContext is required to process InjectMethodProcessor', + ); + } + + return Method( + (b) => b + ..name = context.referenceName + ..lambda = true + ..type = MethodType.getter + ..returns = refer('List<${context.injectionType.widgetName}>') + ..body = literal( + context.plants + .where((plant) => plant.singleton) + .where((plant) => plant.constructor != null) + .map( + (plant) => CodeExpression( + Block.of([ + refer(plant.injectorClassName).call( + [], + { + context.onInitRef: refer(plant.onInitFunctionName), + }, + ).code, + ]), + ), + ) + .toList(growable: false), + ).code, + ); + } +} diff --git a/packages/pine_generator/lib/src/processors/injector_class_processor.dart b/packages/pine_generator/lib/src/processors/injector_class_processor.dart new file mode 100644 index 0000000..0cd1a74 --- /dev/null +++ b/packages/pine_generator/lib/src/processors/injector_class_processor.dart @@ -0,0 +1,187 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; +import 'package:pine_generator/src/misc/expressions.dart'; +import 'package:pine_generator/src/models/seeded.dart'; +import 'package:pine_generator/src/processors/processor.dart'; + +class InjectorClassProcessorContext extends ProcessorContext { + final Seeded currentPlant; + + InjectorClassProcessorContext({ + required this.currentPlant, + required super.plants, + }); +} + +class InjectorClassProcessor extends Processor { + @override + Class process(ProcessorContext context) { + if (context is! InjectorClassProcessorContext) { + throw ArgumentError( + 'InjectorClassProcessorContext is required to process InjectorClassProcessor', + ); + } + + final plant = context.currentPlant; + return Class((b) => b + ..docs.add('/// The provider for ${plant.implementationName}') + ..name = plant.injectorClassName + ..extend = refer( + plant.injection.widgetNameOf(context.currentPlant.implementationName), + ) + ..constructors.add( + Constructor( + (b) => b + ..optionalParameters.addAll( + [ + Parameter( + (b) => b + ..name = context.keyRef + ..named = true + ..toSuper = true, + ), + Parameter( + (b) => b + ..name = context.childWidgetRef + ..named = true + ..toSuper = true, + ), + Parameter( + (b) => b + ..name = context.onInitRef + ..named = true + ..type = refer( + context.onInitTypeOfRef( + plant.implementationName, + nullable: true, + ), + ), + ), + ], + ) + ..initializers.add( + Block( + (b) { + b.statements.add(Code('super(create:')); + b.statements.add(createContextClosure( + context.contextRef, + _expressionsForCreate(context, plant), + trailingComma: true, + ).code); + b.statements.add(Code('lazy: ${plant.lazy},')); + b.statements.add(Code(')')); + }, + ), + ), + ), + )); + } + + List _expressionsForCreate( + InjectorClassProcessorContext context, + Seeded plant, + ) { + final resultKey = 'result'; + final resultRef = refer(resultKey); + + return [ + declareFinal(resultKey).assign( + _fillDependency(context, plant, firstLevel: true), + ), + refer(context.onInitRef).nullSafeProperty('call').call( + [refer(context.contextRef), resultRef], + ), + resultRef.returned, + ]; + } + + Expression _fillDependency( + InjectorClassProcessorContext context, + Seeded? plant, { + bool firstLevel = false, + Object? defaultValue, + }) { + if (defaultValue != null) { + return literal(defaultValue); + } + + if (plant == null) { + return literal(null); + } + + if (!firstLevel && plant.singleton) { + return readFromContext(context.contextRef); + } + + final positionalFields = + plant.constructor!.fields.where((field) => field.positional).map( + (field) => _fillDependency( + context, + _findRelatedPlant(context, [field.type]), + defaultValue: field.value, + ), + ); + + final namedFields = plant.constructor!.fields + .where((field) => field.named) + .toList(growable: false) + .asMap() + .map( + (_, field) => MapEntry( + field.name, + _fillDependency( + context, + _findRelatedPlant( + context, + [field.type], + ), + defaultValue: field.value, + ), + ), + ); + + final isConstructorConst = plant.constructor?.isConst == true && + positionalFields.isEmpty && + namedFields.isEmpty; + final constructorConst = isConstructorConst ? 'const ' : ''; + return refer('$constructorConst${plant.constructorName}').newInstance( + positionalFields, + namedFields, + ); + } + + Seeded? _findRelatedPlant( + InjectorClassProcessorContext context, + List classNames, + ) => + classNames + .map((name) => context.namedPlants[name]) + .where((element) => element != null) + .firstOrNull; +} diff --git a/packages/pine_generator/lib/src/processors/processor.dart b/packages/pine_generator/lib/src/processors/processor.dart new file mode 100644 index 0000000..614c4d8 --- /dev/null +++ b/packages/pine_generator/lib/src/processors/processor.dart @@ -0,0 +1,73 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:pine_generator/src/models/enums/seeded_type.dart'; +import 'package:pine_generator/src/models/seeded.dart'; + +class ProcessorContext { + final Iterable plants; + + final String contextRef = 'context'; + final String childWidgetRef = 'child'; + final String keyRef = 'key'; + final String blocsRef = '_blocs'; + final String repositoriesRef = '_repositories'; + final String mappersRef = '_mappers'; + final String providersRef = '_providers'; + final String onInitRef = 'onInit'; + + const ProcessorContext({ + required this.plants, + }); + + Map get namedPlants => Map.fromEntries( + plants.expand( + (plant) => [ + MapEntry(plant.implementationName, plant), + if (plant.parent != null) MapEntry(plant.parent!.name, plant), + ], + ), + ); + + Iterable plantsOfType(SeededType type) => + plants.where((element) => element.type == type); + + Map namedPlantsOfType(SeededType type) => Map.fromEntries( + namedPlants.entries.where((element) => element.value.type == type), + ); + + String onInitTypeOfRef(String generic, {bool nullable = false}) => [ + 'OnPineSeedInit<$generic>', + if (nullable) '?', + ].join(); +} + +abstract class Processor { + const Processor(); + + T process(ProcessorContext context); +} diff --git a/packages/pine_generator/lib/src/processors/seed_container_processor.dart b/packages/pine_generator/lib/src/processors/seed_container_processor.dart new file mode 100644 index 0000000..ce345d7 --- /dev/null +++ b/packages/pine_generator/lib/src/processors/seed_container_processor.dart @@ -0,0 +1,152 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; +import 'package:pine_generator/src/models/enums/injection_type.dart'; +import 'package:pine_generator/src/models/enums/seeded_type.dart'; +import 'package:pine_generator/src/processors/inject_method_processor.dart'; +import 'package:pine_generator/src/processors/processor.dart'; + +class SeedContainerProcessorContext extends ProcessorContext { + final String containerName; + + SeedContainerProcessorContext({ + required this.containerName, + required super.plants, + }); +} + +class SeedContainerProcessor extends Processor { + final Processor diContainerMethodProcessor; + final Processor injectMethodProcessor; + + SeedContainerProcessor({ + required this.diContainerMethodProcessor, + required this.injectMethodProcessor, + }); + + @override + Class process(ProcessorContext context) { + if (context is! SeedContainerProcessorContext) { + throw ArgumentError( + 'SeedContainerProcessorContext is required to process SeedContainerProcessor', + ); + } + + final singletonPlants = context.plants.where((plant) => plant.singleton); + return Class( + (b) => b + ..name = context.containerName + ..extend = refer('StatelessWidget') + ..fields.addAll([ + Field( + (b) => b + ..name = context.childWidgetRef + ..modifier = FieldModifier.final$ + ..type = refer('Widget'), + ), + ...singletonPlants.map( + (plant) => Field( + (b) => b + ..name = plant.onInitFunctionName + ..modifier = FieldModifier.final$ + ..type = refer( + context.onInitTypeOfRef( + plant.implementationName, + nullable: true, + ), + ), + ), + ), + ]) + ..constructors.add( + Constructor( + (b) => b + ..constant = true + ..optionalParameters.addAll([ + Parameter( + (b) => b + ..name = context.keyRef + ..named = true + ..toSuper = true, + ), + Parameter( + (b) => b + ..name = context.childWidgetRef + ..named = true + ..toThis = true + ..required = true, + ), + ...singletonPlants.map( + (plant) => Parameter( + (b) => b + ..name = plant.onInitFunctionName + ..named = true + ..toThis = true, + ), + ), + ]), + ), + ) + ..methods.addAll( + [ + diContainerMethodProcessor.process(context), + ...[ + ( + context.blocsRef, + InjectionType.blocProvider, + context.plantsOfType(SeededType.bloc), + ), + ( + context.repositoriesRef, + InjectionType.repositoryProvider, + context.plantsOfType(SeededType.repository), + ), + ( + context.mappersRef, + InjectionType.provider, + context.plantsOfType(SeededType.mapper), + ), + ( + context.providersRef, + InjectionType.provider, + context.plantsOfType(SeededType.generic), + ), + ].map( + (e) => injectMethodProcessor.process( + InjectMethodProcessorContext( + referenceName: e.$1, + injectionType: e.$2, + plants: e.$3, + ), + ), + ), + ], + ), + ); + } +} diff --git a/packages/pine_generator/lib/src/processors/typedefs_processor.dart b/packages/pine_generator/lib/src/processors/typedefs_processor.dart new file mode 100644 index 0000000..ae9e843 --- /dev/null +++ b/packages/pine_generator/lib/src/processors/typedefs_processor.dart @@ -0,0 +1,40 @@ +/* + * + * * Copyright (c) 2024 MyLittleSuite + * * + * * Permission is hereby granted, free of charge, to any person + * * obtaining a copy of this software and associated documentation + * * files (the "Software"), to deal in the Software without + * * restriction, including without limitation the rights to use, + * * copy, modify, merge, publish, distribute, sublicense, and/or sell + * * copies of the Software, and to permit persons to whom the + * * Software is furnished to do so, subject to the following + * * conditions: + * * + * * The above copyright notice and this permission notice shall be + * * included in all copies or substantial portions of the Software. + * * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +import 'package:code_builder/code_builder.dart'; +import 'package:pine_generator/src/processors/processor.dart'; + +class TypedefsProcessor extends Processor> { + @override + List process(ProcessorContext context) => [ + CodeExpression( + Code( + 'typedef ${context.onInitTypeOfRef('T')} = void Function(BuildContext context, T value);', + ), + ), + ]; +} diff --git a/packages/pine_generator/pubspec.yaml b/packages/pine_generator/pubspec.yaml new file mode 100644 index 0000000..d94e0f1 --- /dev/null +++ b/packages/pine_generator/pubspec.yaml @@ -0,0 +1,24 @@ +name: pine_generator +description: A lightweight architecture helper for your Flutter projects. +version: 2.0.0 +repository: https://github.com/MyLittleSuite/pine +issue_tracker: https://github.com/MyLittleSuite/pine/issues +homepage: https://www.mylittlesuite.com + +environment: + sdk: ">=3.0.0 <4.0.0" + +# Add regular dependencies here. +dependencies: + analyzer: ^6.5.0 + build: ^2.4.1 + code_builder: ^4.10.0 + source_gen: ^1.5.0 + dart_style: ^2.3.4 + pine_annotations: ^2.0.0 + glob: ^2.1.2 + +dev_dependencies: + lints: ^4.0.0 + test: ^1.24.0 + source_gen_test: ^1.0.6 diff --git a/packages/pine_generator/pubspec_overrides.yaml b/packages/pine_generator/pubspec_overrides.yaml new file mode 100644 index 0000000..44a5b75 --- /dev/null +++ b/packages/pine_generator/pubspec_overrides.yaml @@ -0,0 +1,3 @@ +dependency_overrides: + pine_annotations: + path: ../pine_annotations diff --git a/packages/pine_generator/test/pine_generator_test.dart b/packages/pine_generator/test/pine_generator_test.dart new file mode 100644 index 0000000..1c05771 --- /dev/null +++ b/packages/pine_generator/test/pine_generator_test.dart @@ -0,0 +1,15 @@ +import 'package:test/test.dart'; + +void main() { + group('A group of tests', () { + final awesome = true; + + setUp(() { + // Additional setup goes here. + }); + + test('First Test', () { + expect(awesome, isTrue); + }); + }); +}