From 25cfb881560a699ab9110077e4b5a61aeed2432e Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Tue, 24 Oct 2023 20:47:51 +0400 Subject: [PATCH] Add do not generate timestamp options --- .github/dependabot.yaml | 10 +++++ .vscode/extensions.json | 5 +++ .vscode/launch.json | 11 ++++++ .vscode/settings.json | 39 +++++++++++++++++++ .vscode/tasks.json | 17 ++++++++ CHANGELOG.md | 6 +++ analysis_options.yaml | 15 ++----- build.yaml | 1 + example/example.dart | 26 +++++++------ lib/src/generator/class_generator_mixin.dart | 2 +- lib/src/generator/pubspec_generator.dart | 8 +++- lib/src/generator/pubspec_generator_impl.dart | 3 +- .../generator/timestamp_generator_mixin.dart | 30 +++++++------- lib/src/generator/topics_generator_mixin.dart | 4 +- lib/src/pubspec_builder.dart | 3 +- lib/src/pubspec_builder_config.dart | 26 +++++++++++-- pubspec.yaml | 2 +- tool/runner.dart | 5 ++- 18 files changed, 163 insertions(+), 50 deletions(-) create mode 100644 .github/dependabot.yaml create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..ec843bf --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,10 @@ +version: 2 +enable-beta-ecosystems: true +updates: + - directory: "/" + open-pull-requests-limit: 5 + package-ecosystem: "pub" + rebase-strategy: auto + schedule: + interval: "monthly" + timezone: "UTC" \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..a368654 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "dart-code.dart-code" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d4565db --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Example", + "request": "launch", + "type": "dart", + "program": "tool/runner.dart", + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..161449b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,39 @@ +{ + "[dart]": { + "editor.selectionHighlight": false, + "editor.suggest.snippetsPreventQuickSuggestions": false, + "editor.suggestSelection": "first", + "editor.tabCompletion": "onlySnippets", + "editor.wordBasedSuggestions": false, + "editor.rulers": [80], + "editor.defaultFormatter": "Dart-Code.dart-code", + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + //"editor.formatOnType" : true, + "editor.insertSpaces": true + }, + "dart.lineLength": 80, + "dart.doNotFormat": ["**.g.dart", "**.mocks.dart"], + "search.exclude": { + ".dart_tool": true, + "coverage": true, + "build": true + }, + "files.watcherExclude": { + ".dart_tool": true, + "coverage": true, + "build": true + }, + "debug.openDebug": "openOnDebugBreak", + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.expand": false, + "explorer.fileNesting.patterns": { + "pubspec.yaml": ".packages, .metadata, .packages, pubspec.lock, *.yaml", + ".gitignore": ".gitattributes, .gitmodules, .gitmessage, .mailmap, .git-blame*, .dockerignore", + "readme.*": "authors, backers.md, changelog*, citation*, code_of_conduct.md, codeowners, contributing.md, contributors, copying, credits, governance.md, history.md, license*, maintainers, readme*, security.md, sponsors.md", + "*.dart": "$(capture).g.dart, $(capture).i.dart, $(capture).stub.dart, $(capture).web.dart, $(capture).html.dart, $(capture).js.dart, $(capture).io.dart, $(capture).base.dart" + }, + "files.associations": { + "*.drift": "sql" + } +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4ddd098 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Dependencies", + "type": "shell", + "command": [ + "dart pub get" + ], + "group": { + "kind": "none", + "isDefault": true + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3efdd57..530eb76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.1.0-pre.1 - 2023-10-24 + +# Added + +- Disable timestamp generation option + ## 4.0.0 - 2023-07-03 ### Changed diff --git a/analysis_options.yaml b/analysis_options.yaml index 368399b..507d24c 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,7 +1,3 @@ -# Customizing static analysis -# https://dart.dev/guides/language/analysis-options/ -# https://dart-lang.github.io/linter/lints/ - include: package:lints/recommended.yaml analyzer: @@ -22,12 +18,10 @@ analyzer: strict-raw-types: true strict-inference: true - #enable-experiment: - # - non-nullable - errors: + todo: ignore + # Info - todo: info directives_ordering: info always_declare_return_types: info @@ -59,7 +53,6 @@ linter: prefer_relative_imports: false prefer_final_locals: false avoid_escaping_inner_quotes: false - avoid_classes_with_only_static_members: false # Enabled always_put_required_named_parameters_first: true @@ -84,10 +77,9 @@ linter: close_sinks: true control_flow_in_finally: true empty_statements: true - iterable_contains_unrelated_type: true + collection_methods_unrelated_type: true join_return_with_assignment: true leading_newlines_in_multiline_strings: true - list_remove_unrelated_type: true literal_only_boolean_expressions: true missing_whitespace_between_adjacent_strings: true no_adjacent_strings_in_list: true @@ -197,6 +189,7 @@ linter: avoid_catching_errors: true use_to_and_as_if_applicable: true one_member_abstracts: true + avoid_classes_with_only_static_members: true prefer_mixin: true use_setters_to_change_properties: true avoid_setters_without_getters: true diff --git a/build.yaml b/build.yaml index 7a20d04..960a5dc 100644 --- a/build.yaml +++ b/build.yaml @@ -8,6 +8,7 @@ targets: builders: pubspec_generator: options: + timestamp: true output: lib/src/constants/pubspec.yaml.g.dart builders: diff --git a/example/example.dart b/example/example.dart index 1483d50..21ddb7c 100644 --- a/example/example.dart +++ b/example/example.dart @@ -93,13 +93,13 @@ sealed class Pubspec { static const PubspecVersion version = ( /// Non-canonical string representation of the version as provided /// in the pubspec.yaml file. - representation: r'4.0.0', + representation: r'4.1.0-pre.1', /// Returns a 'canonicalized' representation /// of the application version. /// This represents the version string in accordance with /// Semantic Versioning (SemVer) standards. - canonical: r'4.0.0', + canonical: r'4.1.0-pre.1', /// MAJOR version when you make incompatible API changes. /// The major version number: 1 in "1.2.3". @@ -108,14 +108,14 @@ sealed class Pubspec { /// MINOR version when you add functionality /// in a backward compatible manner. /// The minor version number: 2 in "1.2.3". - minor: 0, + minor: 1, /// PATCH version when you make backward compatible bug fixes. /// The patch version number: 3 in "1.2.3". patch: 0, /// The pre-release identifier: "foo" in "1.2.3-foo". - preRelease: [], + preRelease: [r'pre', r'1'], /// The build identifier: "foo" in "1.2.3+foo". build: [], @@ -124,13 +124,13 @@ sealed class Pubspec { /// Build date and time (UTC) static final DateTime timestamp = DateTime.utc( 2023, - 7, - 3, - 9, - 49, - 54, - 100, - 370, + 10, + 24, + 16, + 45, + 28, + 717, + 914, ); /// Name @@ -330,7 +330,9 @@ sealed class Pubspec { /// /// Current app [topics] /// - /// Package authors can use the topics field to categorize their package. Topics can be used to assist discoverability during search with filters on pub.dev. Pub.dev displays the topics on the package page as well as in the search results. + /// Package authors can use the topics field to categorize their package. + /// Topics can be used to assist discoverability during search with filters on pub.dev. + /// Pub.dev displays the topics on the package page as well as in the search results. /// /// The field consists of a list of names. For example: /// diff --git a/lib/src/generator/class_generator_mixin.dart b/lib/src/generator/class_generator_mixin.dart index 1bdd861..31edf18 100644 --- a/lib/src/generator/class_generator_mixin.dart +++ b/lib/src/generator/class_generator_mixin.dart @@ -9,7 +9,7 @@ mixin ClassGeneratorMixin on PubspecGenerator { yield _$classDescription; yield 'sealed class Pubspec {'; yield* super.generate(pubspec).map(_padding); - yield '}'; + yield '}\n'; } String _padding(String text) => text diff --git a/lib/src/generator/pubspec_generator.dart b/lib/src/generator/pubspec_generator.dart index 60ecb49..2d106bb 100644 --- a/lib/src/generator/pubspec_generator.dart +++ b/lib/src/generator/pubspec_generator.dart @@ -1,9 +1,15 @@ +import 'package:pubspec_generator/src/pubspec_builder_config.dart'; + /// {@nodoc} /// @immutable // ignore: one_member_abstracts abstract class PubspecGenerator { /// {@nodoc} - const PubspecGenerator(); + const PubspecGenerator({required this.config}); + + /// Configuration for builder + /// {@nodoc} + final PubspecBuilderConfig config; /// {@nodoc} /// @mustCallSuper diff --git a/lib/src/generator/pubspec_generator_impl.dart b/lib/src/generator/pubspec_generator_impl.dart index 9148695..394b6b2 100644 --- a/lib/src/generator/pubspec_generator_impl.dart +++ b/lib/src/generator/pubspec_generator_impl.dart @@ -40,6 +40,5 @@ class PubspecGeneratorImpl extends PubspecGenerator HeaderGeneratorMixin, IgnoreGeneratorMixin { /// {@nodoc} - /// @literal - const PubspecGeneratorImpl() : super(); + const PubspecGeneratorImpl({required super.config}); } diff --git a/lib/src/generator/timestamp_generator_mixin.dart b/lib/src/generator/timestamp_generator_mixin.dart index 28418c6..ebe28f8 100644 --- a/lib/src/generator/timestamp_generator_mixin.dart +++ b/lib/src/generator/timestamp_generator_mixin.dart @@ -6,20 +6,22 @@ import 'package:pubspec_generator/src/generator/pubspec_generator.dart'; mixin TimestampGeneratorMixin on PubspecGenerator { @override Iterable generate(Map pubspec) sync* { - final now = DateTime.now().toUtc(); - final builder = StringBuffer() - ..writeln('/// Build date and time (UTC)') - ..writeln('static final DateTime timestamp = DateTime.utc(') - ..writeln(' ${now.year},') - ..writeln(' ${now.month},') - ..writeln(' ${now.day},') - ..writeln(' ${now.hour},') - ..writeln(' ${now.minute},') - ..writeln(' ${now.second},') - ..writeln(' ${now.millisecond},') - ..writeln(' ${now.microsecond},') - ..writeln(');'); - yield builder.toString(); + if (config.timestamp) { + final now = DateTime.now().toUtc(); + final builder = StringBuffer() + ..writeln('/// Build date and time (UTC)') + ..writeln('static final DateTime timestamp = DateTime.utc(') + ..writeln(' ${now.year},') + ..writeln(' ${now.month},') + ..writeln(' ${now.day},') + ..writeln(' ${now.hour},') + ..writeln(' ${now.minute},') + ..writeln(' ${now.second},') + ..writeln(' ${now.millisecond},') + ..writeln(' ${now.microsecond},') + ..writeln(');'); + yield builder.toString(); + } yield* super.generate(pubspec); } } diff --git a/lib/src/generator/topics_generator_mixin.dart b/lib/src/generator/topics_generator_mixin.dart index e2436e7..10924dd 100644 --- a/lib/src/generator/topics_generator_mixin.dart +++ b/lib/src/generator/topics_generator_mixin.dart @@ -27,7 +27,9 @@ const String _$topicsDescription = ''' /// /// Current app [topics] /// -/// Package authors can use the topics field to categorize their package. Topics can be used to assist discoverability during search with filters on pub.dev. Pub.dev displays the topics on the package page as well as in the search results. +/// Package authors can use the topics field to categorize their package. +/// Topics can be used to assist discoverability during search with filters on pub.dev. +/// Pub.dev displays the topics on the package page as well as in the search results. /// /// The field consists of a list of names. For example: /// diff --git a/lib/src/pubspec_builder.dart b/lib/src/pubspec_builder.dart index c7344c8..5087edb 100644 --- a/lib/src/pubspec_builder.dart +++ b/lib/src/pubspec_builder.dart @@ -1,7 +1,6 @@ // ignore_for_file: avoid_escaping_inner_quotes, avoid_annotating_with_dynamic import 'package:build/build.dart'; - import 'package:pubspec_generator/src/generator/pubspec_generator.dart'; import 'package:pubspec_generator/src/generator/pubspec_generator_impl.dart'; import 'package:pubspec_generator/src/parser/pubspec_parser.dart'; @@ -30,7 +29,7 @@ abstract class PubspecBuilder implements Builder { /// PubspecBuilder constructor with BuilderOptions PubspecBuilder(this.config) : pubspecParser = const PubspecParserImpl(), - pubspecGenerator = const PubspecGeneratorImpl(), + pubspecGenerator = PubspecGeneratorImpl(config: config), buildExtensions = >{ 'pubspec.yaml': [config.output], }; diff --git a/lib/src/pubspec_builder_config.dart b/lib/src/pubspec_builder_config.dart index 3ed99be..6980374 100644 --- a/lib/src/pubspec_builder_config.dart +++ b/lib/src/pubspec_builder_config.dart @@ -1,19 +1,37 @@ import 'package:build/build.dart' show BuilderOptions; /// Builder config -// @immutable +/// @immutable +/// @internal +/// {@nodoc} class PubspecBuilderConfig { + /// Generate timestamp in output file + /// {@nodoc} + final bool timestamp; + + /// Output path for generated file /// {@nodoc} final String output; /// {@nodoc} PubspecBuilderConfig.fromBuilderOptions(BuilderOptions options) - : output = (options.config['output'] as String?) ?? - 'lib/src/constants/pubspec.yaml.g.dart'; + : output = options.config['output']?.toString() ?? + 'lib/src/constants/pubspec.yaml.g.dart', + timestamp = switch (options.config['timestamp']) { + String value => switch (value.trim().toLowerCase()) { + 'false' || 'no' || 'n' || 'f' || '-' || '0' => false, + _ => true, + }, + bool value => value, + int value => value > 0, + _ => true, + }; @override String toString() => (StringBuffer() ..write('Output path: ') - ..writeln(output)) + ..writeln(output) + ..write('Timestamp: ') + ..writeln(timestamp ? 'enabled' : 'disabled')) .toString(); } diff --git a/pubspec.yaml b/pubspec.yaml index 2038321..f36df5e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: > Code generator pubspec.yaml.g.dart from pubspec.yaml. Just import `pubspec_generator` and then run `dart run build_runner build` -version: 4.0.0 +version: 4.1.0-pre.1 repository: https://github.com/PlugFox/pubspec_generator/tree/master diff --git a/tool/runner.dart b/tool/runner.dart index 594bb89..a47d962 100644 --- a/tool/runner.dart +++ b/tool/runner.dart @@ -23,7 +23,10 @@ void main(List args) => runZoned( core.toRoot(), hideOutput: false, defaultDevOptions: const build.BuilderOptions( - {'output': 'example/example.dart'}, + { + 'output': 'example/example.dart', + 'timestamp': 'true', + }, isRoot: true, ), ),