Skip to content

Commit

Permalink
Merge pull request ScerIO#18 from prateekmedia/master
Browse files Browse the repository at this point in the history
Add changes from fantasticicon_flutter package
  • Loading branch information
SergeShkurko authored Oct 25, 2021
2 parents 695c5e2 + 05e9241 commit bd2b13e
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 202 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
pubspec.lock
.flutter-plugins
.flutter-plugins-dependencies
.packages
Expand Down Expand Up @@ -79,4 +80,4 @@ dist/*
map/*
package-lock.json
package.json
yarn.lock
yarn.lock
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Unreleased

- Make ClassNameData public
- Replace pedantic with lints
- Add naming strategy option namely - snake, camel
- Update README with new/deleted flags
- Fix iconsMap hardcoded `ui_icons.json` which prevented custom out-font name

## 3.0.0

* Replaced [icon-font-generator] with [fantasticon] [pull#14](https://github.com/rbcprolabs/icon_font_generator/pull/14)
Expand Down Expand Up @@ -43,4 +51,4 @@

## 0.0.1

* Initial release
* Initial release
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Convert all *.svg icons from dir to icon-font (.ttf) and generates flutter compatible dart class.

Abstraction layer for NodeJs package `icon-font-generator`
Abstraction layer for NodeJs package `fantasticon`.

## Requirements
Node.JS v11+
Expand All @@ -28,6 +28,7 @@ $ pub global activate icon_font_generator
- `--indent` - Indent for generating dart file, for example: ' ', default: ' '
- `--normalize` - Normalize icons sizes, default: false
- `--yarn` - Usage yarn instead npm, default: false
- `--naming-strategy` - Icons name strategy: snake (yaru_icon) or camel (yaruIcon), default: snake

## Example
File structure:
Expand Down
124 changes: 1 addition & 123 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,123 +1 @@
include: package:pedantic/analysis_options.yaml

linter:
rules:
- always_declare_return_types
- always_put_control_body_on_new_line
- always_put_required_named_parameters_first
- always_require_non_null_named_parameters
- avoid_annotating_with_dynamic
- avoid_returning_this
- avoid_classes_with_only_static_members
- annotate_overrides
- avoid_empty_else
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_return_types_on_setters
- avoid_slow_async_io
- avoid_unused_constructor_parameters
- await_only_futures
- prefer_expression_function_bodies
- camel_case_types
- cancel_subscriptions
- cascade_invocations
- comment_references
- control_flow_in_finally
- directives_ordering
- file_names
- flutter_style_todos
- empty_catches
- empty_constructor_bodies
- empty_statements
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- join_return_with_assignment
- library_names
- list_remove_unrelated_type
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_duplicate_case_values
- non_constant_identifier_names
- library_prefixes
- only_throw_errors
- package_names
- package_prefixed_library_names
- parameter_assignments
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
- prefer_contains
- prefer_final_fields
- prefer_final_locals
- prefer_foreach
- prefer_function_declarations_over_variables
- prefer_initializing_formals
- prefer_is_empty
- prefer_is_not_empty
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- prefer_null_aware_operators
- prefer_spread_collections
- provide_deprecation_message
- recursive_getters
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- type_init_formals
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators
- unnecessary_overrides
- unnecessary_statements
- unnecessary_new
- unnecessary_this
- unnecessary_parenthesis
- unnecessary_await_in_return
- lines_longer_than_80_chars
- unrelated_type_equality_checks
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- use_setters_to_change_properties
- use_string_buffers
- use_to_and_as_if_applicable
- valid_regexps

analyzer:
exclude:
- dist/**
strong-mode:
implicit-casts: true
implicit-dynamic: true
errors:
always_declare_return_types: error
camel_case_types: warning
empty_constructor_bodies: warning
annotate_overrides: warning
avoid_init_to_null: warning
constant_identifier_names: warning
slash_for_doc_comments: warning
type_annotate_public_apis: warning
type_init_formals: warning
sort_constructors_first: warning
sort_unnamed_constructors_first: warning
unnecessary_brace_in_string_interps: warning
no_duplicate_case_values: warning
prefer_void_to_null: warning
lines_longer_than_80_chars: warning
always_put_control_body_on_new_line: warning
unnecessary_await_in_return: warning
use_to_and_as_if_applicable: warning
valid_regexps: warning
throw_in_finally: warning
use_full_hex_values_for_flutter_colors: warning
use_function_type_syntax_for_parameters: warning
use_rethrow_when_possible: warning
use_setters_to_change_properties: warning
use_string_buffers: warning
include: package:lints/recommended.yaml
14 changes: 11 additions & 3 deletions bin/icon_font_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GenerateCommand extends Command {
)
..addOption(
'class-name',
help: 'Flutter class name \ family for generating file',
help: 'Flutter class name / family for generating file',
)
..addOption(
'height',
Expand Down Expand Up @@ -65,6 +65,12 @@ class GenerateCommand extends Command {
'yarn',
help: 'Use yarn instead npm',
defaultsTo: false,
)
..addOption(
'naming-strategy',
help: 'Icons name strategy',
defaultsTo: 'snake',
allowed: {'camel', 'snake'},
);
}

Expand Down Expand Up @@ -102,8 +108,9 @@ class GenerateCommand extends Command {
Directory.fromUri(genRootDir.uri.resolve('temp_icons'));
final tempOutDirectory =
Directory.fromUri(genRootDir.uri.resolve('temp_font'));
final iconsMap = File.fromUri(genRootDir.uri
.resolve(path.join(tempOutDirectory.path, 'ui_icons.json')));
final iconsMap = File.fromUri(genRootDir.uri.resolve(path.join(
tempOutDirectory.path,
path.basenameWithoutExtension(argResults!['out-font']) + '.json')));
if (tempSourceDirectory.existsSync()) {
await tempSourceDirectory.delete(recursive: true);
}
Expand Down Expand Up @@ -196,6 +203,7 @@ class GenerateCommand extends Command {
iconMap: iconsMap,
className: argResults!['class-name'],
packageName: argResults!['package'],
namingStrategy: argResults!['naming-strategy'],
indent: argResults!['indent'],
);

Expand Down
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lints/recommended.yaml
26 changes: 13 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand All @@ -50,13 +50,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
console:
dependency: transitive
description:
name: console
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
fake_async:
dependency: transitive
description:
Expand All @@ -81,13 +74,20 @@ packages:
relative: true
source: path
version: "3.0.0"
lints:
dependency: "direct dev"
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -155,7 +155,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
typed_data:
dependency: transitive
description:
Expand All @@ -169,6 +169,6 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
15 changes: 8 additions & 7 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
name: example
description: Flutter font generator example
version: 1.0.0+1
publish_to: 'none'
publish_to: "none"

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

dev_dependencies:
lints: 1.0.1
flutter_test:
sdk: flutter
icon_font_generator:
path: ../

scripts:
generate_icons: icon_font_generator
--from=icons
--class-name=UiIcons
--out-font=lib/icon_font/ui_icons.ttf
generate_icons: icon_font_generator
--from=icons
--class-name=UiIcons
--out-font=lib/icon_font/ui_icons.ttf
--out-flutter=lib/widgets/icons.dart

flutter:
fonts:
- family: UiIcons
fonts:
- asset: lib/icon_font/ui_icons.ttf
- asset: lib/icon_font/ui_icons.ttf
12 changes: 8 additions & 4 deletions lib/generate_flutter_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ Future<GenerateResult> generateFlutterClass({
required File iconMap,
required String className,
required String? packageName,
required String namingStrategy,
String indent = ' ',
}) async {
final Map<String, dynamic> icons = jsonDecode(await iconMap.readAsString());

final dartIconsEntries = icons.entries.map(
(entry) => someReplace(
template.icon
.replaceFirst('%ICON_NAME%', ReCase(entry.key).camelCase)
.replaceFirst(
'%ICON_CODE%',
entry.value.toRadixString(16).toString()
),
'%ICON_NAME%',
namingStrategy == 'snake'
? ReCase(entry.key).snakeCase
: ReCase(entry.key).camelCase,
)
.replaceFirst(
'%ICON_CODE%', entry.value.toRadixString(16).toString()),
className: className,
indent: indent,
),
Expand Down
6 changes: 3 additions & 3 deletions lib/templates/flutter_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const String base = '''
import 'package:flutter/widgets.dart';
@immutable
class _%CLASS_NAME%Data extends IconData {
%INDENT%const _%CLASS_NAME%Data(int codePoint)
class %CLASS_NAME%Data extends IconData {
%INDENT%const %CLASS_NAME%Data(int codePoint)
%INDENT%%INDENT%%INDENT%: super(
%INDENT%%INDENT%%INDENT%%INDENT%%INDENT%codePoint,
%INDENT%%INDENT%%INDENT%%INDENT%%INDENT%fontFamily: '%CLASS_NAME%',%PACKAGE%
Expand All @@ -21,7 +21,7 @@ class %CLASS_NAME% {
''';

const String icon = '%INDENT%static const IconData %ICON_NAME% = '
'_%CLASS_NAME%Data(0x%ICON_CODE%);';
'%CLASS_NAME%Data(0x%ICON_CODE%);';

const String package = '\n%INDENT%%INDENT%%INDENT%%INDENT%'
'%INDENT%fontPackage: \'%PACKAGE_NAME%\',';
Loading

0 comments on commit bd2b13e

Please sign in to comment.