diff --git a/.gitignore b/.gitignore index b3a3d8cb..37789bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ pubspec.lock doc/api/ # The .vscode folder contains launch configuration and tasks you configure in -.vscode/ +# .vscode/ # Avoid committing generated Javascript files: *.dart.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c23472fb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "[dart]": { + "editor.formatOnSave": true + }, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + } +} diff --git a/analysis_options.yaml b/analysis_options.yaml index 1fa64113..7822842c 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,10 +1,34 @@ -# Include option is buggy: -# https://github.com/flutter/flutter/issues/62591 -# In case the include issue gets fixed, lines below INCLUDE_FIX -# can be removed - include: package:lints/recommended.yaml linter: rules: constant_identifier_names: false + always_use_package_imports: true + always_declare_return_types: true + avoid_print: true + prefer_is_empty: true + prefer_is_not_empty: true + prefer_is_not_operator: true + prefer_single_quotes: true + require_trailing_commas: true + unnecessary_overrides: false + avoid_function_literals_in_foreach_calls: false + unrelated_type_equality_checks: true + +analyzer: + errors: + always_use_package_imports: error + always_declare_return_types: error + avoid_init_to_null: error + avoid_print: error + prefer_const_constructors: error + prefer_const_constructors_in_immutables: error + prefer_const_literals_to_create_immutables: error + prefer_is_empty: error + prefer_is_not_empty: error + prefer_is_not_operator: error + prefer_single_quotes: error + require_trailing_commas: error + unrelated_type_equality_checks: error + unused_element: error + unused_local_variable: error \ No newline at end of file diff --git a/lib/commands/commands_list.dart b/lib/commands/commands_list.dart index a7cb9bb4..3954562c 100644 --- a/lib/commands/commands_list.dart +++ b/lib/commands/commands_list.dart @@ -1,5 +1,5 @@ -import 'impl/commads_export.dart'; -import 'interface/command.dart'; +import 'package:get_cli/commands/impl/commads_export.dart'; +import 'package:get_cli/commands/interface/command.dart'; final List commands = [ CommandParent( @@ -10,7 +10,7 @@ final List commands = [ CreateProjectCommand(), CreateProviderCommand(), CreateScreenCommand(), - CreateViewCommand() + CreateViewCommand(), ], ['-c'], ), diff --git a/lib/commands/impl/args_mixin.dart b/lib/commands/impl/args_mixin.dart index 5aa15730..8981eb7f 100644 --- a/lib/commands/impl/args_mixin.dart +++ b/lib/commands/impl/args_mixin.dart @@ -1,7 +1,7 @@ import 'package:http/http.dart'; import 'package:recase/recase.dart'; -import '../../core/generator.dart'; +import 'package:get_cli/core/generator.dart'; mixin ArgsMixin { final List _args = GetCli.arguments; diff --git a/lib/commands/impl/create/controller/controller.dart b/lib/commands/impl/create/controller/controller.dart index 12207fb2..990a55f7 100644 --- a/lib/commands/impl/create/controller/controller.dart +++ b/lib/commands/impl/create/controller/controller.dart @@ -3,18 +3,18 @@ import 'dart:io'; import 'package:http/http.dart'; import 'package:path/path.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../exception_handler/exceptions/cli_exception.dart'; -import '../../../../functions/binding/add_dependencies.dart'; -import '../../../../functions/binding/find_bindings.dart'; -import '../../../../functions/create/create_single_file.dart'; -import '../../../../functions/is_url/is_url.dart'; -import '../../../../functions/replace_vars/replace_vars.dart'; -import '../../../../samples/impl/get_controller.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/functions/binding/add_dependencies.dart'; +import 'package:get_cli/functions/binding/find_bindings.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/is_url/is_url.dart'; +import 'package:get_cli/functions/replace_vars/replace_vars.dart'; +import 'package:get_cli/samples/impl/get_controller.dart'; +import 'package:get_cli/commands/interface/command.dart'; /// This command is a controller with the template: ///``` @@ -37,24 +37,31 @@ class CreateControllerCommand extends Command { if (args.length > 2) { var unnecessaryParameter = args.skip(2).toList(); throw CliException( - LocaleKeys.error_unnecessary_parameter.trArgsPlural( - LocaleKeys.error_unnecessary_parameter_plural, - unnecessaryParameter.length, - [unnecessaryParameter.toString()], - ), - codeSample: codeSample); + LocaleKeys.error_unnecessary_parameter.trArgsPlural( + LocaleKeys.error_unnecessary_parameter_plural, + unnecessaryParameter.length, + [unnecessaryParameter.toString()], + ), + codeSample: codeSample, + ); } return true; } @override Future execute() async { - return createController(name, - withArgument: withArgument, onCommand: onCommand); + return createController( + name, + withArgument: withArgument, + onCommand: onCommand, + ); } - Future createController(String name, - {String withArgument = '', String onCommand = ''}) async { + Future createController( + String name, { + String withArgument = '', + String onCommand = '', + }) async { var sample = ControllerSample('', name, PubspecUtils.isServerProject); if (withArgument.isNotEmpty) { if (isURL(withArgument)) { @@ -64,7 +71,8 @@ class CreateControllerCommand extends Command { sample.customContent = replaceVars(content, name); } else { throw CliException( - LocaleKeys.error_failed_to_connect.trArgs([withArgument])); + LocaleKeys.error_failed_to_connect.trArgs([withArgument]), + ); } } else { var file = File(withArgument); @@ -73,7 +81,8 @@ class CreateControllerCommand extends Command { sample.customContent = replaceVars(content, name); } else { throw CliException( - LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument])); + LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument]), + ); } } } diff --git a/lib/commands/impl/create/page/page.dart b/lib/commands/impl/create/page/page.dart index d911812a..57cced17 100644 --- a/lib/commands/impl/create/page/page.dart +++ b/lib/commands/impl/create/page/page.dart @@ -1,22 +1,21 @@ import 'dart:io'; - import 'package:dcli/dcli.dart'; import 'package:recase/recase.dart'; -import '../../../../common/menu/menu.dart'; -import '../../../../common/utils/logger/log_utils.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../core/generator.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../functions/create/create_single_file.dart'; -import '../../../../functions/routes/get_add_route.dart'; -import '../../../../samples/impl/get_binding.dart'; -import '../../../../samples/impl/get_controller.dart'; -import '../../../../samples/impl/get_view.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/common/menu/menu.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/generator.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/routes/get_add_route.dart'; +import 'package:get_cli/samples/impl/get_binding.dart'; +import 'package:get_cli/samples/impl/get_controller.dart'; +import 'package:get_cli/samples/impl/get_view.dart'; +import 'package:get_cli/commands/interface/command.dart'; /// The command create a Binding and Controller page and view class CreatePageCommand extends Command { diff --git a/lib/commands/impl/create/project/project.dart b/lib/commands/impl/create/project/project.dart index eb7afd36..dfffd584 100644 --- a/lib/commands/impl/create/project/project.dart +++ b/lib/commands/impl/create/project/project.dart @@ -4,26 +4,29 @@ import 'package:dcli/dcli.dart'; import 'package:path/path.dart' as p; import 'package:recase/recase.dart'; -import '../../../../common/menu/menu.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../common/utils/shell/shel.utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../samples/impl/analysis_options.dart'; -import '../../../interface/command.dart'; -import '../../init/flutter/init.dart'; -import '../../init/get_server/get_server_command.dart'; +import 'package:get_cli/common/menu/menu.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/shell/shel.utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/samples/impl/analysis_options.dart'; +import 'package:get_cli/commands/interface/command.dart'; +import 'package:get_cli/commands/impl/init/flutter/init.dart'; +import 'package:get_cli/commands/impl/init/get_server/get_server_command.dart'; class CreateProjectCommand extends Command { @override String get commandName => 'project'; @override Future execute() async { - final menu = Menu([ - 'Flutter Project', - 'Get Server', - ], title: 'Select which type of project you want to create ?'); + final menu = Menu( + [ + 'Flutter Project', + 'Get Server', + ], + title: 'Select which type of project you want to create ?', + ); final result = menu.choose(); String? nameProject = name; if (name == '.') { @@ -34,7 +37,8 @@ class CreateProjectCommand extends Command { } var path = Structure.replaceAsExpected( - path: Directory.current.path + p.separator + nameProject.snakeCase); + path: Directory.current.path + p.separator + nameProject.snakeCase, + ); await Directory(path).create(recursive: true); Directory.current = path; @@ -65,10 +69,13 @@ class CreateProjectCommand extends Command { var androidLang = androidResult.index == 0 ? 'kotlin' : 'java'; - final linterMenu = Menu([ - 'Yes', - 'No', - ], title: LocaleKeys.ask_use_linter.tr); + final linterMenu = Menu( + [ + 'Yes', + 'No', + ], + title: LocaleKeys.ask_use_linter.tr, + ); final linterResult = linterMenu.choose(); await ShellUtils.flutterCreate(path, org, iosLang, androidLang); @@ -78,17 +85,23 @@ class CreateProjectCommand extends Command { switch (linterResult.index) { case 0: if (PubspecUtils.isServerProject) { - await PubspecUtils.addDependencies('lints', - isDev: true, runPubGet: true); + await PubspecUtils.addDependencies( + 'lints', + isDev: true, + runPubGet: true, + ); AnalysisOptionsSample( - include: 'include: package:lints/recommended.yaml') - .create(); + include: 'include: package:lints/recommended.yaml', + ).create(); } else { - await PubspecUtils.addDependencies('flutter_lints', - isDev: true, runPubGet: true); + await PubspecUtils.addDependencies( + 'flutter_lints', + isDev: true, + runPubGet: true, + ); AnalysisOptionsSample( - include: 'include: package:flutter_lints/flutter.yaml') - .create(); + include: 'include: package:flutter_lints/flutter.yaml', + ).create(); } break; diff --git a/lib/commands/impl/create/provider/provider.dart b/lib/commands/impl/create/provider/provider.dart index 5308b48f..78549351 100644 --- a/lib/commands/impl/create/provider/provider.dart +++ b/lib/commands/impl/create/provider/provider.dart @@ -1,8 +1,8 @@ -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../functions/create/create_single_file.dart'; -import '../../../../samples/impl/get_provider.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/samples/impl/get_provider.dart'; +import 'package:get_cli/commands/interface/command.dart'; class CreateProviderCommand extends Command { @override @@ -10,8 +10,14 @@ class CreateProviderCommand extends Command { @override Future execute() async { var name = this.name; - handleFileCreate(name, 'provider', onCommand, onCommand.isNotEmpty, - ProviderSample(name), onCommand.isNotEmpty ? 'providers' : ''); + handleFileCreate( + name, + 'provider', + onCommand, + onCommand.isNotEmpty, + ProviderSample(name), + onCommand.isNotEmpty ? 'providers' : '', + ); } @override diff --git a/lib/commands/impl/create/screen/screen.dart b/lib/commands/impl/create/screen/screen.dart index d3d6e843..ea905f11 100644 --- a/lib/commands/impl/create/screen/screen.dart +++ b/lib/commands/impl/create/screen/screen.dart @@ -2,19 +2,19 @@ import 'dart:io'; import 'package:recase/recase.dart'; -import '../../../../common/menu/menu.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../core/generator.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../functions/create/create_single_file.dart'; -import '../../../../functions/exports_files/add_export.dart'; -import '../../../../functions/routes/arc_add_route.dart'; -import '../../../../samples/impl/get_binding.dart'; -import '../../../../samples/impl/get_controller.dart'; -import '../../../../samples/impl/get_view.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/common/menu/menu.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/generator.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/exports_files/add_export.dart'; +import 'package:get_cli/functions/routes/arc_add_route.dart'; +import 'package:get_cli/samples/impl/get_binding.dart'; +import 'package:get_cli/samples/impl/get_controller.dart'; +import 'package:get_cli/samples/impl/get_view.dart'; +import 'package:get_cli/commands/interface/command.dart'; class CreateScreenCommand extends Command { @override @@ -39,10 +39,13 @@ class CreateScreenCommand extends Command { var path = pathSplit.join('/'); path = Structure.replaceAsExpected(path: path); if (Directory(path).existsSync()) { - final menu = Menu([ - LocaleKeys.options_yes.tr, - LocaleKeys.options_no.tr, - ], title: LocaleKeys.ask_existing_page.trArgs([name]).toString()); + final menu = Menu( + [ + LocaleKeys.options_yes.tr, + LocaleKeys.options_no.tr, + ], + title: LocaleKeys.ask_existing_page.trArgs([name]).toString(), + ); final result = menu.choose(); if (result.index == 0) { _writeFiles(path, name, overwrite: true); @@ -64,47 +67,57 @@ class CreateScreenCommand extends Command { void _writeFiles(String path, String name, {bool overwrite = false}) { var isServer = PubspecUtils.isServerProject; - var controller = handleFileCreate(name, 'controller', path, true, - ControllerSample('', name, isServer), 'controllers', '.'); + var controller = handleFileCreate( + name, + 'controller', + path, + true, + ControllerSample('', name, isServer), + 'controllers', + '.', + ); var controllerImport = Structure.pathToDirImport(controller.path); var view = handleFileCreate( - name, - 'screen', - path, - false, - GetViewSample( - '', - '${name.pascalCase}Screen', - '${name.pascalCase}Controller', - controllerImport, - isServer, - ), + name, + 'screen', + path, + false, + GetViewSample( '', - '.'); + '${name.pascalCase}Screen', + '${name.pascalCase}Controller', + controllerImport, + isServer, + ), + '', + '.', + ); var binding = handleFileCreate( - name, - 'controller.binding', + name, + 'controller.binding', + '', + true, + BindingSample( '', - true, - BindingSample( - '', - name, - '${name.pascalCase}ControllerBinding', - controllerImport, - isServer, - ), - 'controllers', - '.'); + name, + '${name.pascalCase}ControllerBinding', + controllerImport, + isServer, + ), + 'controllers', + '.', + ); var exportView = 'package:${PubspecUtils.projectName}/' '${Structure.pathToDirImport(view.path)}'; addExport('lib/presentation/screens.dart', "export '$exportView';"); addExport( - 'lib/infrastructure/navigation/bindings/controllers/controllers_bindings.dart', - "export 'package:${PubspecUtils.projectName}/${Structure.pathToDirImport(binding.path)}'; "); + 'lib/infrastructure/navigation/bindings/controllers/controllers_bindings.dart', + "export 'package:${PubspecUtils.projectName}/${Structure.pathToDirImport(binding.path)}'; ", + ); arcAddRoute(name); } diff --git a/lib/commands/impl/create/view/view.dart b/lib/commands/impl/create/view/view.dart index 31748bb1..fdb89823 100644 --- a/lib/commands/impl/create/view/view.dart +++ b/lib/commands/impl/create/view/view.dart @@ -3,15 +3,15 @@ import 'dart:io'; import 'package:http/http.dart'; import 'package:recase/recase.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../exception_handler/exceptions/cli_exception.dart'; -import '../../../../functions/create/create_single_file.dart'; -import '../../../../functions/is_url/is_url.dart'; -import '../../../../functions/replace_vars/replace_vars.dart'; -import '../../../../samples/impl/get_view.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/is_url/is_url.dart'; +import 'package:get_cli/functions/replace_vars/replace_vars.dart'; +import 'package:get_cli/samples/impl/get_view.dart'; +import 'package:get_cli/commands/interface/command.dart'; class CreateViewCommand extends Command { @override @@ -36,8 +36,11 @@ class CreateViewCommand extends Command { int get maxParameters => 0; } -Future createView(String name, - {String withArgument = '', String onCommand = ''}) async { +Future createView( + String name, { + String withArgument = '', + String onCommand = '', +}) async { var sample = GetViewSample( '', '${name.pascalCase}View', @@ -53,7 +56,8 @@ Future createView(String name, sample.customContent = replaceVars(content, name); } else { throw CliException( - LocaleKeys.error_failed_to_connect.trArgs([withArgument])); + LocaleKeys.error_failed_to_connect.trArgs([withArgument]), + ); } } else { var file = File(withArgument); @@ -62,7 +66,8 @@ Future createView(String name, sample.customContent = replaceVars(content, name); } else { throw CliException( - LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument])); + LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument]), + ); } } } diff --git a/lib/commands/impl/generate/locales/locales.dart b/lib/commands/impl/generate/locales/locales.dart index 69ff8ccc..e76a1793 100644 --- a/lib/commands/impl/generate/locales/locales.dart +++ b/lib/commands/impl/generate/locales/locales.dart @@ -3,13 +3,13 @@ import 'dart:io'; import 'package:path/path.dart'; -import '../../../../common/utils/logger/log_utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../exception_handler/exceptions/cli_exception.dart'; -import '../../../../samples/impl/generate_locales.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/samples/impl/generate_locales.dart'; +import 'package:get_cli/commands/interface/command.dart'; class GenerateLocalesCommand extends Command { @override @@ -28,7 +28,8 @@ class GenerateLocalesCommand extends Command { if (!await Directory(inputPath).exists()) { LogService.error( - LocaleKeys.error_nonexistent_directory.trArgs([inputPath])); + LocaleKeys.error_nonexistent_directory.trArgs([inputPath]), + ); return; } @@ -80,7 +81,8 @@ class GenerateLocalesCommand extends Command { value = _replaceValue(value); if (RegExp(r'^[0-9]|[!@#<>?":`~;[\]\\|=+)(*&^%-\s]').hasMatch(key)) { throw CliException( - LocaleKeys.error_special_characters_in_key.trArgs([key])); + LocaleKeys.error_special_characters_in_key.trArgs([key]), + ); } parsedLocales.writeln('\t\t\'$key\': \'$value\','); }); @@ -91,15 +93,20 @@ class GenerateLocalesCommand extends Command { Structure.model('locales', 'generate_locales', false, on: onCommand); GenerateLocalesSample( - parsedKeys, parsedLocales.toString(), translationsKeys.toString(), - path: '${newFileModel.path}.g.dart') - .create(); + parsedKeys, + parsedLocales.toString(), + translationsKeys.toString(), + path: '${newFileModel.path}.g.dart', + ).create(); LogService.success(LocaleKeys.sucess_locale_generate.tr); } - void _resolve(Map localization, Map result, - [String? accKey]) { + void _resolve( + Map localization, + Map result, [ + String? accKey, + ]) { final sortedKeys = localization.keys.toList(); for (var key in sortedKeys) { diff --git a/lib/commands/impl/generate/model/model.dart b/lib/commands/impl/generate/model/model.dart index 83dc8d3c..33d94682 100644 --- a/lib/commands/impl/generate/model/model.dart +++ b/lib/commands/impl/generate/model/model.dart @@ -1,21 +1,20 @@ import 'dart:io'; - import 'package:dcli/dcli.dart'; import 'package:http/http.dart'; import 'package:path/path.dart' as p; import 'package:recase/recase.dart'; -import '../../../../common/utils/json_serialize/model_generator.dart'; -import '../../../../common/utils/logger/log_utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../exception_handler/exceptions/cli_exception.dart'; -import '../../../../functions/create/create_single_file.dart'; -import '../../../../models/file_model.dart'; -import '../../../../samples/impl/get_provider.dart'; -import '../../../interface/command.dart'; +import 'package:get_cli/common/utils/json_serialize/model_generator.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/models/file_model.dart'; +import 'package:get_cli/samples/impl/get_provider.dart'; +import 'package:get_cli/commands/interface/command.dart'; class GenerateModelCommand extends Command { @override @@ -34,7 +33,10 @@ class GenerateModelCommand extends Command { FileModel newFileModel; final classGenerator = ModelGenerator( - name, containsArg('--private'), containsArg('--withCopy')); + name, + containsArg('--private'), + containsArg('--withCopy'), + ); newFileModel = Structure.model(name, 'model', false, on: onCommand); @@ -74,8 +76,10 @@ class GenerateModelCommand extends Command { fromArgument.isEmpty) { var codeSample = 'get generate model on home with assets/models/user.json'; - throw CliException(LocaleKeys.error_invalid_json.trArgs([withArgument]), - codeSample: codeSample); + throw CliException( + LocaleKeys.error_invalid_json.trArgs([withArgument]), + codeSample: codeSample, + ); } return true; } @@ -89,15 +93,18 @@ class GenerateModelCommand extends Command { return result.body; } on Exception catch (_) { throw CliException( - LocaleKeys.error_failed_to_connect.trArgs([fromArgument])); + LocaleKeys.error_failed_to_connect.trArgs([fromArgument]), + ); } } } final String? codeSample1 = LogService.code( - 'get generate model on home with assets/models/user.json'); + 'get generate model on home with assets/models/user.json', + ); final String? codeSample2 = LogService.code( - 'get generate model on home from "https://api.github.com/users/CpdnCristiano"'); + 'get generate model on home from "https://api.github.com/users/CpdnCristiano"', + ); @override String get codeSample => ''' diff --git a/lib/commands/impl/help/help.dart b/lib/commands/impl/help/help.dart index 1a2b9d78..57b8cc30 100644 --- a/lib/commands/impl/help/help.dart +++ b/lib/commands/impl/help/help.dart @@ -1,8 +1,8 @@ -import '../../../common/utils/logger/log_utils.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../commands_list.dart'; -import '../../interface/command.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/commands/commands_list.dart'; +import 'package:get_cli/commands/interface/command.dart'; class HelpCommand extends Command { @override diff --git a/lib/commands/impl/init/flutter/init.dart b/lib/commands/impl/init/flutter/init.dart index 68bc17b7..740405a9 100644 --- a/lib/commands/impl/init/flutter/init.dart +++ b/lib/commands/impl/init/flutter/init.dart @@ -1,12 +1,12 @@ -import '../../../../common/menu/menu.dart'; -import '../../../../common/utils/logger/log_utils.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../common/utils/shell/shel.utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../interface/command.dart'; -import 'init_getxpattern.dart'; -import 'init_katteko.dart'; +import 'package:get_cli/common/menu/menu.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/shell/shel.utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/commands/interface/command.dart'; +import 'package:get_cli/commands/impl/init/flutter/init_getxpattern.dart'; +import 'package:get_cli/commands/impl/init/flutter/init_katteko.dart'; class InitCommand extends Command { @override @@ -14,10 +14,13 @@ class InitCommand extends Command { @override Future execute() async { - final menu = Menu([ - 'GetX Pattern (by Kauê)', - 'CLEAN (by Arktekko)', - ], title: 'Which architecture do you want to use?'); + final menu = Menu( + [ + 'GetX Pattern (by Kauê)', + 'CLEAN (by Arktekko)', + ], + title: 'Which architecture do you want to use?', + ); final result = menu.choose(); result.index == 0 diff --git a/lib/commands/impl/init/flutter/init_getxpattern.dart b/lib/commands/impl/init/flutter/init_getxpattern.dart index c136a5ab..dc4ce28c 100644 --- a/lib/commands/impl/init/flutter/init_getxpattern.dart +++ b/lib/commands/impl/init/flutter/init_getxpattern.dart @@ -1,15 +1,15 @@ import 'dart:io'; -import '../../../../common/utils/logger/log_utils.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../functions/create/create_list_directory.dart'; -import '../../../../functions/create/create_main.dart'; -import '../../../../samples/impl/getx_pattern/get_main.dart'; -import '../../commads_export.dart'; -import '../../install/install_get.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/functions/create/create_list_directory.dart'; +import 'package:get_cli/functions/create/create_main.dart'; +import 'package:get_cli/samples/impl/getx_pattern/get_main.dart'; +import 'package:get_cli/commands/impl/commads_export.dart'; +import 'package:get_cli/commands/impl/install/install_get.dart'; Future createInitGetxPattern() async { var canContinue = await createMain(); diff --git a/lib/commands/impl/init/flutter/init_katteko.dart b/lib/commands/impl/init/flutter/init_katteko.dart index 20910f22..a177479a 100644 --- a/lib/commands/impl/init/flutter/init_katteko.dart +++ b/lib/commands/impl/init/flutter/init_katteko.dart @@ -1,16 +1,16 @@ import 'dart:io'; -import '../../../../common/utils/logger/log_utils.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../core/internationalization.dart'; -import '../../../../core/locales.g.dart'; -import '../../../../core/structure.dart'; -import '../../../../functions/create/create_list_directory.dart'; -import '../../../../functions/create/create_main.dart'; -import '../../../../samples/impl/arctekko/arc_main.dart'; -import '../../../../samples/impl/arctekko/config_example.dart'; -import '../../commads_export.dart'; -import '../../install/install_get.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/functions/create/create_list_directory.dart'; +import 'package:get_cli/functions/create/create_main.dart'; +import 'package:get_cli/samples/impl/arctekko/arc_main.dart'; +import 'package:get_cli/samples/impl/arctekko/config_example.dart'; +import 'package:get_cli/commands/impl/commads_export.dart'; +import 'package:get_cli/commands/impl/install/install_get.dart'; Future createInitKatekko() async { var canContinue = await createMain(); @@ -20,14 +20,22 @@ Future createInitKatekko() async { } var initialDirs = [ Directory(Structure.replaceAsExpected(path: 'lib/domain/core/interfaces/')), - Directory(Structure.replaceAsExpected( - path: 'lib/infrastructure/navigation/bindings/controllers/')), - Directory(Structure.replaceAsExpected( - path: 'lib/infrastructure/navigation/bindings/domains/')), Directory( - Structure.replaceAsExpected(path: 'lib/infrastructure/dal/daos/')), + Structure.replaceAsExpected( + path: 'lib/infrastructure/navigation/bindings/controllers/', + ), + ), Directory( - Structure.replaceAsExpected(path: 'lib/infrastructure/dal/services/')), + Structure.replaceAsExpected( + path: 'lib/infrastructure/navigation/bindings/domains/', + ), + ), + Directory( + Structure.replaceAsExpected(path: 'lib/infrastructure/dal/daos/'), + ), + Directory( + Structure.replaceAsExpected(path: 'lib/infrastructure/dal/services/'), + ), Directory(Structure.replaceAsExpected(path: 'lib/presentation/')), Directory(Structure.replaceAsExpected(path: 'lib/infrastructure/theme/')), ]; diff --git a/lib/commands/impl/init/get_server/get_server_command.dart b/lib/commands/impl/init/get_server/get_server_command.dart index ade45869..5b64021f 100644 --- a/lib/commands/impl/init/get_server/get_server_command.dart +++ b/lib/commands/impl/init/get_server/get_server_command.dart @@ -1,13 +1,12 @@ import 'dart:io'; +import 'package:get_cli/commands/impl/init/flutter/init_getxpattern.dart'; +import 'package:get_cli/commands/interface/command.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/samples/impl/analysis_options.dart'; +import 'package:get_cli/samples/impl/get_server/pubspec.dart'; import 'package:path/path.dart'; -import '../../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../../samples/impl/analysis_options.dart'; -import '../../../../samples/impl/get_server/pubspec.dart'; -import '../../../interface/command.dart'; -import '../flutter/init_getxpattern.dart'; - class InitGetServer extends Command { @override String get commandName => 'init'; @@ -20,8 +19,11 @@ class InitGetServer extends Command { include: 'include: package:pedantic/analysis_options.yaml', ).create(); await PubspecUtils.addDependencies('get_server', runPubGet: false); - await PubspecUtils.addDependencies('pedantic', - isDev: true, runPubGet: false); + await PubspecUtils.addDependencies( + 'pedantic', + isDev: true, + runPubGet: false, + ); await PubspecUtils.addDependencies('test', isDev: true, runPubGet: false); await createInitGetxPattern(); diff --git a/lib/commands/impl/install/install.dart b/lib/commands/impl/install/install.dart index 573c4866..96997f96 100644 --- a/lib/commands/impl/install/install.dart +++ b/lib/commands/impl/install/install.dart @@ -1,10 +1,10 @@ -import '../../../common/utils/logger/log_utils.dart'; -import '../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../common/utils/shell/shel.utils.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../../exception_handler/exceptions/cli_exception.dart'; -import '../../interface/command.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/shell/shel.utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/commands/interface/command.dart'; class InstallCommand extends Command { @override @@ -20,13 +20,20 @@ class InstallCommand extends Command { var packageInfo = element.split(':'); LogService.info('Installing package "${packageInfo.first}" …'); if (packageInfo.length == 1) { - runPubGet = await PubspecUtils.addDependencies(packageInfo.first, - isDev: isDev, runPubGet: false) + runPubGet = await PubspecUtils.addDependencies( + packageInfo.first, + isDev: isDev, + runPubGet: false, + ) ? true : runPubGet; } else { - runPubGet = await PubspecUtils.addDependencies(packageInfo.first, - version: packageInfo[1], isDev: isDev, runPubGet: false) + runPubGet = await PubspecUtils.addDependencies( + packageInfo.first, + version: packageInfo[1], + isDev: isDev, + runPubGet: false, + ) ? true : runPubGet; } @@ -44,8 +51,9 @@ class InstallCommand extends Command { if (args.isEmpty) { throw CliException( - 'Please, enter the name of a package you wanna install', - codeSample: codeSample); + 'Please, enter the name of a package you wanna install', + codeSample: codeSample, + ); } return true; } diff --git a/lib/commands/impl/install/install_get.dart b/lib/commands/impl/install/install_get.dart index 529d5c96..f680d6c0 100644 --- a/lib/commands/impl/install/install_get.dart +++ b/lib/commands/impl/install/install_get.dart @@ -1,4 +1,4 @@ -import '../../../common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; Future installGet([bool runPubGet = false]) async { PubspecUtils.removeDependencies('get', logger: false); diff --git a/lib/commands/impl/remove/remove.dart b/lib/commands/impl/remove/remove.dart index 354a661b..805d76cf 100644 --- a/lib/commands/impl/remove/remove.dart +++ b/lib/commands/impl/remove/remove.dart @@ -1,10 +1,10 @@ -import '../../../common/utils/logger/log_utils.dart'; -import '../../../common/utils/pubspec/pubspec_utils.dart'; -import '../../../common/utils/shell/shel.utils.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../../exception_handler/exceptions/cli_exception.dart'; -import '../../interface/command.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/shell/shel.utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/commands/interface/command.dart'; class RemoveCommand extends Command { @override @@ -27,8 +27,10 @@ class RemoveCommand extends Command { bool validate() { super.validate(); if (args.isEmpty) { - CliException(LocaleKeys.error_no_package_to_remove.tr, - codeSample: codeSample); + CliException( + LocaleKeys.error_no_package_to_remove.tr, + codeSample: codeSample, + ); } return true; } diff --git a/lib/commands/impl/sort/sort.dart b/lib/commands/impl/sort/sort.dart index 7110a4d3..05123118 100644 --- a/lib/commands/impl/sort/sort.dart +++ b/lib/commands/impl/sort/sort.dart @@ -1,11 +1,11 @@ import 'dart:io'; -import '../../../common/utils/logger/log_utils.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../../exception_handler/exceptions/cli_exception.dart'; -import '../../../functions/create/create_single_file.dart'; -import '../../interface/command.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/commands/interface/command.dart'; class SortCommand extends Command { @override @@ -25,7 +25,8 @@ class SortCommand extends Command { sortImportsFile(path); } else { throw CliException( - LocaleKeys.error_invalid_file_or_directory.trArgs([path])); + LocaleKeys.error_invalid_file_or_directory.trArgs([path]), + ); } } @@ -43,8 +44,10 @@ class SortCommand extends Command { bool validate() { super.validate(); if (args.isEmpty) { - throw CliException(LocaleKeys.error_required_path.tr, - codeSample: codeSample); + throw CliException( + LocaleKeys.error_required_path.tr, + codeSample: codeSample, + ); } return true; } @@ -54,24 +57,31 @@ class SortCommand extends Command { .listSync(recursive: true, followLinks: false) .forEach((element) { if (element is File && element.path.endsWith('.dart')) { - writeFile(element.path, element.readAsStringSync(), - overwrite: true, - logger: false, - skipRename: containsArg('--skipRename'), - useRelativeImport: containsArg('--relative')); + writeFile( + element.path, + element.readAsStringSync(), + overwrite: true, + logger: false, + skipRename: containsArg('--skipRename'), + useRelativeImport: containsArg('--relative'), + ); LogService.success( - LocaleKeys.sucess_file_formatted.trArgs([element.path])); + LocaleKeys.sucess_file_formatted.trArgs([element.path]), + ); } }); } void sortImportsFile(String path) { if (path.endsWith('.dart') && File(path).existsSync()) { - writeFile(path, File(path).readAsStringSync(), - overwrite: true, - logger: false, - skipRename: containsArg('--skipRename'), - useRelativeImport: containsArg('--relative')); + writeFile( + path, + File(path).readAsStringSync(), + overwrite: true, + logger: false, + skipRename: containsArg('--skipRename'), + useRelativeImport: containsArg('--relative'), + ); LogService.success(LocaleKeys.sucess_file_formatted.trArgs([path])); } else { throw CliException(LocaleKeys.error_invalid_dart.trArgs([path])); diff --git a/lib/commands/impl/update/update.dart b/lib/commands/impl/update/update.dart index 8e9e772e..1e4208ec 100644 --- a/lib/commands/impl/update/update.dart +++ b/lib/commands/impl/update/update.dart @@ -1,7 +1,7 @@ -import '../../../common/utils/shell/shel.utils.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../interface/command.dart'; +import 'package:get_cli/common/utils/shell/shel.utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/commands/interface/command.dart'; class UpdateCommand extends Command { @override diff --git a/lib/commands/impl/version/version.dart b/lib/commands/impl/version/version.dart index e5f798fc..c0145c5f 100644 --- a/lib/commands/impl/version/version.dart +++ b/lib/commands/impl/version/version.dart @@ -1,8 +1,8 @@ -import '../../../common/utils/pubspec/pubspec_lock.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../../functions/version/print_get_cli.dart'; -import '../../interface/command.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_lock.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/functions/version/print_get_cli.dart'; +import 'package:get_cli/commands/interface/command.dart'; // ignore_for_file: avoid_print diff --git a/lib/commands/interface/command.dart b/lib/commands/interface/command.dart index 7e0092c9..2c1654fe 100644 --- a/lib/commands/interface/command.dart +++ b/lib/commands/interface/command.dart @@ -1,9 +1,9 @@ -import '../../common/utils/logger/log_utils.dart'; -import '../../core/generator.dart'; -import '../../core/locales.g.dart'; -import '../../exception_handler/exceptions/cli_exception.dart'; -import '../../extensions.dart'; -import '../impl/args_mixin.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/generator.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/extensions.dart'; +import 'package:get_cli/commands/impl/args_mixin.dart'; abstract class Command with ArgsMixin { Command() { @@ -37,22 +37,25 @@ abstract class Command with ArgsMixin { var flagsNotAceppts = flags; flagsNotAceppts.removeWhere((element) => acceptedFlags.contains(element)); if (flagsNotAceppts.isNotEmpty) { - LogService.info(LocaleKeys.info_unnecessary_flag.trArgsPlural( - LocaleKeys.info_unnecessary_flag_prural, - flagsNotAceppts.length, - [flagsNotAceppts.toString()], - )!); + LogService.info( + LocaleKeys.info_unnecessary_flag.trArgsPlural( + LocaleKeys.info_unnecessary_flag_prural, + flagsNotAceppts.length, + [flagsNotAceppts.toString()], + )!, + ); } if (args.length > maxParameters) { List pars = args.skip(maxParameters).toList(); throw CliException( - LocaleKeys.error_unnecessary_parameter.trArgsPlural( - LocaleKeys.error_unnecessary_parameter_plural, - pars.length, - [pars.toString()], - ), - codeSample: codeSample); + LocaleKeys.error_unnecessary_parameter.trArgsPlural( + LocaleKeys.error_unnecessary_parameter_plural, + pars.length, + [pars.toString()], + ), + codeSample: codeSample, + ); } } return true; diff --git a/lib/common/menu/menu.dart b/lib/common/menu/menu.dart index b9b3520a..560a8a30 100644 --- a/lib/common/menu/menu.dart +++ b/lib/common/menu/menu.dart @@ -16,7 +16,6 @@ class Menu { // final answer = dialog.ask(); // final result = answer['result'] as String; - print(""); final result = menu(title, options: choices, defaultOption: choices[0]); final index = choices.indexOf(result); diff --git a/lib/common/utils/json_serialize/helpers.dart b/lib/common/utils/json_serialize/helpers.dart index ecce6766..302412b1 100644 --- a/lib/common/utils/json_serialize/helpers.dart +++ b/lib/common/utils/json_serialize/helpers.dart @@ -4,9 +4,9 @@ import 'dart:math'; import 'package:collection/collection.dart'; -import '../logger/log_utils.dart'; -import 'json_ast/json_ast.dart'; -import 'sintaxe.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/json_ast.dart'; +import 'package:get_cli/common/utils/json_serialize/sintaxe.dart'; const Map PRIMITIVE_TYPES = { 'int': true, @@ -58,8 +58,11 @@ String camelCase(String text) { String capitalize(Match m) => m[0]!.substring(0, 1).toUpperCase() + m[0]!.substring(1); String skip(String s) => ''; - return text.splitMapJoin(RegExp(r'[a-zA-Z0-9]+'), - onMatch: capitalize, onNonMatch: skip); + return text.splitMapJoin( + RegExp(r'[a-zA-Z0-9]+'), + onMatch: capitalize, + onNonMatch: skip, + ); } String camelCaseFirstLower(String text) { @@ -126,8 +129,11 @@ WithWarning mergeObj(Map obj, Map other, String path) { return WithWarning(clone, warnings); } -WithWarning mergeObjectList(List list, String path, - [int idx = -1]) { +WithWarning mergeObjectList( + List list, + String path, [ + int idx = -1, +]) { var warnings = {}; var obj = {}; for (var i = 0; i < list.length; i++) { @@ -198,8 +204,11 @@ bool isPrimitiveType(String? typeName) { return isPrimitive; } -String fixFieldName(String name, - {TypeDefinition? typeDef, bool privateField = false}) { +String fixFieldName( + String name, { + TypeDefinition? typeDef, + bool privateField = false, +}) { var properName = name; if (name.startsWith('_') || name.startsWith(RegExp(r'[0-9]'))) { final firstCharType = typeDef!.name!.substring(0, 1).toLowerCase(); diff --git a/lib/common/utils/json_serialize/json_ast/error.dart b/lib/common/utils/json_serialize/json_ast/error.dart index 3b2690ba..a80ec205 100644 --- a/lib/common/utils/json_serialize/json_ast/error.dart +++ b/lib/common/utils/json_serialize/json_ast/error.dart @@ -7,8 +7,12 @@ class Settings { final bool loc; final String? source; - Settings( - {this.extraLines = 2, this.tabSize = 4, this.loc = true, this.source}); + Settings({ + this.extraLines = 2, + this.tabSize = 4, + this.loc = true, + this.source, + }); } String repeatString(String str, int n) { @@ -25,26 +29,41 @@ String repeatString(String str, int n) { } String printLine( - String line, int position, int maxNumLength, Settings settings) { + String line, + int position, + int maxNumLength, + Settings settings, +) { final n = position.toString(); final formattedNum = n.padLeft(maxNumLength); final tabReplacement = repeatString(' ', settings.tabSize); return '$formattedNum | ${line.replaceAll('\t', tabReplacement)}'; } -String printLines(List lines, int start, int end, int maxNumLength, - Settings settings) { +String printLines( + List lines, + int start, + int end, + int maxNumLength, + Settings settings, +) { return lines .sublist(start, end) .asMap() - .map((i, line) => - MapEntry(i, printLine(line, start + i + 1, maxNumLength, settings))) + .map( + (i, line) => + MapEntry(i, printLine(line, start + i + 1, maxNumLength, settings)), + ) .values .join('\n'); } -String codeErrorFragment(String input, int linePos, int columnPos, - [Settings? settings]) { +String codeErrorFragment( + String input, + int linePos, + int columnPos, [ + Settings? settings, +]) { final splitter = RegExp(r'\r\n?|\n|\f'); final lines = input.split(splitter); settings = settings ?? Settings(); @@ -54,10 +73,11 @@ String codeErrorFragment(String input, int linePos, int columnPos, final prevLines = printLines(lines, startLinePos, linePos, maxNumLength, settings); final targetLineBeforeCursor = printLine( - lines[linePos - 1].substring(0, columnPos - 1), - linePos, - maxNumLength, - settings); + lines[linePos - 1].substring(0, columnPos - 1), + linePos, + maxNumLength, + settings, + ); final cursorLine = '${repeatString(' ', targetLineBeforeCursor.length)}^'; final nextLines = printLines(lines, linePos, endLinePos, maxNumLength, settings); @@ -74,7 +94,12 @@ class JSONASTException implements Exception { String? _message; JSONASTException( - this.rawMessage, this.input, this.source, this.line, this.column) { + this.rawMessage, + this.input, + this.source, + this.line, + this.column, + ) { if (input != null) { _message = line != 0 ? '$rawMessage\n${codeErrorFragment(input!, line!, column!)}' diff --git a/lib/common/utils/json_serialize/json_ast/location.dart b/lib/common/utils/json_serialize/json_ast/location.dart index b7644292..459b89ae 100644 --- a/lib/common/utils/json_serialize/json_ast/location.dart +++ b/lib/common/utils/json_serialize/json_ast/location.dart @@ -40,9 +40,15 @@ class Location { end == other.end && source == other.source; - static Location create(int? startLine, int? startColumn, int? startOffset, - int? endLine, int? endColumn, int? endOffset, - [String? source]) { + static Location create( + int? startLine, + int? startColumn, + int? startOffset, + int? endLine, + int? endColumn, + int? endOffset, [ + String? source, + ]) { final startSegment = Segment(startLine, startColumn, startOffset); final endSegment = Segment(endLine, endColumn, endOffset); return Location(startSegment, endSegment, source); diff --git a/lib/common/utils/json_serialize/json_ast/parse.dart b/lib/common/utils/json_serialize/json_ast/parse.dart index 59aebce1..5625bf7e 100644 --- a/lib/common/utils/json_serialize/json_ast/parse.dart +++ b/lib/common/utils/json_serialize/json_ast/parse.dart @@ -1,10 +1,10 @@ import 'dart:math'; -import './error.dart'; -import './location.dart'; -import './parse_error_types.dart'; -import './tokenize.dart'; -import './utils/substring.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/error.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/location.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/parse_error_types.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/tokenize.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/utils/substring.dart'; enum _ObjectState { _START_, OPEN_OBJECT, PROPERTY, COMMA } @@ -13,13 +13,21 @@ enum _PropertyState { _START_, KEY, COLON } enum _ArrayState { _START_, OPEN_ARRAY, VALUE, COMMA } JSONASTException errorEof( - String input, List tokenList, Settings settings) { + String input, + List tokenList, + Settings settings, +) { final loc = (tokenList.isNotEmpty ? tokenList[tokenList.length - 1].loc.end as Loc : Loc(line: 1, column: 1)); return JSONASTException( - unexpectedEnd(), input, settings.source, loc.line, loc.column); + unexpectedEnd(), + input, + settings.source, + loc.line, + loc.column, + ); } /// [hexCode] is the hexCode string without '\u' prefix @@ -37,7 +45,7 @@ final escapes = { 'f': '\f', // Form feed 'n': '\n', // New line 'r': '\r', // Carriage return - 't': '\t' // Horizontal tab + 't': '\t', // Horizontal tab }; final passEscapes = ['"', '\\', '/']; @@ -67,7 +75,11 @@ String parseString(String string) { } ValueIndex? parseObject( - String input, List tokenList, int index, Settings settings) { + String input, + List tokenList, + int index, + Settings settings, +) { // object: LEFT_BRACE (property (COMMA property)*)? RIGHT_BRACE late Token startToken; var object = ObjectNode(); @@ -94,14 +106,16 @@ ValueIndex? parseObject( if (token.type == TokenType.RIGHT_BRACE) { // if (settings.loc != null) { object = object.copyWith( - loc: Location.create( - startToken.loc!.start.line, - startToken.loc!.start.column, - startToken.loc!.start.offset, - token.loc!.end.line, - token.loc!.end.column, - token.loc!.end.offset, - settings.source)); + loc: Location.create( + startToken.loc!.start.line, + startToken.loc!.start.column, + startToken.loc!.start.offset, + token.loc!.end.line, + token.loc!.end.column, + token.loc!.end.offset, + settings.source, + ), + ); // } return ValueIndex(object, index + 1); } else { @@ -135,13 +149,22 @@ ValueIndex? parseObject( index++; } else { final msg = unexpectedToken( - substring( - input, token.loc!.start.offset!, token.loc!.end.offset), - settings.source, - token.loc!.start.line, - token.loc!.start.column); - throw JSONASTException(msg, input, settings.source, - token.loc!.start.line, token.loc!.start.column); + substring( + input, + token.loc!.start.offset!, + token.loc!.end.offset, + ), + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); + throw JSONASTException( + msg, + input, + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); } break; } @@ -155,13 +178,22 @@ ValueIndex? parseObject( state = _ObjectState.PROPERTY; } else { final msg = unexpectedToken( - substring( - input, token.loc!.start.offset!, token.loc!.end.offset), - settings.source, - token.loc!.start.line, - token.loc!.start.column); - throw JSONASTException(msg, input, settings.source, - token.loc!.start.line, token.loc!.start.column); + substring( + input, + token.loc!.start.offset!, + token.loc!.end.offset, + ), + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); + throw JSONASTException( + msg, + input, + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); } break; } @@ -171,7 +203,11 @@ ValueIndex? parseObject( } ValueIndex? parseProperty( - String input, List tokenList, int index, Settings settings) { + String input, + List tokenList, + int index, + Settings settings, +) { // property: STRING COLON value late Token startToken; var property = PropertyNode(); @@ -184,8 +220,13 @@ ValueIndex? parseProperty( case _PropertyState._START_: { if (token.type == TokenType.STRING) { - final value = parseString(safeSubstring(input, - token.loc!.start.offset! + 1, token.loc!.end.offset! - 1)); + final value = parseString( + safeSubstring( + input, + token.loc!.start.offset! + 1, + token.loc!.end.offset! - 1, + ), + ); var key = ValueNode(value, token.value); if (settings.loc) { key = key.copyWith(loc: token.loc); @@ -207,13 +248,22 @@ ValueIndex? parseProperty( index++; } else { final msg = unexpectedToken( - substring( - input, token.loc!.start.offset!, token.loc!.end.offset), - settings.source, - token.loc!.start.line, - token.loc!.start.column); - throw JSONASTException(msg, input, settings.source, - token.loc!.start.line, token.loc!.start.column); + substring( + input, + token.loc!.start.offset!, + token.loc!.end.offset, + ), + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); + throw JSONASTException( + msg, + input, + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); } break; } @@ -224,14 +274,16 @@ ValueIndex? parseProperty( property = property.copyWith(value: value.value); if (settings.loc) { property = property.copyWith( - loc: Location.create( - startToken.loc?.start.line, - startToken.loc?.start.column, - startToken.loc?.start.offset, - value.value?.loc?.end.line, - value.value?.loc?.end.column, - value.value?.loc?.end.offset, - settings.source)); + loc: Location.create( + startToken.loc?.start.line, + startToken.loc?.start.column, + startToken.loc?.start.offset, + value.value?.loc?.end.line, + value.value?.loc?.end.column, + value.value?.loc?.end.offset, + settings.source, + ), + ); } return ValueIndex(property, value.index); } @@ -241,7 +293,11 @@ ValueIndex? parseProperty( } ValueIndex? parseArray( - String input, List tokenList, int index, Settings settings) { + String input, + List tokenList, + int index, + Settings settings, +) { // array: LEFT_BRACKET (value (COMMA value)*)? RIGHT_BRACKET late Token startToken; var array = ArrayNode(); @@ -267,14 +323,16 @@ ValueIndex? parseArray( if (token.type == TokenType.RIGHT_BRACKET) { if (settings.loc) { array = array.copyWith( - loc: Location.create( - startToken.loc!.start.line, - startToken.loc!.start.column, - startToken.loc!.start.offset, - token.loc!.end.line, - token.loc!.end.column, - token.loc!.end.offset, - settings.source)); + loc: Location.create( + startToken.loc!.start.line, + startToken.loc!.start.column, + startToken.loc!.start.offset, + token.loc!.end.line, + token.loc!.end.column, + token.loc!.end.offset, + settings.source, + ), + ); } return ValueIndex(array, index + 1); } else { @@ -291,14 +349,16 @@ ValueIndex? parseArray( if (token.type == TokenType.RIGHT_BRACKET) { if (settings.loc) { array = array.copyWith( - loc: Location.create( - startToken.loc!.start.line, - startToken.loc!.start.column, - startToken.loc!.start.offset, - token.loc!.end.line, - token.loc!.end.column, - token.loc!.end.offset, - settings.source)); + loc: Location.create( + startToken.loc!.start.line, + startToken.loc!.start.column, + startToken.loc!.start.offset, + token.loc!.end.line, + token.loc!.end.column, + token.loc!.end.offset, + settings.source, + ), + ); } return ValueIndex(array, index + 1); } else if (token.type == TokenType.COMMA) { @@ -306,13 +366,22 @@ ValueIndex? parseArray( index++; } else { final msg = unexpectedToken( - substring( - input, token.loc!.start.offset!, token.loc!.end.offset), - settings.source, - token.loc!.start.line, - token.loc!.start.column); - throw JSONASTException(msg, input, settings.source, - token.loc!.start.line, token.loc!.start.column); + substring( + input, + token.loc!.start.offset!, + token.loc!.end.offset, + ), + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); + throw JSONASTException( + msg, + input, + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); } break; } @@ -331,7 +400,11 @@ ValueIndex? parseArray( } ValueIndex? parseLiteral( - String input, List tokenList, int index, Settings settings) { + String input, + List tokenList, + int index, + Settings settings, +) { // literal: STRING | NUMBER | TRUE | FALSE | NULL final token = tokenList[index]; dynamic value; @@ -339,8 +412,13 @@ ValueIndex? parseLiteral( switch (token.type) { case TokenType.STRING: { - value = parseString(safeSubstring( - input, token.loc!.start.offset! + 1, token.loc!.end.offset! - 1)); + value = parseString( + safeSubstring( + input, + token.loc!.start.offset! + 1, + token.loc!.end.offset! - 1, + ), + ); break; } case TokenType.NUMBER: @@ -378,15 +456,27 @@ ValueIndex? parseLiteral( } typedef ParserFun = ValueIndex? Function( - String input, List tokenList, int index, Settings settings); + String input, + List tokenList, + int index, + Settings settings, +); List _parsersList = [parseLiteral, parseObject, parseArray]; ValueIndex? _findValueIndex( - String input, List tokenList, int index, Settings settings) { + String input, + List tokenList, + int index, + Settings settings, +) { for (var i = 0; i < _parsersList.length; i++) { final parser = _parsersList.elementAt(i) as ValueIndex? Function( - String, List, int, Settings); + String, + List, + int, + Settings, + ); final valueIndex = parser(input, tokenList, index, settings); if (valueIndex != null) { return valueIndex; @@ -396,7 +486,11 @@ ValueIndex? _findValueIndex( } ValueIndex _parseValue( - String input, List tokenList, int index, Settings settings) { + String input, + List tokenList, + int index, + Settings settings, +) { // value: literal | object | array final token = tokenList[index]; @@ -406,12 +500,18 @@ ValueIndex _parseValue( return value; } else { final msg = unexpectedToken( - substring(input, token.loc!.start.offset!, token.loc!.end.offset), - settings.source, - token.loc!.start.line, - token.loc!.start.column); - throw JSONASTException(msg, input, settings.source, token.loc!.start.line, - token.loc!.start.column); + substring(input, token.loc!.start.offset!, token.loc!.end.offset), + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); + throw JSONASTException( + msg, + input, + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); } } @@ -431,10 +531,16 @@ Node parse(String input, Settings settings) { final token = tokenList[value.index]; final msg = unexpectedToken( - substring(input, token.loc!.start.offset!, token.loc!.end.offset), - settings.source, - token.loc!.start.line, - token.loc!.start.column); - throw JSONASTException(msg, input, settings.source, token.loc!.start.line, - token.loc!.start.column); + substring(input, token.loc!.start.offset!, token.loc!.end.offset), + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); + throw JSONASTException( + msg, + input, + settings.source, + token.loc!.start.line, + token.loc!.start.column, + ); } diff --git a/lib/common/utils/json_serialize/json_ast/tokenize.dart b/lib/common/utils/json_serialize/json_ast/tokenize.dart index 02ddfa5a..d0ddf955 100644 --- a/lib/common/utils/json_serialize/json_ast/tokenize.dart +++ b/lib/common/utils/json_serialize/json_ast/tokenize.dart @@ -1,9 +1,9 @@ import 'package:meta/meta.dart'; -import './error.dart'; -import './location.dart'; -import './tokenize_error_types.dart'; -import './utils/substring.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/error.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/location.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/tokenize_error_types.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/utils/substring.dart'; enum TokenType { LEFT_BRACE, // { @@ -25,13 +25,13 @@ final Map punctuatorTokensMap = { '[': TokenType.LEFT_BRACKET, ']': TokenType.RIGHT_BRACKET, ':': TokenType.COLON, - ',': TokenType.COMMA + ',': TokenType.COMMA, }; final Map keywordTokensMap = { 'true': TokenType.TRUE, 'false': TokenType.FALSE, - 'null': TokenType.NULL + 'null': TokenType.NULL, }; enum _StringState { _START_, START_QUOTE_OR_CHAR, ESCAPE } @@ -45,7 +45,7 @@ final Map escapes = { 'n': 5, // New line 'r': 6, // Carriage return 't': 7, // Horizontal tab - 'u': 8 // 4 hexadecimal digits + 'u': 8, // 4 hexadecimal digits }; enum _NumberState { @@ -147,9 +147,11 @@ class Token { class ObjectNode extends Node { final List children; - ObjectNode( - [super.type = 'Object', super.loc, List? children]) - : children = children ?? []; + ObjectNode([ + super.type = 'Object', + super.loc, + List? children, + ]) : children = children ?? []; ObjectNode copyWith({ String? type, @@ -171,7 +173,6 @@ class ObjectNode extends Node { _compareDynamicList(children, other.children); @override - // TODO: implement hashCode int get hashCode => super.hashCode; } @@ -201,7 +202,6 @@ class ArrayNode extends Node { _compareDynamicList(children, other.children); @override - // TODO: implement hashCode int get hashCode => super.hashCode; } @@ -250,7 +250,6 @@ class PropertyNode extends Node { } @override - // TODO: implement hashCode int get hashCode => super.hashCode; } @@ -288,7 +287,6 @@ class LiteralNode extends Node { } @override - // TODO: implement hashCode int get hashCode => super.hashCode; } @@ -304,7 +302,6 @@ class ValueIndex { other is ValueIndex && value == other.value && index == other.index; @override - // TODO: implement hashCode int get hashCode => super.hashCode; } @@ -421,8 +418,13 @@ Token? parseString(String input, int index, int line, int column) { state = _StringState.ESCAPE; } else if (char == '"') { index++; - return Token(TokenType.STRING, line, column + index - startIndex, - index, safeSubstring(input, startIndex, index)); + return Token( + TokenType.STRING, + line, + column + index - startIndex, + index, + safeSubstring(input, startIndex, index), + ); } else { // buffer.write(char); index++; @@ -574,8 +576,13 @@ Token? parseNumber(String input, int index, int line, int column) { } if (passedValueIndex > 0) { - return Token(TokenType.NUMBER, line, column + passedValueIndex - startIndex, - passedValueIndex, safeSubstring(input, startIndex, passedValueIndex)); + return Token( + TokenType.NUMBER, + line, + column + passedValueIndex - startIndex, + passedValueIndex, + safeSubstring(input, startIndex, passedValueIndex), + ); } return null; @@ -585,7 +592,7 @@ List _parsers = [ parseChar, parseKeyword, parseString, - parseNumber + parseNumber, ]; Token? _parseToken(String input, int index, int line, int column) { @@ -616,15 +623,26 @@ List tokenize(String input, Settings settings) { final token = _parseToken(input, index, line, column); if (token != null) { - token.loc = Location.create(line, column, index, token.line, token.column, - token.index, settings.source); + token.loc = Location.create( + line, + column, + index, + token.line, + token.column, + token.index, + settings.source, + ); tokens.add(token); index = token.index; line = token.line; column = token.column; } else { final msg = unexpectedSymbol( - substring(input, index, index + 1), settings.source, line, column); + substring(input, index, index + 1), + settings.source, + line, + column, + ); throw JSONASTException(msg, input, settings.source, line, column); } } diff --git a/lib/common/utils/json_serialize/json_ast/utils/grapheme_splitter.dart b/lib/common/utils/json_serialize/json_ast/utils/grapheme_splitter.dart index 18e25500..b208952e 100644 --- a/lib/common/utils/json_serialize/json_ast/utils/grapheme_splitter.dart +++ b/lib/common/utils/json_serialize/json_ast/utils/grapheme_splitter.dart @@ -1,26 +1,26 @@ -const int CR = 0; -const int LF = 1; -const int Control = 2; -const int Extend = 3; -const int Regional_Indicator = 4; -const int SpacingMark = 5; +const int cr = 0; +const int lf = 1; +const int control = 2; +const int extend = 3; +const int regionalIndicator = 4; +const int spacingMark = 5; const int L = 6; const int V = 7; -const int T = 8; -const int LV = 9; -const int LVT = 10; -const int Other = 11; -const int Prepend = 12; -const int E_Base = 13; -const int E_Modifier = 14; -const int ZWJ = 15; -const int Glue_After_Zwj = 16; -const int E_Base_GAZ = 17; -const int NotBreak = 0; -const int BreakStart = 1; -const int Break = 2; -const int BreakLastRegional = 3; -const int BreakPenultimateRegional = 4; +const int t = 8; +const int lv = 9; +const int lvt = 10; +const int other = 11; +const int prepend = 12; +const int eBase = 13; +const int eModifier = 14; +const int zwj = 15; +const int glueAfterZwj = 16; +const int eBaseGAZ = 17; +const int notBreak = 0; +const int breakStart = 1; +const int kBreak = 2; +const int breakLastRegional = 3; +const int breakPenultimateRegional = 4; bool _isSurrogate(String str, int pos) { return 0xd800 <= str.codeUnitAt(pos) && @@ -61,65 +61,65 @@ int shouldBreak(int start, List mid, int end) { all.addAll([end]); final previous = all[all.length - 2]; final next = end; - final eModifierIndex = all.lastIndexOf(E_Modifier); + final eModifierIndex = all.lastIndexOf(eModifier); if (eModifierIndex > 1 && - all.sublist(1, eModifierIndex).every((c) => c == Extend) && - ![Extend, E_Base, E_Base_GAZ].contains(start)) { - return Break; + all.sublist(1, eModifierIndex).every((c) => c == extend) && + ![extend, eBase, eBaseGAZ].contains(start)) { + return kBreak; } - var rIIndex = all.lastIndexOf(Regional_Indicator); + var rIIndex = all.lastIndexOf(regionalIndicator); if (rIIndex > 0 && - all.sublist(1, rIIndex).every((c) => c == Regional_Indicator) && - ![Prepend, Regional_Indicator].contains(previous)) { - if (all.where((c) => c == Regional_Indicator).length % 2 == 1) { - return BreakLastRegional; + all.sublist(1, rIIndex).every((c) => c == regionalIndicator) && + ![prepend, regionalIndicator].contains(previous)) { + if (all.where((c) => c == regionalIndicator).length % 2 == 1) { + return breakLastRegional; } else { - return BreakPenultimateRegional; + return breakPenultimateRegional; } } - if (previous == CR && next == LF) { - return NotBreak; - } else if (previous == Control || previous == CR || previous == LF) { - if (next == E_Modifier && mid.every((c) => c == Extend)) { - return Break; + if (previous == cr && next == lf) { + return notBreak; + } else if (previous == control || previous == cr || previous == lf) { + if (next == eModifier && mid.every((c) => c == extend)) { + return kBreak; } else { - return BreakStart; + return breakStart; } - } else if (next == Control || next == CR || next == LF) { - return BreakStart; + } else if (next == control || next == cr || next == lf) { + return breakStart; } else if (previous == L && - (next == L || next == V || next == LV || next == LVT)) { - return NotBreak; - } else if ((previous == LV || previous == V) && (next == V || next == T)) { - return NotBreak; - } else if ((previous == LVT || previous == T) && next == T) { - return NotBreak; - } else if (next == Extend || next == ZWJ) { - return NotBreak; - } else if (next == SpacingMark) { - return NotBreak; - } else if (previous == Prepend) { - return NotBreak; + (next == L || next == V || next == lv || next == lvt)) { + return notBreak; + } else if ((previous == lv || previous == V) && (next == V || next == t)) { + return notBreak; + } else if ((previous == lvt || previous == t) && next == t) { + return notBreak; + } else if (next == extend || next == zwj) { + return notBreak; + } else if (next == spacingMark) { + return notBreak; + } else if (previous == prepend) { + return notBreak; } final previousNonExtendIndex = - all.contains(Extend) ? all.lastIndexOf(Extend) - 1 : all.length - 2; + all.contains(extend) ? all.lastIndexOf(extend) - 1 : all.length - 2; if (previousNonExtendIndex != -1 && - [E_Base, E_Base_GAZ].contains(all[previousNonExtendIndex]) && + [eBase, eBaseGAZ].contains(all[previousNonExtendIndex]) && all.length > previousNonExtendIndex + 1 && - sliceFromEnd(all, previousNonExtendIndex + 1).every((c) => c == Extend) && - next == E_Modifier) { - return NotBreak; + sliceFromEnd(all, previousNonExtendIndex + 1).every((c) => c == extend) && + next == eModifier) { + return notBreak; } - if (previous == ZWJ && [Glue_After_Zwj, E_Base_GAZ].contains(next)) { - return NotBreak; + if (previous == zwj && [glueAfterZwj, eBaseGAZ].contains(next)) { + return notBreak; } - if (mid.contains(Regional_Indicator)) { - return Break; + if (mid.contains(regionalIndicator)) { + return kBreak; } - if (previous == Regional_Indicator && next == Regional_Indicator) { - return NotBreak; + if (previous == regionalIndicator && next == regionalIndicator) { + return notBreak; } - return BreakStart; + return breakStart; } int getGraphemeBreakProperty(int code) { @@ -133,13 +133,13 @@ int getGraphemeBreakProperty(int code) { 0x11A3A == code || (0x11A86 <= code && code <= 0x11A89) || 0x11D46 == code) { - return Prepend; + return prepend; } if (0x000D == code) { - return CR; + return cr; } if (0x000A == code) { - return LF; + return lf; } if ((0x0000 <= code && code <= 0x0009) || (0x000B <= code && code <= 0x000C) || @@ -167,7 +167,7 @@ int getGraphemeBreakProperty(int code) { (0xE0002 <= code && code <= 0xE001F) || (0xE0080 <= code && code <= 0xE00FF) || (0xE01F0 <= code && code <= 0xE0FFF)) { - return Control; + return control; } if ((0x0300 <= code && code <= 0x036F) || (0x0483 <= code && code <= 0x0487) || @@ -498,10 +498,10 @@ int getGraphemeBreakProperty(int code) { (0x1E944 <= code && code <= 0x1E94A) || (0xE0020 <= code && code <= 0xE007F) || (0xE0100 <= code && code <= 0xE01EF)) { - return Extend; + return extend; } if ((0x1F1E6 <= code && code <= 0x1F1FF)) { - return Regional_Indicator; + return regionalIndicator; } if (0x0903 == code || 0x093B == code || @@ -648,7 +648,7 @@ int getGraphemeBreakProperty(int code) { (0x16F51 <= code && code <= 0x16F7E) || 0x1D166 == code || 0x1D16D == code) { - return SpacingMark; + return spacingMark; } if ((0x1100 <= code && code <= 0x115F) || (0xA960 <= code && code <= 0xA97C)) { @@ -660,7 +660,7 @@ int getGraphemeBreakProperty(int code) { } if ((0x11A8 <= code && code <= 0x11FF) || (0xD7CB <= code && code <= 0xD7FB)) { - return T; + return t; } if (0xAC00 == code || 0xAC1C == code || @@ -1061,7 +1061,7 @@ int getGraphemeBreakProperty(int code) { 0xD750 == code || 0xD76C == code || 0xD788 == code) { - return LV; + return lv; } if ((0xAC01 <= code && code <= 0xAC1B) || (0xAC1D <= code && code <= 0xAC37) || @@ -1462,7 +1462,7 @@ int getGraphemeBreakProperty(int code) { (0xD751 <= code && code <= 0xD76B) || (0xD76D <= code && code <= 0xD787) || (0xD789 <= code && code <= 0xD7A3)) { - return LVT; + return lvt; } if (0x261D == code || 0x26F9 == code || @@ -1495,13 +1495,13 @@ int getGraphemeBreakProperty(int code) { (0x1F930 <= code && code <= 0x1F939) || (0x1F93D <= code && code <= 0x1F93E) || (0x1F9D1 <= code && code <= 0x1F9DD)) { - return E_Base; + return eBase; } if ((0x1F3FB <= code && code <= 0x1F3FF)) { - return E_Modifier; + return eModifier; } if (0x200D == code) { - return ZWJ; + return zwj; } if (0x2640 == code || 0x2642 == code || @@ -1523,12 +1523,12 @@ int getGraphemeBreakProperty(int code) { 0x1F5E8 == code || 0x1F680 == code || 0x1F692 == code) { - return Glue_After_Zwj; + return glueAfterZwj; } if ((0x1F466 <= code && code <= 0x1F469)) { - return E_Base_GAZ; + return eBaseGAZ; } - return Other; + return other; } class GraphemeSplitter { diff --git a/lib/common/utils/json_serialize/json_ast/utils/substring.dart b/lib/common/utils/json_serialize/json_ast/utils/substring.dart index 00856004..e4f02eb6 100644 --- a/lib/common/utils/json_serialize/json_ast/utils/substring.dart +++ b/lib/common/utils/json_serialize/json_ast/utils/substring.dart @@ -1,6 +1,7 @@ import 'dart:math'; -import 'grapheme_splitter.dart' show GraphemeSplitter; +import 'package:get_cli/common/utils/json_serialize/json_ast/utils/grapheme_splitter.dart' + show GraphemeSplitter; String substring(String str, int start, [int? end]) { end ??= start + 1; diff --git a/lib/common/utils/json_serialize/model_generator.dart b/lib/common/utils/json_serialize/model_generator.dart index 9b85032e..868e383a 100644 --- a/lib/common/utils/json_serialize/model_generator.dart +++ b/lib/common/utils/json_serialize/model_generator.dart @@ -3,10 +3,11 @@ import 'dart:collection'; import 'package:collection/collection.dart' show IterableExtension; import 'package:dart_style/dart_style.dart'; -import '../pubspec/pubspec_utils.dart'; -import 'helpers.dart'; -import 'json_ast/json_ast.dart' show parse, Settings, Node; -import 'sintaxe.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/json_serialize/helpers.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/json_ast.dart' + show parse, Settings, Node; +import 'package:get_cli/common/utils/json_serialize/sintaxe.dart'; class DartCode extends WithWarning { DartCode(super.result, super.warnings); @@ -30,10 +31,12 @@ class ModelGenerator { final Map sameClassMapping = HashMap(); late List hints; - ModelGenerator(this._rootClassName, - [this._privateFields = false, - this._withCopyConstructor, - List? hints]) { + ModelGenerator( + this._rootClassName, [ + this._privateFields = false, + this._withCopyConstructor, + List? hints, + ]) { if (hints != null) { this.hints = hints; } else { @@ -45,8 +48,12 @@ class ModelGenerator { return hints.firstWhereOrNull((h) => h.path == path); } - List _generateClassDefinition(String className, - dynamic jsonRawDynamicData, String path, Node? astNode) { + List _generateClassDefinition( + String className, + dynamic jsonRawDynamicData, + String path, + Node? astNode, + ) { var warnings = []; if (jsonRawDynamicData is List) { // if first element is an array, start in the first element. @@ -113,21 +120,30 @@ class ModelGenerator { dynamic toAnalyze; if (!dependency.typeDef.isAmbiguous!) { var mergeWithWarning = mergeObjectList( - jsonRawData[dependency.name] as List, - '$path/${dependency.name}'); + jsonRawData[dependency.name] as List, + '$path/${dependency.name}', + ); toAnalyze = mergeWithWarning.result; warnings.addAll(mergeWithWarning.warnings); } else { toAnalyze = jsonRawData[dependency.name][0]; } final node = navigateNode(astNode, dependency.name); - warns = _generateClassDefinition(dependency.className, toAnalyze, - '$path/${dependency.name}', node); + warns = _generateClassDefinition( + dependency.className, + toAnalyze, + '$path/${dependency.name}', + node, + ); } } else { final node = navigateNode(astNode, dependency.name); - warns = _generateClassDefinition(dependency.className, - jsonRawData[dependency.name], '$path/${dependency.name}', node); + warns = _generateClassDefinition( + dependency.className, + jsonRawData[dependency.name], + '$path/${dependency.name}', + node, + ); } if (warns != null) { warnings.addAll(warns); @@ -181,6 +197,8 @@ class ModelGenerator { final unsafeDartCode = generateUnsafeDart(rawJson); final formatter = DartFormatter(); return DartCode( - formatter.format(unsafeDartCode.code), unsafeDartCode.warnings); + formatter.format(unsafeDartCode.code), + unsafeDartCode.warnings, + ); } } diff --git a/lib/common/utils/json_serialize/sintaxe.dart b/lib/common/utils/json_serialize/sintaxe.dart index 743baad9..fb46739f 100644 --- a/lib/common/utils/json_serialize/sintaxe.dart +++ b/lib/common/utils/json_serialize/sintaxe.dart @@ -2,9 +2,10 @@ import 'package:collection/collection.dart' show IterableExtension; -import '../pubspec/pubspec_utils.dart'; -import 'helpers.dart'; -import 'json_ast/json_ast.dart' show Node; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/json_serialize/helpers.dart'; +import 'package:get_cli/common/utils/json_serialize/json_ast/json_ast.dart' + show Node; // ignore_for_file: avoid_equals_and_hash_code_on_mutable_classes @@ -62,8 +63,12 @@ class TypeDefinition { // when array is empty insert Null just to warn the user elemType = 'Null'; } - return TypeDefinition(type, - astNode: astNode, subtype: elemType, isAmbiguous: isAmbiguous); + return TypeDefinition( + type, + astNode: astNode, + subtype: elemType, + isAmbiguous: isAmbiguous, + ); } return TypeDefinition(type, astNode: astNode, isAmbiguous: isAmbiguous); } @@ -203,8 +208,11 @@ class ClassDefinition { return dependenciesList; } - ClassDefinition(this._name, - [this._privateFields = false, this._withCopyConstructor = false]); + ClassDefinition( + this._name, [ + this._privateFields = false, + this._withCopyConstructor = false, + ]); @override bool operator ==(Object other) { @@ -396,6 +404,5 @@ class ClassDefinition { } @override - // TODO: implement hashCode int get hashCode => super.hashCode; } diff --git a/lib/common/utils/pub_dev/pub_dev_api.dart b/lib/common/utils/pub_dev/pub_dev_api.dart index 136fc7cf..20a0f10c 100644 --- a/lib/common/utils/pub_dev/pub_dev_api.dart +++ b/lib/common/utils/pub_dev/pub_dev_api.dart @@ -3,9 +3,9 @@ import 'dart:io'; import 'package:http/http.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; class PubDevApi { static Future getLatestVersionFromPackage(String package) async { diff --git a/lib/common/utils/pubspec/pubspec_lock.dart b/lib/common/utils/pubspec/pubspec_lock.dart index 833df20f..e7ba72a1 100644 --- a/lib/common/utils/pubspec/pubspec_lock.dart +++ b/lib/common/utils/pubspec/pubspec_lock.dart @@ -3,10 +3,10 @@ import 'dart:io'; import 'package:path/path.dart'; import 'package:yaml/yaml.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../../functions/version/check_dev_version.dart'; -import '../logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/functions/version/check_dev_version.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; class PubspecLock { static Future getVersionCli({bool disableLog = false}) async { @@ -28,7 +28,8 @@ class PubspecLock { } on Exception catch (_) { if (!disableLog) { LogService.error( - Translation(LocaleKeys.error_cli_version_not_found).tr); + Translation(LocaleKeys.error_cli_version_not_found).tr, + ); } return null; } diff --git a/lib/common/utils/pubspec/pubspec_utils.dart b/lib/common/utils/pubspec/pubspec_utils.dart index 4918dc97..61682428 100644 --- a/lib/common/utils/pubspec/pubspec_utils.dart +++ b/lib/common/utils/pubspec/pubspec_utils.dart @@ -4,12 +4,12 @@ import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:yaml/yaml.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../../../extensions.dart'; -import '../../menu/menu.dart'; -import '../logger/log_utils.dart'; -import '../shell/shel.utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/extensions.dart'; +import 'package:get_cli/common/menu/menu.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/shell/shel.utils.dart'; // ignore: avoid_classes_with_only_static_members class PubspecUtils { @@ -19,7 +19,7 @@ class PubspecUtils { static String get pubspecString => _pubspecFile.readAsStringSync(); - static get pubspecJson => loadYaml(pubspecString); + static dynamic get pubspecJson => loadYaml(pubspecString); /// separtor static final _mapSep = _PubValue(() { @@ -58,13 +58,18 @@ class PubspecUtils { static bool? get extraFolder => _extraFolder.value; - static Future addDependencies(String package, - {String? version, bool isDev = false, bool runPubGet = true}) async { + static Future addDependencies( + String package, { + String? version, + bool isDev = false, + bool runPubGet = true, + }) async { if (containsPackage(package)) { LogService.info( - LocaleKeys.ask_package_already_installed.trArgs([package]), - false, - false); + LocaleKeys.ask_package_already_installed.trArgs([package]), + false, + false, + ); final menu = Menu( [ LocaleKeys.options_yes.tr, @@ -109,8 +114,10 @@ class PubspecUtils { return true; } - static Future removeDependencies(String package, - {bool logger = true}) async { + static Future removeDependencies( + String package, { + bool logger = true, + }) async { if (logger) LogService.info('Removing package: "$package"'); await ShellUtils.removePackage(package); diff --git a/lib/common/utils/pubspec/yaml_to.string.dart b/lib/common/utils/pubspec/yaml_to.string.dart index 3286a00c..1dfe54ed 100644 --- a/lib/common/utils/pubspec/yaml_to.string.dart +++ b/lib/common/utils/pubspec/yaml_to.string.dart @@ -1,5 +1,6 @@ final _unsuportedCharacters = RegExp( - r'''^[\n\t ,[\]{}#&*!|<>'"%@']|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$'''); + r'''^[\n\t ,[\]{}#&*!|<>'"%@']|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$''', +); class CliYamlToString { const CliYamlToString({ @@ -21,11 +22,21 @@ class CliYamlToString { _writeYamlString(node, 0, sink, true, false); } - void _writeYamlString(node, int indentCount, StringSink stringSink, - bool isTopLevel, bool isList) { + void _writeYamlString( + node, + int indentCount, + StringSink stringSink, + bool isTopLevel, + bool isList, + ) { if (node is Map) { - _mapToYamlString(node.cast(), indentCount, stringSink, - isTopLevel, isList); + _mapToYamlString( + node.cast(), + indentCount, + stringSink, + isTopLevel, + isList, + ); } else if (node is Iterable) { _listToYamlString(node, indentCount, stringSink, isTopLevel); } else if (node is String) { diff --git a/lib/common/utils/shell/shel.utils.dart b/lib/common/utils/shell/shel.utils.dart index 01487545..0456e788 100644 --- a/lib/common/utils/shell/shel.utils.dart +++ b/lib/common/utils/shell/shel.utils.dart @@ -2,12 +2,12 @@ import 'dart:io'; import 'package:process_run/shell_run.dart'; -import '../../../core/generator.dart'; -import '../../../core/internationalization.dart'; -import '../../../core/locales.g.dart'; -import '../logger/log_utils.dart'; -import '../pub_dev/pub_dev_api.dart'; -import '../pubspec/pubspec_lock.dart'; +import 'package:get_cli/core/generator.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pub_dev/pub_dev_api.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_lock.dart'; class ShellUtils { static Future pubGet() async { @@ -34,13 +34,16 @@ class ShellUtils { LogService.info('Running `flutter create $path` …'); await run( - 'flutter create --no-pub -i $iosLang -a $androidLang --org $org' - ' "$path"', - verbose: true); + 'flutter create --no-pub -i $iosLang -a $androidLang --org $org' + ' "$path"', + verbose: true, + ); } - static Future update( - [bool isGit = false, bool forceUpdate = false]) async { + static Future update([ + bool isGit = false, + bool forceUpdate = false, + ]) async { isGit = GetCli.arguments.contains('--git'); forceUpdate = GetCli.arguments.contains('-f'); if (!isGit && !forceUpdate) { @@ -51,8 +54,9 @@ class ShellUtils { if (versionInstalled == versionInPubDev) { return LogService.info( - Translation(LocaleKeys.info_cli_last_version_already_installed.tr) - .toString()); + Translation(LocaleKeys.info_cli_last_version_already_installed.tr) + .toString(), + ); } } @@ -62,16 +66,18 @@ class ShellUtils { if (Platform.script.path.contains('flutter')) { if (isGit) { await run( - 'flutter pub global activate -sgit https://github.com/jonataslaw/get_cli/', - verbose: true); + 'flutter pub global activate -sgit https://github.com/jonataslaw/get_cli/', + verbose: true, + ); } else { await run('flutter pub global activate get_cli', verbose: true); } } else { if (isGit) { await run( - 'flutter pub global activate -sgit https://github.com/jonataslaw/get_cli/', - verbose: true); + 'flutter pub global activate -sgit https://github.com/jonataslaw/get_cli/', + verbose: true, + ); } else { await run('flutter pub global activate get_cli', verbose: true); } diff --git a/lib/core/generator.dart b/lib/core/generator.dart index 200e5c15..4b54c7dd 100644 --- a/lib/core/generator.dart +++ b/lib/core/generator.dart @@ -1,7 +1,7 @@ -import '../commands/commands_list.dart'; -import '../commands/impl/help/help.dart'; -import '../commands/interface/command.dart'; -import '../common/utils/logger/log_utils.dart'; +import 'package:get_cli/commands/commands_list.dart'; +import 'package:get_cli/commands/impl/help/help.dart'; +import 'package:get_cli/commands/interface/command.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; class GetCli { final List _arguments; @@ -22,10 +22,11 @@ class GetCli { final currentArgument = arguments[currentIndex].split(':').first; var command = commands.firstWhere( - (command) => - command.commandName == currentArgument || - command.alias.contains(currentArgument), - orElse: () => ErrorCommand('command not found')); + (command) => + command.commandName == currentArgument || + command.alias.contains(currentArgument), + orElse: () => ErrorCommand('command not found'), + ); if (command.childrens.isNotEmpty) { if (command is CommandParent) { command = _findCommand(++currentIndex, command.childrens); diff --git a/lib/core/internationalization.dart b/lib/core/internationalization.dart index 728611b5..ddcac3a6 100644 --- a/lib/core/internationalization.dart +++ b/lib/core/internationalization.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'locales.g.dart'; +import 'package:get_cli/core/locales.g.dart'; extension TranslationExt on String { /// Translation @@ -54,8 +54,11 @@ extension TranslationExt on String { return i > 1 ? plural?.tr : tr; } - String? trArgsPlural( - [String? plural, int i = 0, List args = const []]) { + String? trArgsPlural([ + String? plural, + int i = 0, + List args = const [], + ]) { return i > 1 ? plural?.trArgs(args) : trArgs(args); } } diff --git a/lib/core/locales.g.dart b/lib/core/locales.g.dart index 0fcd5858..38e35d3d 100644 --- a/lib/core/locales.g.dart +++ b/lib/core/locales.g.dart @@ -4,7 +4,6 @@ // ignore_for_file: constant_identifier_names // ignore: avoid_classes_with_only_static_members - class AppTranslation { static Map> translations = { 'tr_TR': Locales.tr_TR, @@ -352,7 +351,8 @@ class Locales { 'error_failed_to_connect': 'Failed to connect with %s.', 'error_no_valid_file_or_url': '%s is not a file or valid url.', 'error_unnecessary_parameter': 'the %s parameter is not necessary.', - 'error_unnecessary_parameter_plural': 'the %s parameters are not necessary.', + 'error_unnecessary_parameter_plural': + 'the %s parameters are not necessary.', 'error_nonexistent_directory': '%s directory does not exist.', 'error_empty_directory': '%s is empty.', 'error_invalid_json': '%s is not a valid json file.', diff --git a/lib/core/structure.dart b/lib/core/structure.dart index cbb1a3ce..2ad6a94d 100644 --- a/lib/core/structure.dart +++ b/lib/core/structure.dart @@ -1,18 +1,19 @@ import 'dart:io'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/models/file_model.dart'; import 'package:path/path.dart' as p; import 'package:recase/recase.dart'; -import '../exception_handler/exceptions/cli_exception.dart'; -import '../models/file_model.dart'; -import 'internationalization.dart'; -import 'locales.g.dart'; - class Structure { static final Map _paths = { - 'page': Directory(replaceAsExpected( - path: '${Directory.current.path}/lib/pages/')) - .existsSync() + 'page': Directory( + replaceAsExpected( + path: '${Directory.current.path}/lib/pages/', + ), + ).existsSync() ? replaceAsExpected(path: 'lib/pages') : replaceAsExpected(path: 'lib/app/modules'), 'widget': replaceAsExpected(path: 'lib/app/widgets/'), @@ -29,34 +30,48 @@ class Structure { 'controller.binding': replaceAsExpected(path: 'lib/infrastructure/navigation/bindings'), 'navigation': replaceAsExpected( - path: 'lib/infrastructure/navigation/navigation.dart'), + path: 'lib/infrastructure/navigation/navigation.dart', + ), //generator files 'generate_locales': replaceAsExpected(path: 'lib/generated'), }; - static FileModel model(String? name, String command, bool wrapperFolder, - {String? on, String? folderName}) { + static FileModel model( + String? name, + String command, + bool wrapperFolder, { + String? on, + String? folderName, + }) { if (on != null && on != '') { on = replaceAsExpected(path: on).replaceAll('\\\\', '\\'); var current = Directory('lib'); final list = current.listSync(recursive: true, followLinks: false); - final contains = list.firstWhere((element) { - if (element is File) { - return false; - } - - return '${element.path}${p.separator}'.contains('$on${p.separator}'); - }, orElse: () { - return list.firstWhere((element) { - //Fix erro ao encontrar arquivo com nome + final contains = list.firstWhere( + (element) { if (element is File) { return false; } - return element.path.contains(on!); - }, orElse: () { - throw CliException(LocaleKeys.error_folder_not_found.trArgs([on])); - }); - }); + + return '${element.path}${p.separator}'.contains('$on${p.separator}'); + }, + orElse: () { + return list.firstWhere( + (element) { + //Fix erro ao encontrar arquivo com nome + if (element is File) { + return false; + } + return element.path.contains(on!); + }, + orElse: () { + throw CliException( + LocaleKeys.error_folder_not_found.trArgs([on]), + ); + }, + ); + }, + ); return FileModel( name: name, @@ -99,8 +114,12 @@ class Structure { } } - static String? getPathWithName(String? firstPath, String secondPath, - {bool createWithWrappedFolder = false, required String? folderName}) { + static String? getPathWithName( + String? firstPath, + String secondPath, { + bool createWithWrappedFolder = false, + required String? folderName, + }) { late String betweenPaths; if (Platform.isWindows) { betweenPaths = '\\\\'; diff --git a/lib/exception_handler/exception_handler.dart b/lib/exception_handler/exception_handler.dart index f0140f70..4eb1be41 100644 --- a/lib/exception_handler/exception_handler.dart +++ b/lib/exception_handler/exception_handler.dart @@ -1,9 +1,9 @@ import 'dart:io'; -import '../common/utils/logger/log_utils.dart'; -import '../core/internationalization.dart'; -import '../core/locales.g.dart'; -import 'exceptions/cli_exception.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; class ExceptionHandler { void handle(dynamic e) { diff --git a/lib/extensions/dart_code.dart b/lib/extensions/dart_code.dart index 3bef7bc2..1b22b16e 100644 --- a/lib/extensions/dart_code.dart +++ b/lib/extensions/dart_code.dart @@ -3,8 +3,8 @@ import 'dart:io'; import 'package:get_cli/functions/create/create_single_file.dart'; import 'package:get_cli/functions/formatter_dart_file/frommatter_dart_file.dart'; -import '../exception_handler/exceptions/cli_exception.dart'; -import 'string.dart'; +import 'package:get_cli/exception_handler/exceptions/cli_exception.dart'; +import 'package:get_cli/extensions/string.dart'; extension DartCodeExt on File { /// Append the content of dart class @@ -35,7 +35,8 @@ extension DartCodeExt on File { throw CliException('The class $className is not found in the file $path'); } else if (matches.length > 1) { throw CliException( - 'The class $className is found more than once in the file $path'); + 'The class $className is found more than once in the file $path', + ); } var match = matches.first; content = content.insert(match.end - 1, value); diff --git a/lib/functions/binding/add_dependencies.dart b/lib/functions/binding/add_dependencies.dart index b5657de5..8bc3eff7 100644 --- a/lib/functions/binding/add_dependencies.dart +++ b/lib/functions/binding/add_dependencies.dart @@ -2,11 +2,11 @@ import 'dart:io'; import 'package:recase/recase.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import '../create/create_single_file.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; /// /// Add a new dependency to bindings @@ -59,7 +59,9 @@ void addDependencyToBinding(String path, String controllerName, String import) { () => ${controllerName.pascalCase}Controller(), );'''); writeFile(file.path, lines.join('\n'), overwrite: true, logger: false); - LogService.success(LocaleKeys.sucess_add_controller_in_bindings - .trArgs([controllerName.pascalCase, path])); + LogService.success( + LocaleKeys.sucess_add_controller_in_bindings + .trArgs([controllerName.pascalCase, path]), + ); } } diff --git a/lib/functions/binding/find_bindings.dart b/lib/functions/binding/find_bindings.dart index 2cc8dce9..abd47cda 100644 --- a/lib/functions/binding/find_bindings.dart +++ b/lib/functions/binding/find_bindings.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:path/path.dart'; import 'package:recase/recase.dart'; -import '../../core/structure.dart'; +import 'package:get_cli/core/structure.dart'; String findBindingFromName(String path, String name) { path = Structure.replaceAsExpected(path: path); diff --git a/lib/functions/create/create_main.dart b/lib/functions/create/create_main.dart index aa43f349..dc283548 100644 --- a/lib/functions/create/create_main.dart +++ b/lib/functions/create/create_main.dart @@ -1,10 +1,10 @@ import 'dart:io'; -import '../../common/menu/menu.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import '../../core/structure.dart'; +import 'package:get_cli/common/menu/menu.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; Future createMain() async { var newFileModel = Structure.model('', 'init', false); @@ -15,8 +15,10 @@ Future createMain() async { /// apenas quem chama essa função é o create project e o init, /// ambas funções iniciam um projeto e sobrescreve os arquivos - final menu = Menu([LocaleKeys.options_yes.tr, LocaleKeys.options_no.tr], - title: LocaleKeys.ask_lib_not_empty.tr); + final menu = Menu( + [LocaleKeys.options_yes.tr, LocaleKeys.options_no.tr], + title: LocaleKeys.ask_lib_not_empty.tr, + ); final result = menu.choose(); if (result.index == 1) { LogService.info(LocaleKeys.info_no_file_overwritten.tr); diff --git a/lib/functions/create/create_navigation.dart b/lib/functions/create/create_navigation.dart index 29b10c5b..844e0df6 100644 --- a/lib/functions/create/create_navigation.dart +++ b/lib/functions/create/create_navigation.dart @@ -3,21 +3,24 @@ import 'dart:io'; import 'package:recase/recase.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import '../../core/structure.dart'; -import '../../samples/impl/arctekko/arc_navigation.dart'; -import '../formatter_dart_file/frommatter_dart_file.dart'; -import 'create_single_file.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/samples/impl/arctekko/arc_navigation.dart'; +import 'package:get_cli/functions/formatter_dart_file/frommatter_dart_file.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; void createNavigation() { ArcNavigationSample().create(skipFormatter: true); } void addNavigation(String name) { - var navigationFile = File(Structure.replaceAsExpected( - path: 'lib/infrastructure/navigation/navigation.dart')); + var navigationFile = File( + Structure.replaceAsExpected( + path: 'lib/infrastructure/navigation/navigation.dart', + ), + ); List lines; @@ -46,9 +49,16 @@ void addNavigation(String name) { binding: ${name.pascalCase}ControllerBinding(), ), '''); - writeFile(navigationFile.path, lines.join('\n'), - overwrite: true, logger: false); + writeFile( + navigationFile.path, + lines.join('\n'), + overwrite: true, + logger: false, + ); - LogService.success(Translation( - LocaleKeys.sucess_navigation_added.trArgs([name.pascalCase]))); + LogService.success( + Translation( + LocaleKeys.sucess_navigation_added.trArgs([name.pascalCase]), + ), + ); } diff --git a/lib/functions/create/create_single_file.dart b/lib/functions/create/create_single_file.dart index 17deb720..da830ba2 100644 --- a/lib/functions/create/create_single_file.dart +++ b/lib/functions/create/create_single_file.dart @@ -2,35 +2,49 @@ import 'dart:io'; import 'package:path/path.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import '../../core/structure.dart'; -import '../../samples/interface/sample_interface.dart'; -import '../sorter_imports/sort.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; +import 'package:get_cli/functions/sorter_imports/sort.dart'; -File handleFileCreate(String name, String command, String on, bool extraFolder, - Sample sample, String folderName, - [String sep = '_']) { +File handleFileCreate( + String name, + String command, + String on, + bool extraFolder, + Sample sample, + String folderName, [ + String sep = '_', +]) { folderName = folderName; /* if (folderName.isNotEmpty) { extraFolder = PubspecUtils.extraFolder ?? extraFolder; } */ - final fileModel = Structure.model(name, command, extraFolder, - on: on, folderName: folderName); + final fileModel = Structure.model( + name, + command, + extraFolder, + on: on, + folderName: folderName, + ); var path = '${fileModel.path}$sep${fileModel.commandName}.dart'; sample.path = path; return sample.create(); } /// Create or edit the contents of a file -File writeFile(String path, String content, - {bool overwrite = false, - bool skipFormatter = false, - bool logger = true, - bool skipRename = false, - bool useRelativeImport = false}) { +File writeFile( + String path, + String content, { + bool overwrite = false, + bool skipFormatter = false, + bool logger = true, + bool skipRename = false, + bool useRelativeImport = false, +}) { var newFile = File(Structure.replaceAsExpected(path: path)); if (!newFile.existsSync() || overwrite) { @@ -46,7 +60,8 @@ File writeFile(String path, String content, } on Exception catch (_) { if (newFile.existsSync()) { LogService.info( - LocaleKeys.error_invalid_dart.trArgs([newFile.path])); + LocaleKeys.error_invalid_dart.trArgs([newFile.path]), + ); } rethrow; } @@ -78,8 +93,10 @@ File writeFile(String path, String content, /// Replace the file name separator String replacePathTypeSeparator(String path, String separator) { if (separator.isNotEmpty) { - var index = path.indexOf(RegExp(r'controller.dart|model.dart|provider.dart|' - 'binding.dart|view.dart|screen.dart|widget.dart|repository.dart')); + var index = path.indexOf( + RegExp(r'controller.dart|model.dart|provider.dart|' + 'binding.dart|view.dart|screen.dart|widget.dart|repository.dart'), + ); if (index != -1) { var chars = path.split(''); index--; diff --git a/lib/functions/exports_files/add_export.dart b/lib/functions/exports_files/add_export.dart index 3db0ba01..c5cadfab 100644 --- a/lib/functions/exports_files/add_export.dart +++ b/lib/functions/exports_files/add_export.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import '../../core/structure.dart'; +import 'package:get_cli/core/structure.dart'; void addExport(String path, String line) { var newFile = File(Structure.replaceAsExpected(path: path)); diff --git a/lib/functions/find_file/find_file_by_name.dart b/lib/functions/find_file/find_file_by_name.dart index 48b329fe..7f5a7072 100644 --- a/lib/functions/find_file/find_file_by_name.dart +++ b/lib/functions/find_file/find_file_by_name.dart @@ -6,13 +6,16 @@ import 'package:path/path.dart'; File findFileByName(String name) { var current = Directory('lib'); final list = current.listSync(recursive: true, followLinks: false); - var contains = list.firstWhere((element) { - if (element is File) { - return basename(element.path) == name; - } - return false; - }, orElse: () { - return File(''); - }); + var contains = list.firstWhere( + (element) { + if (element is File) { + return basename(element.path) == name; + } + return false; + }, + orElse: () { + return File(''); + }, + ); return contains as File; } diff --git a/lib/functions/find_file/find_folder_by_directory.dart b/lib/functions/find_file/find_folder_by_directory.dart index c0999393..ff6d4f86 100644 --- a/lib/functions/find_file/find_folder_by_directory.dart +++ b/lib/functions/find_file/find_folder_by_directory.dart @@ -5,14 +5,17 @@ Directory? findFolderByName(String name) { var current = Directory('lib'); final List list = current.listSync(recursive: true, followLinks: false); - var contains = list.firstWhere((element) { - //Fix erro ao encontrar arquivo com nome - if (element is Directory) { - return element.path.contains(name); - } - return false; - }, orElse: () { - return null; - }); + var contains = list.firstWhere( + (element) { + //Fix erro ao encontrar arquivo com nome + if (element is Directory) { + return element.path.contains(name); + } + return false; + }, + orElse: () { + return null; + }, + ); return contains as Directory?; } diff --git a/lib/functions/is_url/is_url.dart b/lib/functions/is_url/is_url.dart index ca1256b6..42746fd6 100644 --- a/lib/functions/is_url/is_url.dart +++ b/lib/functions/is_url/is_url.dart @@ -1,5 +1,7 @@ -bool isURL(String s) => _hasMatch(s, - r"^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$"); +bool isURL(String s) => _hasMatch( + s, + r"^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$", + ); bool _hasMatch(String value, String pattern) { return RegExp(pattern).hasMatch(value); diff --git a/lib/functions/path/replace_to_relative.dart b/lib/functions/path/replace_to_relative.dart index 58942282..4b503b56 100644 --- a/lib/functions/path/replace_to_relative.dart +++ b/lib/functions/path/replace_to_relative.dart @@ -1,6 +1,6 @@ import 'package:path/path.dart'; -import '../../core/structure.dart'; +import 'package:get_cli/core/structure.dart'; /// Replace the import with a relative path import. String replaceToRelativeImport(String import, String otherFile) { diff --git a/lib/functions/replace_vars/replace_vars.dart b/lib/functions/replace_vars/replace_vars.dart index 77a60d24..9e773f4a 100644 --- a/lib/functions/replace_vars/replace_vars.dart +++ b/lib/functions/replace_vars/replace_vars.dart @@ -1,6 +1,6 @@ import 'package:recase/recase.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; String replaceVars(String content, String name) { return content diff --git a/lib/functions/routes/arc_add_route.dart b/lib/functions/routes/arc_add_route.dart index bd310212..0643fdb8 100644 --- a/lib/functions/routes/arc_add_route.dart +++ b/lib/functions/routes/arc_add_route.dart @@ -3,18 +3,21 @@ import 'dart:io'; import 'package:recase/recase.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import '../../core/structure.dart'; -import '../../samples/impl/arctekko/arc_routes.dart'; -import '../create/create_navigation.dart'; -import '../create/create_single_file.dart'; -import '../formatter_dart_file/frommatter_dart_file.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/core/structure.dart'; +import 'package:get_cli/samples/impl/arctekko/arc_routes.dart'; +import 'package:get_cli/functions/create/create_navigation.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/formatter_dart_file/frommatter_dart_file.dart'; void arcAddRoute(String nameRoute) { - var routesFile = File(Structure.replaceAsExpected( - path: 'lib/infrastructure/navigation/routes.dart')); + var routesFile = File( + Structure.replaceAsExpected( + path: 'lib/infrastructure/navigation/routes.dart', + ), + ); var lines = []; if (!routesFile.existsSync()) { ArcRouteSample(nameRoute.snakeCase.toUpperCase()).create(); @@ -39,7 +42,8 @@ void arcAddRoute(String nameRoute) { writeFile(routesFile.path, lines.join('\n'), overwrite: true); LogService.success( - Translation(LocaleKeys.sucess_route_created).trArgs([nameRoute])); + Translation(LocaleKeys.sucess_route_created).trArgs([nameRoute]), + ); addNavigation(nameRoute); } diff --git a/lib/functions/routes/get_add_route.dart b/lib/functions/routes/get_add_route.dart index 01744cab..444e07a6 100644 --- a/lib/functions/routes/get_add_route.dart +++ b/lib/functions/routes/get_add_route.dart @@ -2,15 +2,15 @@ import 'dart:io'; import 'package:recase/recase.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import '../../extensions.dart'; -import '../../samples/impl/get_route.dart'; -import '../find_file/find_file_by_name.dart'; -import 'get_app_pages.dart'; -import 'get_support_children.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/extensions.dart'; +import 'package:get_cli/samples/impl/get_route.dart'; +import 'package:get_cli/functions/find_file/find_file_by_name.dart'; +import 'package:get_cli/functions/routes/get_app_pages.dart'; +import 'package:get_cli/functions/routes/get_support_children.dart'; /// This command will create the route to the new page void addRoute(String nameRoute, String bindingDir, String viewDir) { @@ -52,7 +52,8 @@ void addRoute(String nameRoute, String bindingDir, String viewDir) { addAppPage(nameRoute, bindingDir, viewDir); LogService.success( - Translation(LocaleKeys.sucess_route_created).trArgs([nameRoute])); + Translation(LocaleKeys.sucess_route_created).trArgs([nameRoute]), + ); } /// Create routes from the path diff --git a/lib/functions/routes/get_app_pages.dart b/lib/functions/routes/get_app_pages.dart index 8806600b..4b648022 100644 --- a/lib/functions/routes/get_app_pages.dart +++ b/lib/functions/routes/get_app_pages.dart @@ -3,13 +3,13 @@ import 'dart:io'; import 'package:recase/recase.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../../samples/impl/get_app_pages.dart'; -import '../create/create_single_file.dart'; -import '../find_file/find_file_by_name.dart'; -import '../formatter_dart_file/frommatter_dart_file.dart'; -import 'get_support_children.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/samples/impl/get_app_pages.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/find_file/find_file_by_name.dart'; +import 'package:get_cli/functions/formatter_dart_file/frommatter_dart_file.dart'; +import 'package:get_cli/functions/routes/get_support_children.dart'; void addAppPage(String name, String bindingDir, String viewDir) { var appPagesFile = findFileByName('app_pages.dart'); @@ -42,9 +42,10 @@ void addAppPage(String name, String bindingDir, String viewDir) { var onPageIndex = -1; while (pathSplit.isNotEmpty && onPageIndex == -1) { onPageIndex = lines.indexWhere( - (element) => element - .contains('_Paths.${pathSplit.last.snakeCase.toUpperCase()},'), - indexRoutes); + (element) => element + .contains('_Paths.${pathSplit.last.snakeCase.toUpperCase()},'), + indexRoutes, + ); pathSplit.removeLast(); } @@ -57,9 +58,11 @@ void addAppPage(String name, String bindingDir, String viewDir) { if (onPageStartIndex != -1) { onPageEndIndex = lines.indexWhere( - (element) => element.startsWith( - '${_getTabs(_countTabs(lines[onPageStartIndex]))}),'), - onPageStartIndex); + (element) => element.startsWith( + '${_getTabs(_countTabs(lines[onPageStartIndex]))}),', + ), + onPageStartIndex, + ); } else { _logInvalidFormart(); } @@ -77,9 +80,11 @@ void addAppPage(String name, String bindingDir, String viewDir) { } else { var indexChildrenEnd = -1; indexChildrenEnd = lines.indexWhere( - (element) => element.startsWith( - '${_getTabs(_countTabs(lines[onPageStartIndex]) + 1)}],'), - onPageStartIndex); + (element) => element.startsWith( + '${_getTabs(_countTabs(lines[onPageStartIndex]) + 1)}],', + ), + onPageStartIndex, + ); if (indexChildrenEnd != -1) { index = indexChildrenEnd; tabEspaces = _countTabs(lines[onPageStartIndex]) + 2; @@ -132,8 +137,9 @@ int _countTabs(String line) { /// log invalid format file void _logInvalidFormart() { LogService.info( - 'the app_pages.dart file does not meet the ' - 'expected format, fails to create children pages', - false, - false); + 'the app_pages.dart file does not meet the ' + 'expected format, fails to create children pages', + false, + false, + ); } diff --git a/lib/functions/routes/get_support_children.dart b/lib/functions/routes/get_support_children.dart index d1de57a6..b32229cf 100644 --- a/lib/functions/routes/get_support_children.dart +++ b/lib/functions/routes/get_support_children.dart @@ -1,5 +1,5 @@ -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../find_file/find_file_by_name.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/functions/find_file/find_file_by_name.dart'; /// Checks whether the installed version of get supports child routes bool get supportChildrenRoutes { diff --git a/lib/functions/sorter_imports/sort.dart b/lib/functions/sorter_imports/sort.dart index 8c7c8005..409f8982 100644 --- a/lib/functions/sorter_imports/sort.dart +++ b/lib/functions/sorter_imports/sort.dart @@ -1,10 +1,10 @@ import 'dart:convert'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../../extensions.dart'; -import '../create/create_single_file.dart'; -import '../formatter_dart_file/frommatter_dart_file.dart'; -import '../path/replace_to_relative.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/extensions.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; +import 'package:get_cli/functions/formatter_dart_file/frommatter_dart_file.dart'; +import 'package:get_cli/functions/path/replace_to_relative.dart'; /// Sort imports from a dart file String sortImports( @@ -109,7 +109,7 @@ String sortImports( '', ...exports, '', - ...contentLines + ...contentLines, ]); return formatterDartFile(sortedLines.join('\n')); diff --git a/lib/functions/version/version_update.dart b/lib/functions/version/version_update.dart index 8e1859eb..29990309 100644 --- a/lib/functions/version/version_update.dart +++ b/lib/functions/version/version_update.dart @@ -2,14 +2,14 @@ import 'dart:io'; import 'package:version/version.dart'; -import '../../cli_config/cli_config.dart'; -import '../../common/utils/logger/log_utils.dart'; -import '../../common/utils/pub_dev/pub_dev_api.dart'; -import '../../common/utils/pubspec/pubspec_lock.dart'; -import '../../core/internationalization.dart'; -import '../../core/locales.g.dart'; -import 'check_dev_version.dart'; -import 'print_get_cli.dart'; +import 'package:get_cli/cli_config/cli_config.dart'; +import 'package:get_cli/common/utils/logger/log_utils.dart'; +import 'package:get_cli/common/utils/pub_dev/pub_dev_api.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_lock.dart'; +import 'package:get_cli/core/internationalization.dart'; +import 'package:get_cli/core/locales.g.dart'; +import 'package:get_cli/functions/version/check_dev_version.dart'; +import 'package:get_cli/functions/version/print_get_cli.dart'; void checkForUpdate() async { if (!CliConfig.updateIsCheckingToday()) { @@ -25,18 +25,21 @@ void checkForUpdate() async { final needsUpdate = v1.compareTo(v2); // needs update. if (needsUpdate == 1) { - LogService.info(Translation( - LocaleKeys.info_update_available.trArgs([versionInstalled])) - .toString()); + LogService.info( + Translation( + LocaleKeys.info_update_available.trArgs([versionInstalled]), + ).toString(), + ); //await versionCommand(); printGetCli(); final String codeSample = LogService.code('get update'); LogService.info( - '${LocaleKeys.info_update_available2.trArgs([ - versionInPubDev - ])}${' $codeSample'}', - false, - true); + '${LocaleKeys.info_update_available2.trArgs([ + versionInPubDev, + ])}${' $codeSample'}', + false, + true, + ); } }); }); diff --git a/lib/samples/impl/analysis_options.dart b/lib/samples/impl/analysis_options.dart index 51f2169e..5c71b4fd 100644 --- a/lib/samples/impl/analysis_options.dart +++ b/lib/samples/impl/analysis_options.dart @@ -1,11 +1,12 @@ -import '../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from analysis_options.yaml file creation. class AnalysisOptionsSample extends Sample { String include; - AnalysisOptionsSample( - {String path = 'analysis_options.yaml', this.include = ''}) - : super(path, overwrite: true); + AnalysisOptionsSample({ + String path = 'analysis_options.yaml', + this.include = '', + }) : super(path, overwrite: true); @override String get content => '''$include diff --git a/lib/samples/impl/arctekko/arc_main.dart b/lib/samples/impl/arctekko/arc_main.dart index 4e8b6400..f3853d14 100644 --- a/lib/samples/impl/arctekko/arc_main.dart +++ b/lib/samples/impl/arctekko/arc_main.dart @@ -1,4 +1,4 @@ -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; class ArcMainSample extends Sample { ArcMainSample() : super('lib/main.dart', overwrite: true); diff --git a/lib/samples/impl/arctekko/arc_navigation.dart b/lib/samples/impl/arctekko/arc_navigation.dart index a68f0637..9d6301d7 100644 --- a/lib/samples/impl/arctekko/arc_navigation.dart +++ b/lib/samples/impl/arctekko/arc_navigation.dart @@ -1,9 +1,9 @@ -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; class ArcNavigationSample extends Sample { - ArcNavigationSample( - {String path = 'lib/infrastructure/navigation/navigation.dart'}) - : super(path); + ArcNavigationSample({ + String path = 'lib/infrastructure/navigation/navigation.dart', + }) : super(path); @override String get content => '''import 'package:flutter/material.dart'; diff --git a/lib/samples/impl/arctekko/arc_routes.dart b/lib/samples/impl/arctekko/arc_routes.dart index 2a8e4416..adbddc43 100644 --- a/lib/samples/impl/arctekko/arc_routes.dart +++ b/lib/samples/impl/arctekko/arc_routes.dart @@ -1,10 +1,11 @@ -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; class ArcRouteSample extends Sample { String initial; - ArcRouteSample(this.initial, - {String path = 'lib/infrastructure/navigation/routes.dart'}) - : super(path); + ArcRouteSample( + this.initial, { + String path = 'lib/infrastructure/navigation/routes.dart', + }) : super(path); @override String get content => ''' class Routes { diff --git a/lib/samples/impl/arctekko/arc_screen.dart b/lib/samples/impl/arctekko/arc_screen.dart index 5f5307ef..7a88e98a 100644 --- a/lib/samples/impl/arctekko/arc_screen.dart +++ b/lib/samples/impl/arctekko/arc_screen.dart @@ -1,13 +1,17 @@ import 'package:recase/recase.dart'; -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; //Usei arc pra fazer referencia a clean do katekko class ArcScreenSample extends Sample { late String fileName; bool isExample; - ArcScreenSample(super.path, String fileName, - {super.overwrite, this.isExample = false}); + ArcScreenSample( + super.path, + String fileName, { + super.overwrite, + this.isExample = false, + }); @override String get content => !isExample diff --git a/lib/samples/impl/arctekko/config_example.dart b/lib/samples/impl/arctekko/config_example.dart index b057786f..ea39154b 100644 --- a/lib/samples/impl/arctekko/config_example.dart +++ b/lib/samples/impl/arctekko/config_example.dart @@ -1,4 +1,4 @@ -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; class ConfigExampleSample extends Sample { ConfigExampleSample({String path = 'lib/config.dart'}) : super(path); diff --git a/lib/samples/impl/generate_locales.dart b/lib/samples/impl/generate_locales.dart index 1599e4d7..f3dd6e31 100644 --- a/lib/samples/impl/generate_locales.dart +++ b/lib/samples/impl/generate_locales.dart @@ -1,12 +1,15 @@ -import '../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; class GenerateLocalesSample extends Sample { final String _translationsKeys; final String _keys; final String _locales; - GenerateLocalesSample(this._keys, this._locales, this._translationsKeys, - {String path = 'lib/generated/locales.g.dart'}) - : super(path, overwrite: true); + GenerateLocalesSample( + this._keys, + this._locales, + this._translationsKeys, { + String path = 'lib/generated/locales.g.dart', + }) : super(path, overwrite: true); @override String get content => ''' diff --git a/lib/samples/impl/get_app_pages.dart b/lib/samples/impl/get_app_pages.dart index 972a2fcb..a1ce1b8a 100644 --- a/lib/samples/impl/get_app_pages.dart +++ b/lib/samples/impl/get_app_pages.dart @@ -1,12 +1,13 @@ -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../interface/sample_interface.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from [app_pages] file creation. class AppPagesSample extends Sample { String initial; - AppPagesSample( - {String path = 'lib/app/routes/app_pages.dart', this.initial = 'HOME'}) - : super(path); + AppPagesSample({ + String path = 'lib/app/routes/app_pages.dart', + this.initial = 'HOME', + }) : super(path); final import = PubspecUtils.getPackageImport; String get _initialRoute => initial.isNotEmpty ? '\nstatic const INITIAL = Routes.$initial;' : ''; diff --git a/lib/samples/impl/get_binding.dart b/lib/samples/impl/get_binding.dart index fe2fcd1a..31ecc699 100644 --- a/lib/samples/impl/get_binding.dart +++ b/lib/samples/impl/get_binding.dart @@ -1,7 +1,7 @@ import 'package:recase/recase.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../interface/sample_interface.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from Module_Binding file creation. class BindingSample extends Sample { @@ -10,9 +10,14 @@ class BindingSample extends Sample { final String _bindingName; final bool _isServer; - BindingSample(super.path, this._fileName, this._bindingName, - this._controllerDir, this._isServer, - {super.overwrite}); + BindingSample( + super.path, + this._fileName, + this._bindingName, + this._controllerDir, + this._isServer, { + super.overwrite, + }); String get _import => _isServer ? "import 'package:get_server/get_server.dart';" diff --git a/lib/samples/impl/get_controller.dart b/lib/samples/impl/get_controller.dart index 1a454720..d0cb0323 100644 --- a/lib/samples/impl/get_controller.dart +++ b/lib/samples/impl/get_controller.dart @@ -1,13 +1,17 @@ import 'package:recase/recase.dart'; -import '../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from Module_Controller file creation. class ControllerSample extends Sample { final String _fileName; final bool _isServer; - ControllerSample(super.path, this._fileName, this._isServer, - {super.overwrite}); + ControllerSample( + super.path, + this._fileName, + this._isServer, { + super.overwrite, + }); @override String get content => _isServer ? serverController : flutterController; diff --git a/lib/samples/impl/get_provider.dart b/lib/samples/impl/get_provider.dart index f1e8d3d6..4365e9b9 100644 --- a/lib/samples/impl/get_provider.dart +++ b/lib/samples/impl/get_provider.dart @@ -1,7 +1,7 @@ import 'package:recase/recase.dart'; -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../interface/sample_interface.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from Provider file creation. class ProviderSample extends Sample { @@ -11,13 +11,14 @@ class ProviderSample extends Sample { final String modelPath; String? _namePascal; String? _nameLower; - ProviderSample(this._fileName, - {bool overwrite = false, - this.createEndpoints = false, - this.modelPath = '', - this.isServer = false, - String path = ''}) - : super(path, overwrite: overwrite) { + ProviderSample( + this._fileName, { + bool overwrite = false, + this.createEndpoints = false, + this.modelPath = '', + this.isServer = false, + String path = '', + }) : super(path, overwrite: overwrite) { _namePascal = _fileName.pascalCase; _nameLower = _fileName.toLowerCase(); } @@ -41,7 +42,7 @@ $_defaultEndpoint} '''; String get _defaultEndpoint => createEndpoints - ? ''' + ? ''' \tFuture<$_namePascal?> get$_namePascal(int id) async { \t\tfinal response = await get('$_nameLower/\$id'); \t\treturn response.body; diff --git a/lib/samples/impl/get_route.dart b/lib/samples/impl/get_route.dart index 171fdc95..a07fe4bd 100644 --- a/lib/samples/impl/get_route.dart +++ b/lib/samples/impl/get_route.dart @@ -1,4 +1,4 @@ -import '../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from [app_routes] file creation. class RouteSample extends Sample { diff --git a/lib/samples/impl/get_server/pubspec.dart b/lib/samples/impl/get_server/pubspec.dart index 7b66c8c3..e76b850d 100644 --- a/lib/samples/impl/get_server/pubspec.dart +++ b/lib/samples/impl/get_server/pubspec.dart @@ -1,4 +1,4 @@ -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from pubspec.yaml file creation. class GetServerPubspecSample extends Sample { diff --git a/lib/samples/impl/get_view.dart b/lib/samples/impl/get_view.dart index 5d966fdc..fe66db71 100644 --- a/lib/samples/impl/get_view.dart +++ b/lib/samples/impl/get_view.dart @@ -1,5 +1,5 @@ -import '../../common/utils/pubspec/pubspec_utils.dart'; -import '../interface/sample_interface.dart'; +import 'package:get_cli/common/utils/pubspec/pubspec_utils.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; /// [Sample] file from Module_View file creation. class GetViewSample extends Sample { @@ -8,9 +8,14 @@ class GetViewSample extends Sample { final String _controller; final bool _isServer; - GetViewSample(super.path, this._viewName, this._controller, - this._controllerDir, this._isServer, - {super.overwrite}); + GetViewSample( + super.path, + this._viewName, + this._controller, + this._controllerDir, + this._isServer, { + super.overwrite, + }); String get import => _controllerDir.isNotEmpty ? '''import 'package:${PubspecUtils.projectName}/$_controllerDir';''' diff --git a/lib/samples/impl/getx_pattern/get_main.dart b/lib/samples/impl/getx_pattern/get_main.dart index 233c6616..2f5629a1 100644 --- a/lib/samples/impl/getx_pattern/get_main.dart +++ b/lib/samples/impl/getx_pattern/get_main.dart @@ -1,4 +1,4 @@ -import '../../interface/sample_interface.dart'; +import 'package:get_cli/samples/interface/sample_interface.dart'; class GetXMainSample extends Sample { final bool? isServer; diff --git a/lib/samples/interface/sample_interface.dart b/lib/samples/interface/sample_interface.dart index 28344d1a..e9ba10b2 100644 --- a/lib/samples/interface/sample_interface.dart +++ b/lib/samples/interface/sample_interface.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import '../../functions/create/create_single_file.dart'; +import 'package:get_cli/functions/create/create_single_file.dart'; /// [Sample] is the Base class in which the files for each command /// will be built. diff --git a/test/path/test.dart b/test/path/test.dart index d8e6eb4e..59ae35df 100644 --- a/test/path/test.dart +++ b/test/path/test.dart @@ -6,7 +6,9 @@ void main() { var import = "import 'package:ponto_facil/app/modules/home/views/home.view.dart';"; var otherFile = 'lib/app/data/file.dart'; - expect(replaceToRelativeImport(import, otherFile), - equals("import '../modules/home/views/home.view.dart';")); + expect( + replaceToRelativeImport(import, otherFile), + equals("import '../modules/home/views/home.view.dart';"), + ); }); }