forked from authpass/frameit-chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow configuration, cropping and changing devices.
- Loading branch information
Showing
8 changed files
with
583 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
targets: | ||
$default: | ||
builders: | ||
builder_static_text|static_text: | ||
generate_for: | ||
- lib/**/*.dart | ||
options: | ||
content: '// ignore_for_file: implicit_dynamic_parameter,strong_mode_implicit_dynamic_parameter,strong_mode_implicit_dynamic_variable,non_constant_identifier_names,unused_element' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
part 'config.g.dart'; | ||
|
||
@JsonSerializable(anyMap: true) | ||
class FrameConfig { | ||
FrameConfig({ | ||
@JsonKey(nullable: true) this.rewrite, | ||
@JsonKey(nullable: true) 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; | ||
|
||
static Future<FrameConfig> load(String baseDir) async { | ||
final configFile = File(path.join(baseDir, FrameConfig.FILE_NAME)); | ||
if (!configFile.existsSync()) { | ||
return null; | ||
} | ||
return FrameConfig.fromJson( | ||
loadYaml(await configFile.readAsString()) as Map); | ||
} | ||
|
||
FrameImage findImageConfig(String screenshotName) { | ||
return images.entries | ||
.firstWhere((element) => screenshotName.contains(element.key), | ||
orElse: () => null) | ||
?.value; | ||
} | ||
} | ||
|
||
@JsonSerializable(nullable: false, anyMap: true) | ||
class FileNameMapping { | ||
FileNameMapping({ | ||
this.pattern, | ||
this.replace, | ||
@JsonKey(defaultValue: false) this.duplicate, | ||
}); | ||
factory FileNameMapping.fromJson(Map json) => _$FileNameMappingFromJson(json); | ||
Map<String, dynamic> toJson() => _$FileNameMappingToJson(this); | ||
|
||
final String pattern; | ||
final String replace; | ||
final bool duplicate; | ||
|
||
RegExp _patternRegExp; | ||
RegExp get patternRegExp => _patternRegExp ??= RegExp(pattern); | ||
} | ||
|
||
@JsonSerializable(nullable: true, anyMap: true) | ||
class FrameImage { | ||
FrameImage({ | ||
this.cropWidth, | ||
this.cropHeight, | ||
this.device, | ||
}); | ||
factory FrameImage.fromJson(Map<String, dynamic> json) => | ||
_$FrameImageFromJson(json); | ||
Map<String, dynamic> toJson() => _$FrameImageToJson(this); | ||
|
||
final int cropWidth; | ||
final int cropHeight; | ||
final String device; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.