Skip to content

Commit

Permalink
Add do not generate timestamp options
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Oct 24, 2023
1 parent 67433e8 commit 25cfb88
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 50 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dart-code.dart-code"
]
}
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"request": "launch",
"type": "dart",
"program": "tool/runner.dart",
}
]
}
39 changes: 39 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Dependencies",
"type": "shell",
"command": [
"dart pub get"
],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
}
]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 4.1.0-pre.1 - 2023-10-24

# Added

- Disable timestamp generation option

## 4.0.0 - 2023-07-03

### Changed
Expand Down
15 changes: 4 additions & 11 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ targets:
builders:
pubspec_generator:
options:
timestamp: true
output: lib/src/constants/pubspec.yaml.g.dart

builders:
Expand Down
26 changes: 14 additions & 12 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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: <String>[],
preRelease: <String>[r'pre', r'1'],

/// The build identifier: "foo" in "1.2.3+foo".
build: <String>[],
Expand All @@ -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
Expand Down Expand Up @@ -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:
///
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generator/class_generator_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mixin ClassGeneratorMixin on PubspecGenerator {
yield _$classDescription;
yield 'sealed class Pubspec {';
yield* super.generate(pubspec).map<String>(_padding);
yield '}';
yield '}\n';
}

String _padding(String text) => text
Expand Down
8 changes: 7 additions & 1 deletion lib/src/generator/pubspec_generator.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/src/generator/pubspec_generator_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ class PubspecGeneratorImpl extends PubspecGenerator
HeaderGeneratorMixin,
IgnoreGeneratorMixin {
/// {@nodoc}
/// @literal
const PubspecGeneratorImpl() : super();
const PubspecGeneratorImpl({required super.config});
}
30 changes: 16 additions & 14 deletions lib/src/generator/timestamp_generator_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import 'package:pubspec_generator/src/generator/pubspec_generator.dart';
mixin TimestampGeneratorMixin on PubspecGenerator {
@override
Iterable<String> generate(Map<String, Object> 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);
}
}
4 changes: 3 additions & 1 deletion lib/src/generator/topics_generator_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down
3 changes: 1 addition & 2 deletions lib/src/pubspec_builder.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = <String, List<String>>{
'pubspec.yaml': <String>[config.output],
};
Expand Down
26 changes: 22 additions & 4 deletions lib/src/pubspec_builder_config.dart
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion tool/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ void main(List<String> args) => runZoned(
core.toRoot(),
hideOutput: false,
defaultDevOptions: const build.BuilderOptions(
<String, dynamic>{'output': 'example/example.dart'},
<String, dynamic>{
'output': 'example/example.dart',
'timestamp': 'true',
},
isRoot: true,
),
),
Expand Down

0 comments on commit 25cfb88

Please sign in to comment.