Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ linter:
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
- always_require_non_null_named_parameters
# - always_require_non_null_named_parameters
# - always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # not yet tested
Expand Down Expand Up @@ -82,12 +82,12 @@ linter:
- hash_and_equals
- implementation_imports
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
- iterable_contains_unrelated_type
# - iterable_contains_unrelated_type
# - join_return_with_assignment # not yet tested
- library_names
- library_prefixes
# - lines_longer_than_80_chars # not yet tested
- list_remove_unrelated_type
# - list_remove_unrelated_type
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
- no_adjacent_strings_in_list
- no_duplicate_case_values
Expand All @@ -113,7 +113,7 @@ linter:
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
# - prefer_double_quotes # opposite of prefer_single_quotes
- prefer_equal_for_default_values
# - prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
- prefer_final_fields
- prefer_final_in_for_each
Expand Down
10 changes: 5 additions & 5 deletions bin/frameit_chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Future<void> main(List<String> args) async {
defaultsTo: '2');
final result = parser.parse(args);

final baseDir = result[ARG_BASE_DIR] as String;
final framesDir = result[ARG_FRAMES_DIR] as String;
final chromeBinary = result[ARG_CHROME_BINARY] as String;
final baseDir = result[ARG_BASE_DIR] as String?;
final framesDir = result[ARG_FRAMES_DIR] as String?;
final chromeBinary = result[ARG_CHROME_BINARY] as String?;
final pixelRatio = double.tryParse(result[ARG_PIXEL_RATIO].toString());
if (baseDir == null ||
framesDir == null ||
Expand Down Expand Up @@ -134,7 +134,7 @@ Future<void> runFrame(String baseDir, String framesDirPath, String chromeBinary,
await tempDir.delete(recursive: true);
}

Future<Map<String, String>> _parseStrings(File file) async {
Future<Map<String, String>?> _parseStrings(File file) async {
final strings = <String, String>{};
if (!file.existsSync()) {
return null;
Expand All @@ -143,7 +143,7 @@ Future<Map<String, String>> _parseStrings(File file) async {
final tmp = await file.readAsString();
final tmp2 =
tmp.replaceAll(RegExp(r';$', multiLine: true), '').replaceAll('=', ':');
final result = loadYaml(tmp2) as Map;
final result = loadYaml(tmp2) as Map?;
_logger.fine('got result: $result');
if (result == null) {
return null;
Expand Down
47 changes: 25 additions & 22 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';
Expand All @@ -9,19 +10,21 @@ part 'config.g.dart';
@JsonSerializable(anyMap: true)
class FrameConfig {
FrameConfig({
@JsonKey(nullable: true) this.rewrite,
@JsonKey(nullable: true) this.images,
this.rewrite,
this.images,
});
factory FrameConfig.fromJson(Map json) => _$FrameConfigFromJson(json);

static const FILE_NAME = 'frameit.yaml';

Map<String, dynamic> toJson() => _$FrameConfigToJson(this);

final List<FileNameMapping> rewrite;
final Map<String, FrameImage> images;
@JsonKey()
final List<FileNameMapping>? rewrite;
@JsonKey()
final Map<String, FrameImage>? images;

static Future<FrameConfig> load(String baseDir) async {
static Future<FrameConfig?> load(String baseDir) async {
final configFile = File(path.join(baseDir, FrameConfig.FILE_NAME));
if (!configFile.existsSync()) {
return null;
Expand All @@ -30,10 +33,9 @@ class FrameConfig {
loadYaml(await configFile.readAsString()) as Map);
}

FrameImage findImageConfig(String screenshotName) {
return images.entries
.firstWhere((element) => screenshotName.contains(element.key),
orElse: () => null)
FrameImage? findImageConfig(String screenshotName) {
return images?.entries
.firstWhereOrNull((element) => screenshotName.contains(element.key))
?.value;
}
}
Expand All @@ -45,29 +47,30 @@ enum FileAction {
include,
}

@JsonSerializable(nullable: false, anyMap: true)
@JsonSerializable(anyMap: true)
class FileNameMapping {
FileNameMapping({
this.pattern,
this.replace,
// @JsonKey(defaultValue: false) this.duplicate,
// @JsonKey(defaultValue: false) this.exclude,
@JsonKey(defaultValue: FileAction.rename) this.action,
this.action,
});
factory FileNameMapping.fromJson(Map json) => _$FileNameMappingFromJson(json);
Map<String, dynamic> toJson() => _$FileNameMappingToJson(this);

final String pattern;
final String replace;
final String? pattern;
final String? replace;
// final bool duplicate;
// final bool exclude;
final FileAction action;
@JsonKey(defaultValue: FileAction.rename)
final FileAction? action;

RegExp _patternRegExp;
RegExp get patternRegExp => _patternRegExp ??= RegExp(pattern);
RegExp? _patternRegExp;
RegExp get patternRegExp => _patternRegExp ??= RegExp(pattern ?? '');
}

@JsonSerializable(nullable: true, anyMap: true)
@JsonSerializable(anyMap: true)
class FrameImage {
FrameImage({
this.cropWidth,
Expand All @@ -81,17 +84,17 @@ class FrameImage {
Map<String, dynamic> toJson() => _$FrameImageToJson(this);

/// Crop with of the final image. (null for using the original width)
final int cropWidth;
final int? cropWidth;

/// Crop height of the final image. (null for using the original width)
final int cropHeight;
final int? cropHeight;

/// device name used to look up correct frame.
final String device;
final String? device;

/// Optional label used only for the `_preview.html`
final String previewLabel;
final String? previewLabel;

/// Allows customizing the css.
final String css;
final String? css;
}
74 changes: 21 additions & 53 deletions lib/src/config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading