From b02524700245c1f7dbca16cf22d685817416a5c5 Mon Sep 17 00:00:00 2001 From: AN12345 Date: Mon, 6 Feb 2023 18:41:54 +0100 Subject: [PATCH] feat: add class annotation for component code generators --- mason.yaml | 10 +-- .../.gitignore | 7 ++ .../.vscode/extensions.json | 24 +++++++ .../.vscode/launch.json | 34 +++++++++ .../.vscode/settings.json | 72 +++++++++++++++++++ .../CHANGELOG.md | 3 + .../README.md | 66 +++++++++++++++++ .../analysis_options.yaml | 7 ++ .../example/.gitignore | 44 ++++++++++++ .../example/.metadata | 30 ++++++++ .../example/README.md | 16 +++++ .../example/analysis_options.yaml | 7 ++ .../example/lib/main.dart | 29 ++++++++ .../example/pubspec.yaml | 27 +++++++ .../lib/component_copy_with_extension.dart | 22 ++++++ .../src/component_copy_with_extension.dart | 25 +++++++ .../lib/src/component_proxy_extension.dart | 25 +++++++ .../lib/src/domain/component_annotation.dart | 24 +++++++ .../lib/src/domain/domain.dart | 17 +++++ .../pubspec.yaml | 20 ++++++ 20 files changed, 504 insertions(+), 5 deletions(-) create mode 100644 packages/wyatt_component_copy_with_extension/.gitignore create mode 100644 packages/wyatt_component_copy_with_extension/.vscode/extensions.json create mode 100644 packages/wyatt_component_copy_with_extension/.vscode/launch.json create mode 100644 packages/wyatt_component_copy_with_extension/.vscode/settings.json create mode 100644 packages/wyatt_component_copy_with_extension/CHANGELOG.md create mode 100644 packages/wyatt_component_copy_with_extension/README.md create mode 100644 packages/wyatt_component_copy_with_extension/analysis_options.yaml create mode 100644 packages/wyatt_component_copy_with_extension/example/.gitignore create mode 100644 packages/wyatt_component_copy_with_extension/example/.metadata create mode 100644 packages/wyatt_component_copy_with_extension/example/README.md create mode 100644 packages/wyatt_component_copy_with_extension/example/analysis_options.yaml create mode 100644 packages/wyatt_component_copy_with_extension/example/lib/main.dart create mode 100644 packages/wyatt_component_copy_with_extension/example/pubspec.yaml create mode 100644 packages/wyatt_component_copy_with_extension/lib/component_copy_with_extension.dart create mode 100644 packages/wyatt_component_copy_with_extension/lib/src/component_copy_with_extension.dart create mode 100644 packages/wyatt_component_copy_with_extension/lib/src/component_proxy_extension.dart create mode 100644 packages/wyatt_component_copy_with_extension/lib/src/domain/component_annotation.dart create mode 100644 packages/wyatt_component_copy_with_extension/lib/src/domain/domain.dart create mode 100644 packages/wyatt_component_copy_with_extension/pubspec.yaml diff --git a/mason.yaml b/mason.yaml index c9c22317..e0e797ee 100644 --- a/mason.yaml +++ b/mason.yaml @@ -1,13 +1,13 @@ bricks: wyatt_clean_code: git: - url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git + url: "ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git" path: bricks/wyatt_clean_code wyatt_feature_brick: git: - url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git + url: "ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git" path: bricks/wyatt_feature_brick - wyatt_package: + wyatt_package_template: git: - url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git - path: bricks/wyatt_package \ No newline at end of file + url: "ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git" + path: bricks/wyatt_package_template \ No newline at end of file diff --git a/packages/wyatt_component_copy_with_extension/.gitignore b/packages/wyatt_component_copy_with_extension/.gitignore new file mode 100644 index 00000000..3cceda55 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/.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/wyatt_component_copy_with_extension/.vscode/extensions.json b/packages/wyatt_component_copy_with_extension/.vscode/extensions.json new file mode 100644 index 00000000..30cd2233 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/.vscode/extensions.json @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 WYATT GROUP + * Please see the AUTHORS file for details. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +{ + "recommendations": [ + "psioniq.psi-header", + "blaugold.melos-code" + ] +} \ No newline at end of file diff --git a/packages/wyatt_component_copy_with_extension/.vscode/launch.json b/packages/wyatt_component_copy_with_extension/.vscode/launch.json new file mode 100644 index 00000000..653eabc8 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/.vscode/launch.json @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 WYATT GROUP + * Please see the AUTHORS file for details. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Example", + "request": "launch", + "type": "dart", + "cwd": "example/", + "program": "lib/main.dart", + "flutterMode": "debug" + }, + ] +} \ No newline at end of file diff --git a/packages/wyatt_component_copy_with_extension/.vscode/settings.json b/packages/wyatt_component_copy_with_extension/.vscode/settings.json new file mode 100644 index 00000000..a729c46c --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/.vscode/settings.json @@ -0,0 +1,72 @@ +{ + "dart.runPubGetOnPubspecChanges": "never", + "bloc.newCubitTemplate.type": "equatable", + "psi-header.changes-tracking": { + "isActive": true + }, + "psi-header.config": { + "blankLinesAfter": 1, + "forceToTop": true + }, + "psi-header.lang-config": [ + { + "beforeHeader": [ + "# -*- coding:utf-8 -*-", + "#!/usr/bin/env python3" + ], + "begin": "###", + "end": "###", + "language": "python", + "prefix": "# " + }, + { + "beforeHeader": [ + "#!/usr/bin/env sh", + "" + ], + "language": "shellscript", + "begin": "", + "end": "", + "prefix": "# " + }, + { + "begin": "", + "end": "", + "language": "dart", + "prefix": "// " + }, + { + "begin": "", + "end": "", + "language": "yaml", + "prefix": "# " + }, + { + "begin": "", + "language": "markdown", + }, + ], + "psi-header.templates": [ + { + "language": "*", + "template": [ + "Copyright (C) <> WYATT GROUP", + "Please see the AUTHORS file for details.", + "", + "This program is free software: you can redistribute it and/or modify", + "it under the terms of the GNU General Public License as published by", + "the Free Software Foundation, either version 3 of the License, or", + "any later version.", + "", + "This program is distributed in the hope that it will be useful,", + "but WITHOUT ANY WARRANTY; without even the implied warranty of", + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", + "GNU General Public License for more details.", + "", + "You should have received a copy of the GNU General Public License", + "along with this program. If not, see ." + ], + } + ], +} \ No newline at end of file diff --git a/packages/wyatt_component_copy_with_extension/CHANGELOG.md b/packages/wyatt_component_copy_with_extension/CHANGELOG.md new file mode 100644 index 00000000..effe43c8 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/packages/wyatt_component_copy_with_extension/README.md b/packages/wyatt_component_copy_with_extension/README.md new file mode 100644 index 00000000..3ef1d24d --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/README.md @@ -0,0 +1,66 @@ + + +# Flutter - Component Copy With Extension + +

+ Style: Wyatt Analysis + SDK: Flutter +

+ +This package provides annotations for generating code and simplifying the use of an UI kit within a Flutter application. **The package contains only the annotation classes**. + +## Annotation Classes + +#### `ComponentProxyExtension` + +This annotation class is used to annotate a new component of an UI kit in the `wyatt_ui_components` package. It generates the abstract proxy of the component and allows access to all its properties in different packages and throughout the application. + +```dart +part 'text_field_component.g.dart'; + +@ComponentProxyExtension() +abstract class TextFieldComponent extends Component { + with CopyWithMixin<$TextFieldComponentCWProxy> { + + const TextFieldComponent({ + ... + }); +} +``` + +#### `ComponentCopyWithExtension` + +This annotation class is used to annotate the implementation of components directly in the application. It generates the implementation of the proxy and the mixin to ensure that the component meets the specifications defined in the `wyatt_ui_components package`. + +```dart +part 'text_field_component.g.dart'; + +@ComponentProxyExtension() +abstract class TextFieldComponent extends Component { + with CopyWithMixin<$TextFieldComponentCWProxy> { + + const TextFieldComponent({ + ... + }); +} +``` + +## Additional features + +The skipFields field allows you to directly and specifically change a field. This makes it easier to use. You can disable it through annotation. diff --git a/packages/wyatt_component_copy_with_extension/analysis_options.yaml b/packages/wyatt_component_copy_with_extension/analysis_options.yaml new file mode 100644 index 00000000..0939257e --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/analysis_options.yaml @@ -0,0 +1,7 @@ + +include: package:wyatt_analysis/analysis_options.flutter.yaml + + + + + diff --git a/packages/wyatt_component_copy_with_extension/example/.gitignore b/packages/wyatt_component_copy_with_extension/example/.gitignore new file mode 100644 index 00000000..24476c5d --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/example/.gitignore @@ -0,0 +1,44 @@ +# 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 +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/packages/wyatt_component_copy_with_extension/example/.metadata b/packages/wyatt_component_copy_with_extension/example/.metadata new file mode 100644 index 00000000..30e0d3ce --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/example/.metadata @@ -0,0 +1,30 @@ +# 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. + +version: + revision: b06b8b2710955028a6b562f5aa6fe62941d6febf + channel: stable + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf + base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf + - platform: web + create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf + base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/wyatt_component_copy_with_extension/example/README.md b/packages/wyatt_component_copy_with_extension/example/README.md new file mode 100644 index 00000000..2b3fce4c --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/example/README.md @@ -0,0 +1,16 @@ +# example + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/wyatt_component_copy_with_extension/example/analysis_options.yaml b/packages/wyatt_component_copy_with_extension/example/analysis_options.yaml new file mode 100644 index 00000000..0939257e --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/example/analysis_options.yaml @@ -0,0 +1,7 @@ + +include: package:wyatt_analysis/analysis_options.flutter.yaml + + + + + diff --git a/packages/wyatt_component_copy_with_extension/example/lib/main.dart b/packages/wyatt_component_copy_with_extension/example/lib/main.dart new file mode 100644 index 00000000..f728d06c --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/example/lib/main.dart @@ -0,0 +1,29 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; + +@ComponentProxyExtension() +class BasicComponentAnnotationExemple {} + +@ComponentProxyExtension(skipFields: true) +class ComponentAnnotationExempleWithSkipFields {} + +@ComponentCopyWithExtension() +class BasicCustomComponent {} + +@ComponentCopyWithExtension(skipFields: false) +class CustomComponentAnnotationExempleWithSkipFields {} diff --git a/packages/wyatt_component_copy_with_extension/example/pubspec.yaml b/packages/wyatt_component_copy_with_extension/example/pubspec.yaml new file mode 100644 index 00000000..5f2cafd0 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/example/pubspec.yaml @@ -0,0 +1,27 @@ +name: component_copy_with_extension_example +description: A new Flutter project. +version: 1.0.0 + +publish_to: "none" + +environment: + sdk: ">=2.19.0 <3.0.0" + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + wyatt_component_copy_with_extension: + path: "../" + +dev_dependencies: + flutter_test: + sdk: flutter + + wyatt_analysis: + hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub + version: ^2.3.0 + +# The following section is specific to Flutter. +flutter: + uses-material-design: true diff --git a/packages/wyatt_component_copy_with_extension/lib/component_copy_with_extension.dart b/packages/wyatt_component_copy_with_extension/lib/component_copy_with_extension.dart new file mode 100644 index 00000000..9ba9c518 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/lib/component_copy_with_extension.dart @@ -0,0 +1,22 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +/// Extension for component copy with feature +library component_copy_with_extension; + +export './src/domain/domain.dart'; +export 'src/component_copy_with_extension.dart'; +export 'src/component_proxy_extension.dart'; diff --git a/packages/wyatt_component_copy_with_extension/lib/src/component_copy_with_extension.dart b/packages/wyatt_component_copy_with_extension/lib/src/component_copy_with_extension.dart new file mode 100644 index 00000000..482b1748 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/lib/src/component_copy_with_extension.dart @@ -0,0 +1,25 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:meta/meta_meta.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; + +/// Annotation used to indicate that the `copyWith` extension +/// should be generated for the compononent. +@Target({TargetKind.classType}) +class ComponentCopyWithExtension extends ComponentAnnotation { + const ComponentCopyWithExtension({super.skipFields}); +} diff --git a/packages/wyatt_component_copy_with_extension/lib/src/component_proxy_extension.dart b/packages/wyatt_component_copy_with_extension/lib/src/component_proxy_extension.dart new file mode 100644 index 00000000..3e75eef5 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/lib/src/component_proxy_extension.dart @@ -0,0 +1,25 @@ +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:meta/meta_meta.dart'; + +@Target({TargetKind.classType}) +class ComponentProxyExtension { + const ComponentProxyExtension({ + this.skipFields = true, + }); + + final bool? skipFields; +} diff --git a/packages/wyatt_component_copy_with_extension/lib/src/domain/component_annotation.dart b/packages/wyatt_component_copy_with_extension/lib/src/domain/component_annotation.dart new file mode 100644 index 00000000..1faf6119 --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/lib/src/domain/component_annotation.dart @@ -0,0 +1,24 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +abstract class ComponentAnnotation { + const ComponentAnnotation({this.skipFields = true}); + + /// Prevent the library from generating `copyWith` functions for individual + /// fields e.g. `instance.copyWith.id("123")`. If you want to use only + /// copyWith(...) function. Default is `true`. + final bool? skipFields; +} diff --git a/packages/wyatt_component_copy_with_extension/lib/src/domain/domain.dart b/packages/wyatt_component_copy_with_extension/lib/src/domain/domain.dart new file mode 100644 index 00000000..c06b052c --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/lib/src/domain/domain.dart @@ -0,0 +1,17 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +export './component_annotation.dart'; diff --git a/packages/wyatt_component_copy_with_extension/pubspec.yaml b/packages/wyatt_component_copy_with_extension/pubspec.yaml new file mode 100644 index 00000000..9d4c06bd --- /dev/null +++ b/packages/wyatt_component_copy_with_extension/pubspec.yaml @@ -0,0 +1,20 @@ +name: wyatt_component_copy_with_extension +description: Extension for component copy with feature. +repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/component_copy_with_extension +version: 1.0.0 + +environment: + sdk: ">=2.19.0 <3.0.0" + +dependencies: + meta: ^1.8.0 + path: ^1.8.0 + +dev_dependencies: + wyatt_analysis: + hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub + version: ^2.3.0 + +# The following section is specific to Flutter. +flutter: + uses-material-design: true