diff --git a/lib/src/commands/create/create_app_command.dart b/lib/src/commands/create/create_app_command.dart index f6064ed..4fd9b8c 100644 --- a/lib/src/commands/create/create_app_command.dart +++ b/lib/src/commands/create/create_app_command.dart @@ -1,7 +1,9 @@ import 'dart:async'; +import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:stacked_cli/src/constants/command_constants.dart'; +import 'package:stacked_cli/src/constants/config_constants.dart'; import 'package:stacked_cli/src/constants/message_constants.dart'; import 'package:stacked_cli/src/locator.dart'; import 'package:stacked_cli/src/services/analytics_service.dart'; @@ -10,6 +12,7 @@ import 'package:stacked_cli/src/services/config_service.dart'; import 'package:stacked_cli/src/services/file_service.dart'; import 'package:stacked_cli/src/services/process_service.dart'; import 'package:stacked_cli/src/services/template_service.dart'; +import 'package:stacked_cli/src/templates/template_constants.dart'; class CreateAppCommand extends Command { final _cLog = locator(); @@ -24,7 +27,7 @@ class CreateAppCommand extends Command { 'Creates a stacked application with all the basics setup'; @override - String get name => 'app'; + String get name => kTemplateNameApp; CreateAppCommand() { argParser.addFlag( @@ -50,34 +53,46 @@ class CreateAppCommand extends Command { defaultsTo: 'mobile', help: kCommandHelpCreateAppTemplate, ); + + argParser.addOption( + ksConfigPath, + abbr: 'c', + help: kCommandHelpCreateAppConfigFile, + ); } @override Future run() async { - await _configService.loadConfig(); - final appName = argResults!.rest.first; - final appNameWithoutPath = appName.split('/').last; - final templateType = argResults![ksTemplateType]; - - unawaited(_analyticsService.createAppEvent(name: appNameWithoutPath)); - _processService.formattingLineLength = argResults![ksLineLength]; - await _processService.runCreateApp(appName: appName); - - _cLog.stackedOutput(message: 'Add Stacked Magic ... ', isBold: true); - - await _templateService.renderTemplate( - templateName: name, - name: appNameWithoutPath, - verbose: true, - outputPath: appName, - useBuilder: argResults![ksV1] ?? _configService.v1, - templateType: templateType, - ); + try { + await _configService.loadConfig(path: argResults![ksConfigPath]); + + final appName = argResults!.rest.first; + final appNameWithoutPath = appName.split('/').last; + final templateType = argResults![ksTemplateType]; + + unawaited(_analyticsService.createAppEvent(name: appNameWithoutPath)); + _processService.formattingLineLength = argResults![ksLineLength]; + await _processService.runCreateApp(appName: appName); + + _cLog.stackedOutput(message: 'Add Stacked Magic ... ', isBold: true); + + await _templateService.renderTemplate( + templateName: name, + name: appNameWithoutPath, + verbose: true, + outputPath: appName, + useBuilder: argResults![ksV1] ?? _configService.v1, + templateType: templateType, + ); - await _processService.runPubGet(appName: appName); - await _processService.runBuildRunner(appName: appName); - await _processService.runFormat(appName: appName); - await _clean(appName: appName); + _replaceConfigFile(appName: appName); + await _processService.runPubGet(appName: appName); + await _processService.runBuildRunner(appName: appName); + await _processService.runFormat(appName: appName); + await _clean(appName: appName); + } catch (e) { + _cLog.warn(message: e.toString()); + } } /// Cleans the project. @@ -109,4 +124,15 @@ class CreateAppCommand extends Command { _cLog.stackedOutput(message: 'Project cleaned.'); } + + /// Replaces configuration file in the project created. + /// + /// If has NO custom config, does nothing. + void _replaceConfigFile({required String appName}) { + if (!_configService.hasCustomConfig) return; + + File('$appName/$kConfigFileName').writeAsStringSync( + _configService.exportConfig(), + ); + } } diff --git a/lib/src/constants/command_constants.dart b/lib/src/constants/command_constants.dart index 8899bfd..d243c75 100644 --- a/lib/src/constants/command_constants.dart +++ b/lib/src/constants/command_constants.dart @@ -27,6 +27,7 @@ const String ksActivate = 'activate'; const String ksStackedCli = 'stacked_cli'; const String ksAnalyze = 'analyze'; const String ksModel = 'model'; +const String ksConfigPath = 'config-path'; const String ksWatch = 'watch'; /// A list of strings that are used to run the run build_runner diff --git a/lib/src/constants/config_constants.dart b/lib/src/constants/config_constants.dart index 11555b6..bb2ba74 100644 --- a/lib/src/constants/config_constants.dart +++ b/lib/src/constants/config_constants.dart @@ -1,2 +1,5 @@ -/// Defines the filename of the stacked configuration file +/// Defines default filename of the stacked configuration file const String kConfigFileName = 'stacked.json'; + +/// Defines default message for current version +const String currentVersionNotAvailable = 'Current Version Not Available'; diff --git a/lib/src/constants/message_constants.dart b/lib/src/constants/message_constants.dart index 3805364..98dc1d8 100644 --- a/lib/src/constants/message_constants.dart +++ b/lib/src/constants/message_constants.dart @@ -44,6 +44,9 @@ const String kCommandHelpLineLength = const String kCommandHelpCreateAppTemplate = 'Selects the type of starter template to use when creating a new app. One oriented for mobile first or web first'; +const String kCommandHelpCreateAppConfigFile = + 'Sets the file path for the custom config'; + const String kCommandHelpCreateViewTemplate = 'Selects the type of view to create instead of the default empty view'; @@ -63,10 +66,13 @@ const String kCommandHelpDeleteConflictingOutputs = 'Assume conflicting outputs in the users package are from previous builds, and skip the user prompt that would usually be provided.'; const String kConfigFileNotFound = - 'No stacked.json file found. Default stacked values will be used.'; + 'No configuration file found. Default Stacked values will be used.'; + +const String kConfigFileNotFoundRetry = + 'No configuration file found. Please, correct the config path passed as argument.'; const String kConfigFileMalformed = - 'Your stacked.json is malformed. Double check to make sure you have properly formatted json.'; + 'Your configuration file is malformed. Double check to make sure you have properly formatted json.'; const String kDeprecatedConfigFileName = ''' Stacked config file should be renamed from "stacked.config.json" to "stacked.json". Stacked cli will not read "stacked.config.json" files after the next minor release. diff --git a/lib/src/exceptions/config_file_not_found_exception.dart b/lib/src/exceptions/config_file_not_found_exception.dart index 5ddf000..88747d5 100644 --- a/lib/src/exceptions/config_file_not_found_exception.dart +++ b/lib/src/exceptions/config_file_not_found_exception.dart @@ -1,6 +1,7 @@ class ConfigFileNotFoundException implements Exception { final String message; - ConfigFileNotFoundException(this.message); + final bool shouldHaltCommand; + ConfigFileNotFoundException(this.message, {this.shouldHaltCommand = false}); @override String toString() { diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 3ad394f..44161bf 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -17,17 +17,17 @@ class Config with _$Config { /// Path where bottom sheets will be genereated. @JsonKey(name: 'bottom_sheets_path') @Default('ui/bottom_sheets') - String bottomSheetsPath, + String bottomSheetsPath, /// File path where BottomSheetType enum values are located. @JsonKey(name: 'bottom_sheet_type_file_path') @Default('enums/bottom_sheet_type.dart') - String bottomSheetTypeFilePath, + String bottomSheetTypeFilePath, /// File path where BottomSheet builders are located. @JsonKey(name: 'bottom_sheet_builder_file_path') @Default('ui/setup/setup_bottom_sheet_ui.dart') - String bottomSheetBuilderFilePath, + String bottomSheetBuilderFilePath, /// Path where dialogs will be genereated. @JsonKey(name: 'dialogs_path') @Default('ui/dialogs') String dialogsPath, @@ -35,33 +35,33 @@ class Config with _$Config { /// File path where DialogType enum values are located. @JsonKey(name: 'dialog_type_file_path') @Default('enums/dialog_type.dart') - String dialogTypeFilePath, + String dialogTypeFilePath, /// File path where Dialog builders are located. @JsonKey(name: 'dialog_builder_file_path') @Default('ui/setup/setup_dialog_ui.dart') - String dialogBuilderFilePath, + String dialogBuilderFilePath, /// File path where StackedApp is setup. @JsonKey(name: 'stacked_app_file_path') @Default('app/app.dart') - String stackedAppFilePath, + String stackedAppFilePath, /// File path where register functions for unit test setup and mock /// declarations are located. @JsonKey(name: 'test_helpers_file_path') @Default('helpers/test_helpers.dart') - String testHelpersFilePath, + String testHelpersFilePath, /// Paths where services unit tests will be genereated. @JsonKey(name: 'test_services_path') @Default('services') - String testServicesPath, + String testServicesPath, /// Path where viewmodels unit tests will be genereated. @JsonKey(name: 'test_views_path') @Default('viewmodels') - String testViewsPath, + String testViewsPath, /// The name of the locator to use when registering test mocks @JsonKey(name: 'locator_name') @Default('locator') String locatorName, @@ -71,7 +71,7 @@ class Config with _$Config { /// This is used when creating a test file during the `create service` command @JsonKey(name: 'register_mocks_function') @Default('registerServices') - String registerMocksFunction, + String registerMocksFunction, /// Boolean value to determine view builder style /// diff --git a/lib/src/models/config_model.freezed.dart b/lib/src/models/config_model.freezed.dart index f436190..5d0d668 100644 --- a/lib/src/models/config_model.freezed.dart +++ b/lib/src/models/config_model.freezed.dart @@ -104,40 +104,25 @@ abstract class $ConfigCopyWith<$Res> { _$ConfigCopyWithImpl<$Res, Config>; @useResult $Res call( - {@JsonKey(name: 'views_path') - String viewsPath, - @JsonKey(name: 'services_path') - String servicesPath, - @JsonKey(name: 'bottom_sheets_path') - String bottomSheetsPath, + {@JsonKey(name: 'views_path') String viewsPath, + @JsonKey(name: 'services_path') String servicesPath, + @JsonKey(name: 'bottom_sheets_path') String bottomSheetsPath, @JsonKey(name: 'bottom_sheet_type_file_path') - String bottomSheetTypeFilePath, + String bottomSheetTypeFilePath, @JsonKey(name: 'bottom_sheet_builder_file_path') - String bottomSheetBuilderFilePath, - @JsonKey(name: 'dialogs_path') - String dialogsPath, - @JsonKey(name: 'dialog_type_file_path') - String dialogTypeFilePath, - @JsonKey(name: 'dialog_builder_file_path') - String dialogBuilderFilePath, - @JsonKey(name: 'stacked_app_file_path') - String stackedAppFilePath, - @JsonKey(name: 'test_helpers_file_path') - String testHelpersFilePath, - @JsonKey(name: 'test_services_path') - String testServicesPath, - @JsonKey(name: 'test_views_path') - String testViewsPath, - @JsonKey(name: 'locator_name') - String locatorName, - @JsonKey(name: 'register_mocks_function') - String registerMocksFunction, - @JsonKey(name: 'v1') - bool v1, - @JsonKey(name: 'line_length') - int lineLength, - @JsonKey(name: 'prefer_web') - bool preferWeb}); + String bottomSheetBuilderFilePath, + @JsonKey(name: 'dialogs_path') String dialogsPath, + @JsonKey(name: 'dialog_type_file_path') String dialogTypeFilePath, + @JsonKey(name: 'dialog_builder_file_path') String dialogBuilderFilePath, + @JsonKey(name: 'stacked_app_file_path') String stackedAppFilePath, + @JsonKey(name: 'test_helpers_file_path') String testHelpersFilePath, + @JsonKey(name: 'test_services_path') String testServicesPath, + @JsonKey(name: 'test_views_path') String testViewsPath, + @JsonKey(name: 'locator_name') String locatorName, + @JsonKey(name: 'register_mocks_function') String registerMocksFunction, + @JsonKey(name: 'v1') bool v1, + @JsonKey(name: 'line_length') int lineLength, + @JsonKey(name: 'prefer_web') bool preferWeb}); } /// @nodoc @@ -251,40 +236,25 @@ abstract class _$$_ConfigCopyWith<$Res> implements $ConfigCopyWith<$Res> { @override @useResult $Res call( - {@JsonKey(name: 'views_path') - String viewsPath, - @JsonKey(name: 'services_path') - String servicesPath, - @JsonKey(name: 'bottom_sheets_path') - String bottomSheetsPath, + {@JsonKey(name: 'views_path') String viewsPath, + @JsonKey(name: 'services_path') String servicesPath, + @JsonKey(name: 'bottom_sheets_path') String bottomSheetsPath, @JsonKey(name: 'bottom_sheet_type_file_path') - String bottomSheetTypeFilePath, + String bottomSheetTypeFilePath, @JsonKey(name: 'bottom_sheet_builder_file_path') - String bottomSheetBuilderFilePath, - @JsonKey(name: 'dialogs_path') - String dialogsPath, - @JsonKey(name: 'dialog_type_file_path') - String dialogTypeFilePath, - @JsonKey(name: 'dialog_builder_file_path') - String dialogBuilderFilePath, - @JsonKey(name: 'stacked_app_file_path') - String stackedAppFilePath, - @JsonKey(name: 'test_helpers_file_path') - String testHelpersFilePath, - @JsonKey(name: 'test_services_path') - String testServicesPath, - @JsonKey(name: 'test_views_path') - String testViewsPath, - @JsonKey(name: 'locator_name') - String locatorName, - @JsonKey(name: 'register_mocks_function') - String registerMocksFunction, - @JsonKey(name: 'v1') - bool v1, - @JsonKey(name: 'line_length') - int lineLength, - @JsonKey(name: 'prefer_web') - bool preferWeb}); + String bottomSheetBuilderFilePath, + @JsonKey(name: 'dialogs_path') String dialogsPath, + @JsonKey(name: 'dialog_type_file_path') String dialogTypeFilePath, + @JsonKey(name: 'dialog_builder_file_path') String dialogBuilderFilePath, + @JsonKey(name: 'stacked_app_file_path') String stackedAppFilePath, + @JsonKey(name: 'test_helpers_file_path') String testHelpersFilePath, + @JsonKey(name: 'test_services_path') String testServicesPath, + @JsonKey(name: 'test_views_path') String testViewsPath, + @JsonKey(name: 'locator_name') String locatorName, + @JsonKey(name: 'register_mocks_function') String registerMocksFunction, + @JsonKey(name: 'v1') bool v1, + @JsonKey(name: 'line_length') int lineLength, + @JsonKey(name: 'prefer_web') bool preferWeb}); } /// @nodoc @@ -392,40 +362,31 @@ class __$$_ConfigCopyWithImpl<$Res> @JsonSerializable() class _$_Config implements _Config { _$_Config( - {@JsonKey(name: 'views_path') - this.viewsPath = 'ui/views', - @JsonKey(name: 'services_path') - this.servicesPath = 'services', + {@JsonKey(name: 'views_path') this.viewsPath = 'ui/views', + @JsonKey(name: 'services_path') this.servicesPath = 'services', @JsonKey(name: 'bottom_sheets_path') - this.bottomSheetsPath = 'ui/bottom_sheets', + this.bottomSheetsPath = 'ui/bottom_sheets', @JsonKey(name: 'bottom_sheet_type_file_path') - this.bottomSheetTypeFilePath = 'enums/bottom_sheet_type.dart', + this.bottomSheetTypeFilePath = 'enums/bottom_sheet_type.dart', @JsonKey(name: 'bottom_sheet_builder_file_path') - this.bottomSheetBuilderFilePath = 'ui/setup/setup_bottom_sheet_ui.dart', - @JsonKey(name: 'dialogs_path') - this.dialogsPath = 'ui/dialogs', + this.bottomSheetBuilderFilePath = 'ui/setup/setup_bottom_sheet_ui.dart', + @JsonKey(name: 'dialogs_path') this.dialogsPath = 'ui/dialogs', @JsonKey(name: 'dialog_type_file_path') - this.dialogTypeFilePath = 'enums/dialog_type.dart', + this.dialogTypeFilePath = 'enums/dialog_type.dart', @JsonKey(name: 'dialog_builder_file_path') - this.dialogBuilderFilePath = 'ui/setup/setup_dialog_ui.dart', + this.dialogBuilderFilePath = 'ui/setup/setup_dialog_ui.dart', @JsonKey(name: 'stacked_app_file_path') - this.stackedAppFilePath = 'app/app.dart', + this.stackedAppFilePath = 'app/app.dart', @JsonKey(name: 'test_helpers_file_path') - this.testHelpersFilePath = 'helpers/test_helpers.dart', - @JsonKey(name: 'test_services_path') - this.testServicesPath = 'services', - @JsonKey(name: 'test_views_path') - this.testViewsPath = 'viewmodels', - @JsonKey(name: 'locator_name') - this.locatorName = 'locator', + this.testHelpersFilePath = 'helpers/test_helpers.dart', + @JsonKey(name: 'test_services_path') this.testServicesPath = 'services', + @JsonKey(name: 'test_views_path') this.testViewsPath = 'viewmodels', + @JsonKey(name: 'locator_name') this.locatorName = 'locator', @JsonKey(name: 'register_mocks_function') - this.registerMocksFunction = 'registerServices', - @JsonKey(name: 'v1') - this.v1 = false, - @JsonKey(name: 'line_length') - this.lineLength = 80, - @JsonKey(name: 'prefer_web') - this.preferWeb = false}); + this.registerMocksFunction = 'registerServices', + @JsonKey(name: 'v1') this.v1 = false, + @JsonKey(name: 'line_length') this.lineLength = 80, + @JsonKey(name: 'prefer_web') this.preferWeb = false}); factory _$_Config.fromJson(Map json) => _$$_ConfigFromJson(json); @@ -606,40 +567,27 @@ class _$_Config implements _Config { abstract class _Config implements Config { factory _Config( - {@JsonKey(name: 'views_path') - final String viewsPath, - @JsonKey(name: 'services_path') - final String servicesPath, - @JsonKey(name: 'bottom_sheets_path') - final String bottomSheetsPath, + {@JsonKey(name: 'views_path') final String viewsPath, + @JsonKey(name: 'services_path') final String servicesPath, + @JsonKey(name: 'bottom_sheets_path') final String bottomSheetsPath, @JsonKey(name: 'bottom_sheet_type_file_path') - final String bottomSheetTypeFilePath, + final String bottomSheetTypeFilePath, @JsonKey(name: 'bottom_sheet_builder_file_path') - final String bottomSheetBuilderFilePath, - @JsonKey(name: 'dialogs_path') - final String dialogsPath, - @JsonKey(name: 'dialog_type_file_path') - final String dialogTypeFilePath, + final String bottomSheetBuilderFilePath, + @JsonKey(name: 'dialogs_path') final String dialogsPath, + @JsonKey(name: 'dialog_type_file_path') final String dialogTypeFilePath, @JsonKey(name: 'dialog_builder_file_path') - final String dialogBuilderFilePath, - @JsonKey(name: 'stacked_app_file_path') - final String stackedAppFilePath, - @JsonKey(name: 'test_helpers_file_path') - final String testHelpersFilePath, - @JsonKey(name: 'test_services_path') - final String testServicesPath, - @JsonKey(name: 'test_views_path') - final String testViewsPath, - @JsonKey(name: 'locator_name') - final String locatorName, + final String dialogBuilderFilePath, + @JsonKey(name: 'stacked_app_file_path') final String stackedAppFilePath, + @JsonKey(name: 'test_helpers_file_path') final String testHelpersFilePath, + @JsonKey(name: 'test_services_path') final String testServicesPath, + @JsonKey(name: 'test_views_path') final String testViewsPath, + @JsonKey(name: 'locator_name') final String locatorName, @JsonKey(name: 'register_mocks_function') - final String registerMocksFunction, - @JsonKey(name: 'v1') - final bool v1, - @JsonKey(name: 'line_length') - final int lineLength, - @JsonKey(name: 'prefer_web') - final bool preferWeb}) = _$_Config; + final String registerMocksFunction, + @JsonKey(name: 'v1') final bool v1, + @JsonKey(name: 'line_length') final int lineLength, + @JsonKey(name: 'prefer_web') final bool preferWeb}) = _$_Config; factory _Config.fromJson(Map json) = _$_Config.fromJson; diff --git a/lib/src/services/config_service.dart b/lib/src/services/config_service.dart index f2ef7fb..e083412 100644 --- a/lib/src/services/config_service.dart +++ b/lib/src/services/config_service.dart @@ -106,42 +106,35 @@ class ConfigService { /// returned. Otherwise, null is returned. /// /// Locations sorted by priority. - /// - $path/stacked.json - /// - stacked.json + /// - $path /// - $XDG_CONFIG_HOME/stacked/stacked.json - /// - stacked.config.json (deprecated config filename, only for backwards compatibility) @visibleForTesting Future resolveConfigFile({String? path}) async { if (path != null) { - if (await _fileService.fileExists(filePath: '$path/$kConfigFileName')) { - return '$path/$kConfigFileName'; + if (await _fileService.fileExists(filePath: path)) { + return path; } - } - if (await _fileService.fileExists(filePath: kConfigFileName)) { - return kConfigFileName; + throw ConfigFileNotFoundException( + kConfigFileNotFoundRetry, + shouldHaltCommand: true, + ); } try { if (await _fileService.fileExists( - filePath: '${_pathService.configHome.path}/stacked/stacked.json', + filePath: '${_pathService.configHome.path}/stacked/$kConfigFileName', )) { - return '${_pathService.configHome.path}/stacked/stacked.json'; + return '${_pathService.configHome.path}/stacked/$kConfigFileName'; } } on StateError catch (_) { // This error is Thrown when HOME environment variable is not set. } - // This is only for backwards compatibility, will be removed on next release - if (await _fileService.fileExists(filePath: 'stacked.config.json')) { - _log.warn(message: kDeprecatedConfigFileName); - return 'stacked.config.json'; - } - return null; } - /// Reads configuration file and set data to [_customConfig] map. + /// Reads configuration file and sets data to [_customConfig] map. Future loadConfig({String? path}) async { try { final configPath = await resolveConfigFile(path: path); @@ -154,6 +147,8 @@ class ConfigService { _hasCustomConfig = true; _sanitizeCustomConfig(); } on ConfigFileNotFoundException catch (e, s) { + if (e.shouldHaltCommand) rethrow; + _log.warn(message: e.message); _analyticsService.logExceptionEvent( level: Level.warning, @@ -249,4 +244,9 @@ class ConfigService { return fileToImport; } + + /// Exports custom config as a formatted Json String. + String exportConfig() { + return JsonEncoder.withIndent(" ").convert(_customConfig.toJson()); + } } diff --git a/lib/src/services/pub_service.dart b/lib/src/services/pub_service.dart index 599bf7a..c27b469 100644 --- a/lib/src/services/pub_service.dart +++ b/lib/src/services/pub_service.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:pub_updater/pub_updater.dart'; import 'package:stacked_cli/src/constants/command_constants.dart'; +import 'package:stacked_cli/src/constants/config_constants.dart'; import 'package:stacked_cli/src/locator.dart'; import 'process_service.dart'; @@ -14,7 +15,7 @@ class PubService { /// Returns current `stacked_cli` version installed on the system. Future getCurrentVersion() async { - String version = 'Current Version Not Available'; + String version = currentVersionNotAvailable; final packages = await _processService.runPubGlobalList(); for (var package in packages) { @@ -36,6 +37,10 @@ class PubService { /// installed on the system. Future hasLatestVersion() async { final currentVersion = await getCurrentVersion(); + if (currentVersion == currentVersionNotAvailable) { + await update(); + return true; + } return await _pubUpdater.isUpToDate( packageName: ksStackedCli, diff --git a/lib/src/templates/compiled_template_map.dart b/lib/src/templates/compiled_template_map.dart index 7e2cd13..cf07dff 100644 --- a/lib/src/templates/compiled_template_map.dart +++ b/lib/src/templates/compiled_template_map.dart @@ -285,18 +285,21 @@ Map> kCompiledStackedTemplates = { relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-dialog', modificationTemplate: '''StackedDialog(classType: {{dialogName}}),''', - modificationProblemError: 'The dialog registration should be stored in lib/app/app.dart', - modificationName: 'Add \'{{dialogName}}\' dependency to StackedApp annotations file', + modificationProblemError: + 'The dialog registration should be stored in lib/app/app.dart', + modificationName: + 'Add \'{{dialogName}}\' dependency to StackedApp annotations file', ), - ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: '''import \'package:{{packageName}}/{{{dialogsPath}}}/{{dialogFolderName}}/{{dialogFilename}}\';''', - modificationProblemError: 'The dialog registration should be stored in lib/app/app.dart', + modificationTemplate: + '''import \'package:{{packageName}}/{{{dialogsPath}}}/{{dialogFolderName}}/{{dialogFilename}}\';''', + modificationProblemError: + 'The dialog registration should be stored in lib/app/app.dart', modificationName: 'Add import for \'{{dialogName}}\' class', ), - ], + ], ), }, 'view': { @@ -324,18 +327,22 @@ Map> kCompiledStackedTemplates = { relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-route', modificationTemplate: '''MaterialRoute(page: {{viewName}}),''', - modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: 'Add {{viewName}} route where @StackedApp annotation is located', + modificationProblemError: + 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: + 'Add {{viewName}} route where @StackedApp annotation is located', ), - ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', - modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: 'Add {{viewName}} route import where @StackedApp annotation is located', + modificationTemplate: + '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', + modificationProblemError: + 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: + 'Add {{viewName}} route import where @StackedApp annotation is located', ), - ], + ], ), 'web': StackedTemplate( templateFiles: [ @@ -369,18 +376,22 @@ Map> kCompiledStackedTemplates = { relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-route', modificationTemplate: '''CustomRoute(page: {{viewName}}),''', - modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: 'Add {{viewName}} route where @StackedApp annotation is located', + modificationProblemError: + 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: + 'Add {{viewName}} route where @StackedApp annotation is located', ), - ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', - modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: 'Add {{viewName}} route import where @StackedApp annotation is located', + modificationTemplate: + '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', + modificationProblemError: + 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: + 'Add {{viewName}} route import where @StackedApp annotation is located', ), - ], + ], ), }, 'service': { @@ -399,63 +410,72 @@ Map> kCompiledStackedTemplates = { ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-mock-create', - modificationTemplate: '''Mock{{serviceName}} getAndRegister{{serviceName}}() { + modificationTemplate: + '''Mock{{serviceName}} getAndRegister{{serviceName}}() { _removeRegistrationIfExists<{{serviceName}}>(); final service = Mock{{serviceName}}(); {{locatorName}}.registerSingleton<{{serviceName}}>(service); return service; }''', - modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', + modificationProblemError: + 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', modificationName: 'Add {{serviceName}} mock to test helpers', ), - ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-service', - modificationTemplate: '''LazySingleton(classType: {{serviceName}}),''', - modificationProblemError: 'The service registration should be stored in lib/app/app.dart', - modificationName: 'Add {{serviceName}} dependency to StackedApp annotations file', + modificationTemplate: + '''LazySingleton(classType: {{serviceName}}),''', + modificationProblemError: + 'The service registration should be stored in lib/app/app.dart', + modificationName: + 'Add {{serviceName}} dependency to StackedApp annotations file', ), - ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', - modificationProblemError: 'The service registration should be stored in lib/app/app.dart', - modificationName: 'Add {{serviceName}} import to StackedApp annotations file', + modificationTemplate: + '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', + modificationProblemError: + 'The service registration should be stored in lib/app/app.dart', + modificationName: + 'Add {{serviceName}} import to StackedApp annotations file', ), - ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-mock-spec', - modificationTemplate: '''MockSpec<{{serviceName}}>(onMissingStub: OnMissingStub.returnDefault),''', - modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', + modificationTemplate: + '''MockSpec<{{serviceName}}>(onMissingStub: OnMissingStub.returnDefault),''', + modificationProblemError: + 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', modificationName: 'Create {{serviceName}} mock to test helpers', ), - ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-mock-register', modificationTemplate: '''getAndRegister{{serviceName}}();''', - modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', + modificationProblemError: + 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', modificationName: 'Add {{serviceName}} register to test helpers', ), - ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', - modificationProblemError: 'It seems your test_helpers.dart file is not in test/helpers/test_helpers.dart. Add a stacked.json file and set the path for \'test_helpers_path\' to the folder we can locate your test_helpers.dart file', + modificationTemplate: + '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', + modificationProblemError: + 'It seems your test_helpers.dart file is not in test/helpers/test_helpers.dart. Add a stacked.json file and set the path for \'test_helpers_path\' to the folder we can locate your test_helpers.dart file', modificationName: 'Add {{serviceName}} import to test helpers', ), - ], + ], ), }, 'bottom_sheet': { 'empty': StackedTemplate( templateFiles: [ TemplateFile( - relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetModelTestPath, + relativeOutputPath: + kBottomSheetEmptyTemplateGenericSheetModelTestPath, content: kBottomSheetEmptyTemplateGenericSheetModelTestContent, fileType: FileType.text), TemplateFile( @@ -463,7 +483,8 @@ return service; content: kBottomSheetEmptyTemplateGenericSheetModelContent, fileType: FileType.text), TemplateFile( - relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetUseModelPath, + relativeOutputPath: + kBottomSheetEmptyTemplateGenericSheetUseModelPath, content: kBottomSheetEmptyTemplateGenericSheetUseModelContent, fileType: FileType.text), TemplateFile( @@ -475,19 +496,23 @@ return service; ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-bottom-sheet', - modificationTemplate: '''StackedBottomsheet(classType: {{sheetName}}),''', - modificationProblemError: 'The bottom sheet registration should be stored in lib/app/app.dart', - modificationName: 'Add \'{{sheetName}}\' dependency to StackedApp annotations file', + modificationTemplate: + '''StackedBottomsheet(classType: {{sheetName}}),''', + modificationProblemError: + 'The bottom sheet registration should be stored in lib/app/app.dart', + modificationName: + 'Add \'{{sheetName}}\' dependency to StackedApp annotations file', ), - ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: '''import \'package:{{packageName}}/{{{bottomSheetsPath}}}/{{sheetFolderName}}/{{sheetFilename}}\';''', - modificationProblemError: 'The bottom sheet registration should be stored in lib/app/app.dart', + modificationTemplate: + '''import \'package:{{packageName}}/{{{bottomSheetsPath}}}/{{sheetFolderName}}/{{sheetFilename}}\';''', + modificationProblemError: + 'The bottom sheet registration should be stored in lib/app/app.dart', modificationName: 'Add import for \'{{sheetName}}\' class', ), - ], + ], ), }, }; diff --git a/lib/src/templates/compiled_templates.dart b/lib/src/templates/compiled_templates.dart index 048efa9..dfb1cf7 100644 --- a/lib/src/templates/compiled_templates.dart +++ b/lib/src/templates/compiled_templates.dart @@ -1,11 +1,9 @@ /// NOTE: This is generated code from the compileTemplates command. Do not modify by hand /// This file should be checked into source control. - // -------- StackedJsonStk Template Data ---------- -const String kAppWebTemplateStackedJsonStkPath = - 'stacked.json.stk'; +const String kAppWebTemplateStackedJsonStkPath = 'stacked.json.stk'; const String kAppWebTemplateStackedJsonStkContent = ''' { @@ -32,7 +30,6 @@ const String kAppWebTemplateStackedJsonStkContent = ''' // -------------------------------------------------- - // -------- UnknownViewmodelTest Template Data ---------- const String kAppWebTemplateUnknownViewmodelTestPath = @@ -54,7 +51,6 @@ void main() { // -------------------------------------------------- - // -------- HomeViewmodelTest Template Data ---------- const String kAppWebTemplateHomeViewmodelTestPath = @@ -106,7 +102,6 @@ void main() { // -------------------------------------------------- - // -------- NoticeSheetModelTest Template Data ---------- const String kAppWebTemplateNoticeSheetModelTestPath = @@ -129,7 +124,6 @@ void main() { // -------------------------------------------------- - // -------- InfoAlertDialogModelTest Template Data ---------- const String kAppWebTemplateInfoAlertDialogModelTestPath = @@ -152,7 +146,6 @@ void main() { // -------------------------------------------------- - // -------- TestHelpers Template Data ---------- const String kAppWebTemplateTestHelpersPath = @@ -242,11 +235,9 @@ void _removeRegistrationIfExists() { // -------------------------------------------------- - // -------- BuildYamlStk Template Data ---------- -const String kAppWebTemplateBuildYamlStkPath = - 'build.yaml.stk'; +const String kAppWebTemplateBuildYamlStkPath = 'build.yaml.stk'; const String kAppWebTemplateBuildYamlStkContent = ''' targets: @@ -259,11 +250,9 @@ targets: // -------------------------------------------------- - // -------- MainIconPngStk Template Data ---------- -const String kAppWebTemplateMainIconPngStkPath = - 'web/main-icon.png.stk'; +const String kAppWebTemplateMainIconPngStkPath = 'web/main-icon.png.stk'; const String kAppWebTemplateMainIconPngStkContent = ''' iVBORw0KGgoAAAANSUhEUgAAALMAAACzCAYAAADCFC3zAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAN5SURBVHgB7daLjVNBDEDRF0QjVEIrdMLSAS3RyZZAByGWdqUQ5Z/5eGbOkSw3cC152wAAAAAAAAAAAAAAAACAjHZbYfuDDW77tdvt3raCvmzQXvGQg5hprUrIQcy0VC3kIGZaqRpyEDMtVA85iJnamoQcxExNzUIOYqaWpiEHMVND85CDmCmtS8hBzJTULeQgZkrpGnIQMyV0DzmImVelCDmImVekCTmImWelCjmImWekCzmImUelDDmImUekDTmImXulDjmImXukDzmImVuGCDmImWuGCTmImUuGCjmImXOGCzmImVNDhhzEzLFhQw5i5tPQIQcxE4YPOYiZKUIOYl7bNCEHMa9rqpCDmNc0XchBzOuZMuQg5rVMG3IQ8zqmDjmIeQ3ThxzEPL8lQg5intsyIQcxz2upkIOY57RcyEHM81ky5CDmuSwbchDzPJYOOYh5DsuHHMQ8PiF/EPPYhHxEzOMS8gkxj0nIZ4h5PEK+QMxjEfIVYh6HkG8Q8xiEfAcx5yfkO4k5NyE/QMx5CflBYs5JyE8Qcz5CfpKYcxHyC8Sch5BfJOYchFyAmPsTciFi7kvIBYm5HyEXJuY+hFyBmNsTciVibkvIFYm5HSFXttsK2+/3bxunvh/mz8axv4fj/r0VVDxm/nc47p+H9bZx6v0Q87etIG9GRUJuS8yVCLk9MVcg5D7EXJiQ+xFzQULuS8yFCLk/MRcg5BzE/CIh5yHmFwg5FzE/Scj5iPkJQs5JzA8Scl5ifoCQcxPznYScn5jvIOQxiPkGIY9DzFcIeSxivkDI4xHzGUIek5hPCHlcYj4i5LGJ+YOQxyfmTcizWD5mIc9j6ZiFPJdlYxbyfJaMWchzWi5mIc9rqZiFPLdlYhby/JaIWchrmD5mIa9j6piFvJZpYxbyeqaMWchrmi5mIa9rqpiFvLZpYhYyU8QsZMLwMQuZT0PHLGSODRuzkDk1ZMxC5pzhYhYylwwVs5C5ZpiYhcwtQ8QsZO6RPmYhc6/UMQuZR6SNWcg8KmXMQuYZ6WIWMs9KFbOQeUWamIXMq1LELGRK6B6zkCmla8xCpqRuMQuZ0rrELGRqaB6zkKmlacxCpqZmMQuZ2prELGRaqB6zkGmlasxCpqVqMQuZ1qrELGR6+LoVdgj5x2HFvG9w2fsGAAAAAAAAAAAAAAAAACzhH8sFZqawpyetAAAAAElFTkSuQmCC @@ -271,11 +260,9 @@ iVBORw0KGgoAAAANSUhEUgAAALMAAACzCAYAAADCFC3zAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNS // -------------------------------------------------- - // -------- IndexHtmlStk Template Data ---------- -const String kAppWebTemplateIndexHtmlStkPath = - 'web/index.html.stk'; +const String kAppWebTemplateIndexHtmlStkPath = 'web/index.html.stk'; const String kAppWebTemplateIndexHtmlStkContent = ''' @@ -453,11 +440,9 @@ const String kAppWebTemplateIndexHtmlStkContent = ''' // -------------------------------------------------- - // -------- FaviconPngStk Template Data ---------- -const String kAppWebTemplateFaviconPngStkPath = - 'web/favicon.png.stk'; +const String kAppWebTemplateFaviconPngStkPath = 'web/favicon.png.stk'; const String kAppWebTemplateFaviconPngStkContent = ''' iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAHaSURBVHgBpVTNasJAEN7dxLQl+FNEFBRR8VCQgo+gryCkh9499CnUg/gMvo3eFWw9eBLS4sWT2oOHRLOdWWLYxkRT+8GS3cnkm28mM0tIMOhpwzmn7plKdurawz9EdLtdNhqNWKvVekyn0ynLsghjTPg4jsNt26a6rnO09/v9r2Qy6UwmkwOlwoX7yZVqtWqA07v78uqKx+NmsVhsw179Jc4wDKVcLrejEvkXCHlBDlmdlkgkPm8lhKw+arWahipRKikUCspqtSqe2FOpFKnX6+QSZrMZ2W63Yr/b7Z6htshl45kOh8MnOWKj0eCXAD8vSKmOf54ho6qqnEREr9fDbjizZzIZikBCut/v6X/IENBeQikSck3TrnFdJJMghJ3V0L86nc5ZHbHOsk82m9WFUCTEzg8DkEVRhpOE6jhD57CUo5IR4tVQpMyCUg5KM0LKorH5crn8lqNhY4/HY9JsNkMVYWPLWK/XXutRmJQHGPQ5uXH0cGxLpdK9SNeVe8jlcgNyI2CWB6ZpHjwDjgxGyOfzb3+5JIBoXqlUXuG2uSOnHpQCUSi0slgs7qCNVAwCEHXZbDZYV+8sZpYxJxaLHaFc1nQ6PYLZCcsAy6BIT0U6eza83X2CBH4AHNJFlWlQookAAAAASUVORK5CYII= @@ -465,11 +450,9 @@ iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNS // -------------------------------------------------- - // -------- READMEMdStk Template Data ---------- -const String kAppWebTemplateREADMEMdStkPath = - 'README.md.stk'; +const String kAppWebTemplateREADMEMdStkPath = 'README.md.stk'; const String kAppWebTemplateREADMEMdStkContent = ''' # stacked_app @@ -493,11 +476,9 @@ samples, guidance on mobile development, and a full API reference. // -------------------------------------------------- - // -------- Main Template Data ---------- -const String kAppWebTemplateMainPath = - 'lib/main.dart.stk'; +const String kAppWebTemplateMainPath = 'lib/main.dart.stk'; const String kAppWebTemplateMainContent = ''' import 'package:flutter/material.dart'; @@ -550,7 +531,6 @@ class MyApp extends StatelessWidget { // -------------------------------------------------- - // -------- AppConstants Template Data ---------- const String kAppWebTemplateAppConstantsPath = @@ -567,11 +547,9 @@ const double kdDesktopMaxContentHeight = 750; // -------------------------------------------------- - // -------- UiHelpers Template Data ---------- -const String kAppWebTemplateUiHelpersPath = - 'lib/ui/common/ui_helpers.dart.stk'; +const String kAppWebTemplateUiHelpersPath = 'lib/ui/common/ui_helpers.dart.stk'; const String kAppWebTemplateUiHelpersContent = ''' import 'dart:math'; @@ -657,7 +635,6 @@ double getResponsiveFontSize(BuildContext context, // -------------------------------------------------- - // -------- AppStrings Template Data ---------- const String kAppWebTemplateAppStringsPath = @@ -672,11 +649,9 @@ const String ksHomeBottomSheetDescription = // -------------------------------------------------- - // -------- AppColors Template Data ---------- -const String kAppWebTemplateAppColorsPath = - 'lib/ui/common/app_colors.dart.stk'; +const String kAppWebTemplateAppColorsPath = 'lib/ui/common/app_colors.dart.stk'; const String kAppWebTemplateAppColorsContent = ''' import 'package:flutter/material.dart'; @@ -695,7 +670,6 @@ const Color kcBackgroundColor = kcDarkGreyColor; // -------------------------------------------------- - // -------- NoticeSheetModel Template Data ---------- const String kAppWebTemplateNoticeSheetModelPath = @@ -710,7 +684,6 @@ class NoticeSheetModel extends BaseViewModel {} // -------------------------------------------------- - // -------- NoticeSheet Template Data ---------- const String kAppWebTemplateNoticeSheetPath = @@ -779,7 +752,6 @@ class NoticeSheet extends StackedView { // -------------------------------------------------- - // -------- InfoAlertDialogModel Template Data ---------- const String kAppWebTemplateInfoAlertDialogModelPath = @@ -794,7 +766,6 @@ class InfoAlertDialogModel extends BaseViewModel {} // -------------------------------------------------- - // -------- InfoAlertDialog Template Data ---------- const String kAppWebTemplateInfoAlertDialogPath = @@ -914,7 +885,6 @@ class InfoAlertDialog extends StackedView { // -------------------------------------------------- - // -------- HomeViewDesktop Template Data ---------- const String kAppWebTemplateHomeViewDesktopPath = @@ -1001,7 +971,6 @@ class HomeViewDesktop extends ViewModelWidget { // -------------------------------------------------- - // -------- HomeViewMobile Template Data ---------- const String kAppWebTemplateHomeViewMobilePath = @@ -1088,7 +1057,6 @@ class HomeViewMobile extends ViewModelWidget { // -------------------------------------------------- - // -------- HomeView Template Data ---------- const String kAppWebTemplateHomeViewPath = @@ -1131,7 +1099,6 @@ class HomeView extends StackedView { // -------------------------------------------------- - // -------- HomeViewmodel Template Data ---------- const String kAppWebTemplateHomeViewmodelPath = @@ -1179,7 +1146,6 @@ class HomeViewModel extends BaseViewModel { // -------------------------------------------------- - // -------- HomeViewTablet Template Data ---------- const String kAppWebTemplateHomeViewTabletPath = @@ -1266,7 +1232,6 @@ class HomeViewTablet extends ViewModelWidget { // -------------------------------------------------- - // -------- UnknownView Template Data ---------- const String kAppWebTemplateUnknownViewPath = @@ -1309,7 +1274,6 @@ class UnknownView extends StackedView { // -------------------------------------------------- - // -------- UnknownViewDesktop Template Data ---------- const String kAppWebTemplateUnknownViewDesktopPath = @@ -1365,7 +1329,6 @@ class UnknownViewDesktop extends ViewModelWidget { // -------------------------------------------------- - // -------- UnknownViewTablet Template Data ---------- const String kAppWebTemplateUnknownViewTabletPath = @@ -1421,7 +1384,6 @@ class UnknownViewTablet extends ViewModelWidget { // -------------------------------------------------- - // -------- UnknownViewmodel Template Data ---------- const String kAppWebTemplateUnknownViewmodelPath = @@ -1436,7 +1398,6 @@ class UnknownViewModel extends BaseViewModel {} // -------------------------------------------------- - // -------- UnknownViewMobile Template Data ---------- const String kAppWebTemplateUnknownViewMobilePath = @@ -1491,7 +1452,6 @@ class UnknownViewMobile extends ViewModelWidget { // -------------------------------------------------- - // -------- StartupViewmodel Template Data ---------- const String kAppWebTemplateStartupViewmodelPath = @@ -1519,7 +1479,6 @@ class StartupViewModel extends BaseViewModel { // -------------------------------------------------- - // -------- StartupView Template Data ---------- const String kAppWebTemplateStartupViewPath = @@ -1594,7 +1553,6 @@ class StartupView extends StackedView { // -------------------------------------------------- - // -------- ScaleOnHover Template Data ---------- const String kAppWebTemplateScaleOnHoverPath = @@ -1644,7 +1602,6 @@ class _ScaleOnHoverState extends State { // -------------------------------------------------- - // -------- TranslateOnHover Template Data ---------- const String kAppWebTemplateTranslateOnHoverPath = @@ -1701,11 +1658,9 @@ class _TranslateOnHoverState extends State { // -------------------------------------------------- - // -------- App Template Data ---------- -const String kAppWebTemplateAppPath = - 'lib/app/app.dart.stk'; +const String kAppWebTemplateAppPath = 'lib/app/app.dart.stk'; const String kAppWebTemplateAppContent = ''' import 'package:{{packageName}}/{{{bottomSheetsPath}}}/notice/notice_sheet.dart'; @@ -1749,7 +1704,6 @@ class App {} // -------------------------------------------------- - // -------- HoverExtensions Template Data ---------- const String kAppWebTemplateHoverExtensionsPath = @@ -1804,11 +1758,9 @@ extension HoverExtensions on Widget { // -------------------------------------------------- - // -------- PubspecYamlStk Template Data ---------- -const String kAppWebTemplatePubspecYamlStkPath = - 'pubspec.yaml.stk'; +const String kAppWebTemplatePubspecYamlStkPath = 'pubspec.yaml.stk'; const String kAppWebTemplatePubspecYamlStkContent = ''' name: {{packageName}} @@ -1915,11 +1867,9 @@ flutter: // -------------------------------------------------- - // -------- SettingsJsonStk Template Data ---------- -const String kAppWebTemplateSettingsJsonStkPath = - '.vscode/settings.json.stk'; +const String kAppWebTemplateSettingsJsonStkPath = '.vscode/settings.json.stk'; const String kAppWebTemplateSettingsJsonStkContent = ''' { @@ -1933,11 +1883,9 @@ const String kAppWebTemplateSettingsJsonStkContent = ''' // -------------------------------------------------- - // -------- StackedJsonStk Template Data ---------- -const String kAppMobileTemplateStackedJsonStkPath = - 'stacked.json.stk'; +const String kAppMobileTemplateStackedJsonStkPath = 'stacked.json.stk'; const String kAppMobileTemplateStackedJsonStkContent = ''' { @@ -1962,7 +1910,6 @@ const String kAppMobileTemplateStackedJsonStkContent = ''' // -------------------------------------------------- - // -------- HomeViewmodelTest Template Data ---------- const String kAppMobileTemplateHomeViewmodelTestPath = @@ -2014,7 +1961,6 @@ void main() { // -------------------------------------------------- - // -------- NoticeSheetModelTest Template Data ---------- const String kAppMobileTemplateNoticeSheetModelTestPath = @@ -2037,7 +1983,6 @@ void main() { // -------------------------------------------------- - // -------- InfoAlertDialogModelTest Template Data ---------- const String kAppMobileTemplateInfoAlertDialogModelTestPath = @@ -2060,7 +2005,6 @@ void main() { // -------------------------------------------------- - // -------- TestHelpers Template Data ---------- const String kAppMobileTemplateTestHelpersPath = @@ -2150,11 +2094,9 @@ void _removeRegistrationIfExists() { // -------------------------------------------------- - // -------- READMEMdStk Template Data ---------- -const String kAppMobileTemplateREADMEMdStkPath = - 'README.md.stk'; +const String kAppMobileTemplateREADMEMdStkPath = 'README.md.stk'; const String kAppMobileTemplateREADMEMdStkContent = ''' # stacked_app @@ -2178,11 +2120,9 @@ samples, guidance on mobile development, and a full API reference. // -------------------------------------------------- - // -------- Main Template Data ---------- -const String kAppMobileTemplateMainPath = - 'lib/main.dart.stk'; +const String kAppMobileTemplateMainPath = 'lib/main.dart.stk'; const String kAppMobileTemplateMainContent = ''' import 'package:flutter/material.dart'; @@ -2229,7 +2169,6 @@ class MyApp extends StatelessWidget { // -------------------------------------------------- - // -------- UiHelpers Template Data ---------- const String kAppMobileTemplateUiHelpersPath = @@ -2319,7 +2258,6 @@ double getResponsiveFontSize(BuildContext context, // -------------------------------------------------- - // -------- AppStrings Template Data ---------- const String kAppMobileTemplateAppStringsPath = @@ -2334,7 +2272,6 @@ const String ksHomeBottomSheetDescription = // -------------------------------------------------- - // -------- AppColors Template Data ---------- const String kAppMobileTemplateAppColorsPath = @@ -2355,7 +2292,6 @@ const Color kcBackgroundColor = kcDarkGreyColor; // -------------------------------------------------- - // -------- NoticeSheetModel Template Data ---------- const String kAppMobileTemplateNoticeSheetModelPath = @@ -2370,7 +2306,6 @@ class NoticeSheetModel extends BaseViewModel {} // -------------------------------------------------- - // -------- NoticeSheet Template Data ---------- const String kAppMobileTemplateNoticeSheetPath = @@ -2439,7 +2374,6 @@ class NoticeSheet extends StackedView { // -------------------------------------------------- - // -------- InfoAlertDialogModel Template Data ---------- const String kAppMobileTemplateInfoAlertDialogModelPath = @@ -2454,7 +2388,6 @@ class InfoAlertDialogModel extends BaseViewModel {} // -------------------------------------------------- - // -------- InfoAlertDialog Template Data ---------- const String kAppMobileTemplateInfoAlertDialogPath = @@ -2574,7 +2507,6 @@ class InfoAlertDialog extends StackedView { // -------------------------------------------------- - // -------- HomeViewV1 Template Data ---------- const String kAppMobileTemplateHomeViewV1Path = @@ -2663,7 +2595,6 @@ class HomeView extends StatelessWidget { // -------------------------------------------------- - // -------- HomeView Template Data ---------- const String kAppMobileTemplateHomeViewPath = @@ -2759,7 +2690,6 @@ class HomeView extends StackedView { // -------------------------------------------------- - // -------- HomeViewmodel Template Data ---------- const String kAppMobileTemplateHomeViewmodelPath = @@ -2807,7 +2737,6 @@ class HomeViewModel extends BaseViewModel { // -------------------------------------------------- - // -------- StartupViewmodel Template Data ---------- const String kAppMobileTemplateStartupViewmodelPath = @@ -2837,7 +2766,6 @@ class StartupViewModel extends BaseViewModel { // -------------------------------------------------- - // -------- StartupViewV1 Template Data ---------- const String kAppMobileTemplateStartupViewV1Path = @@ -2903,7 +2831,6 @@ class StartupView extends StatelessWidget { // -------------------------------------------------- - // -------- StartupView Template Data ---------- const String kAppMobileTemplateStartupViewPath = @@ -2978,11 +2905,9 @@ class StartupView extends StackedView { // -------------------------------------------------- - // -------- App Template Data ---------- -const String kAppMobileTemplateAppPath = - 'lib/app/app.dart.stk'; +const String kAppMobileTemplateAppPath = 'lib/app/app.dart.stk'; const String kAppMobileTemplateAppContent = ''' import 'package:{{packageName}}/{{{bottomSheetsPath}}}/notice/notice_sheet.dart'; @@ -3020,11 +2945,9 @@ class App {} // -------------------------------------------------- - // -------- PubspecYamlStk Template Data ---------- -const String kAppMobileTemplatePubspecYamlStkPath = - 'pubspec.yaml.stk'; +const String kAppMobileTemplatePubspecYamlStkPath = 'pubspec.yaml.stk'; const String kAppMobileTemplatePubspecYamlStkContent = ''' name: {{packageName}} @@ -3128,7 +3051,6 @@ flutter: // -------------------------------------------------- - // -------- SettingsJsonStk Template Data ---------- const String kAppMobileTemplateSettingsJsonStkPath = @@ -3146,7 +3068,6 @@ const String kAppMobileTemplateSettingsJsonStkContent = ''' // -------------------------------------------------- - // -------- GenericDialogModelTest Template Data ---------- const String kDialogEmptyTemplateGenericDialogModelTestPath = @@ -3169,7 +3090,6 @@ void main() { // -------------------------------------------------- - // -------- GenericDialogModel Template Data ---------- const String kDialogEmptyTemplateGenericDialogModelPath = @@ -3184,7 +3104,6 @@ class {{dialogModelName}} extends BaseViewModel {} // -------------------------------------------------- - // -------- GenericDialogUseModel Template Data ---------- const String kDialogEmptyTemplateGenericDialogUseModelPath = @@ -3305,7 +3224,6 @@ class {{dialogName}} extends StackedView<{{dialogModelName}}> { // -------------------------------------------------- - // -------- GenericDialog Template Data ---------- const String kDialogEmptyTemplateGenericDialogPath = @@ -3415,7 +3333,6 @@ class {{dialogName}} extends StatelessWidget { // -------------------------------------------------- - // -------- GenericViewmodelTest Template Data ---------- const String kViewEmptyTemplateGenericViewmodelTestPath = @@ -3438,7 +3355,6 @@ void main() { // -------------------------------------------------- - // -------- GenericViewmodel Template Data ---------- const String kViewEmptyTemplateGenericViewmodelPath = @@ -3453,7 +3369,6 @@ class {{viewModelName}} extends BaseViewModel { // -------------------------------------------------- - // -------- GenericView Template Data ---------- const String kViewEmptyTemplateGenericViewPath = @@ -3491,7 +3406,6 @@ class {{viewName}} extends StackedView<{{viewModelName}}> { // -------------------------------------------------- - // -------- GenericViewV1 Template Data ---------- const String kViewEmptyTemplateGenericViewV1Path = @@ -3523,7 +3437,6 @@ class {{viewName}} extends StatelessWidget { // -------------------------------------------------- - // -------- GenericViewmodelTest Template Data ---------- const String kViewWebTemplateGenericViewmodelTestPath = @@ -3546,7 +3459,6 @@ void main() { // -------------------------------------------------- - // -------- GenericViewmodel Template Data ---------- const String kViewWebTemplateGenericViewmodelPath = @@ -3561,7 +3473,6 @@ class {{viewModelName}} extends BaseViewModel { // -------------------------------------------------- - // -------- GenericViewMobile Template Data ---------- const String kViewWebTemplateGenericViewMobilePath = @@ -3596,7 +3507,6 @@ class {{viewName}}Mobile extends ViewModelWidget<{{viewModelName}}> { // -------------------------------------------------- - // -------- GenericViewTablet Template Data ---------- const String kViewWebTemplateGenericViewTabletPath = @@ -3631,7 +3541,6 @@ class {{viewName}}Tablet extends ViewModelWidget<{{viewModelName}}> { // -------------------------------------------------- - // -------- GenericView Template Data ---------- const String kViewWebTemplateGenericViewPath = @@ -3674,7 +3583,6 @@ class {{viewName}} extends StackedView<{{viewModelName}}> { // -------------------------------------------------- - // -------- GenericViewDesktop Template Data ---------- const String kViewWebTemplateGenericViewDesktopPath = @@ -3709,7 +3617,6 @@ class {{viewName}}Desktop extends ViewModelWidget<{{viewModelName}}> { // -------------------------------------------------- - // -------- GenericServiceTest Template Data ---------- const String kServiceEmptyTemplateGenericServiceTestPath = @@ -3732,7 +3639,6 @@ void main() { // -------------------------------------------------- - // -------- GenericService Template Data ---------- const String kServiceEmptyTemplateGenericServicePath = @@ -3746,7 +3652,6 @@ class {{serviceName}} { // -------------------------------------------------- - // -------- GenericSheetModelTest Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetModelTestPath = @@ -3769,7 +3674,6 @@ void main() { // -------------------------------------------------- - // -------- GenericSheetModel Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetModelPath = @@ -3784,7 +3688,6 @@ class {{sheetModelName}} extends BaseViewModel {} // -------------------------------------------------- - // -------- GenericSheetUseModel Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetUseModelPath = @@ -3855,7 +3758,6 @@ class {{sheetName}} extends StackedView<{{sheetModelName}}> { // -------------------------------------------------- - // -------- GenericSheet Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetPath = @@ -3914,4 +3816,3 @@ class {{sheetName}} extends StatelessWidget { '''; // -------------------------------------------------- - diff --git a/test/helpers/test_helpers.dart b/test/helpers/test_helpers.dart index 68b57e5..86fb813 100644 --- a/test/helpers/test_helpers.dart +++ b/test/helpers/test_helpers.dart @@ -161,6 +161,10 @@ MockConfigService getAndRegisterConfigService({ (invocation) => customPath ?? invocation.positionalArguments[0], ); + when(service.resolveConfigFile(path: anyNamed('path'))).thenAnswer( + (invocation) => customPath ?? invocation.namedArguments[0], + ); + locator.registerSingleton(service); return service; } diff --git a/test/helpers/test_helpers.mocks.dart b/test/helpers/test_helpers.mocks.dart index d252f35..0aaa27b 100644 --- a/test/helpers/test_helpers.mocks.dart +++ b/test/helpers/test_helpers.mocks.dart @@ -1055,6 +1055,15 @@ class MockConfigService extends _i1.Mock implements _i15.ConfigService { returnValue: '', returnValueForMissingStub: '', ) as String); + @override + String exportConfig() => (super.noSuchMethod( + Invocation.method( + #exportConfig, + [], + ), + returnValue: '', + returnValueForMissingStub: '', + ) as String); } /// A class which mocks [ProcessService]. diff --git a/test/services/config_service_test.dart b/test/services/config_service_test.dart index 4440b91..68d3a96 100644 --- a/test/services/config_service_test.dart +++ b/test/services/config_service_test.dart @@ -1,6 +1,7 @@ import 'package:mockito/mockito.dart'; import 'package:stacked_cli/src/constants/config_constants.dart'; import 'package:stacked_cli/src/constants/message_constants.dart'; +import 'package:stacked_cli/src/exceptions/config_file_not_found_exception.dart'; import 'package:stacked_cli/src/locator.dart'; import 'package:stacked_cli/src/services/config_service.dart'; import 'package:test/test.dart'; @@ -14,9 +15,15 @@ void main() { setUp(() => registerServices()); tearDown(() => locator.reset()); + const customConfigFilePath = '/Users/filledstacks/Desktop/stacked.json'; + const xdgConfigFilePath = + '/Users/filledstacks/.config/stacked/stacked.json'; const stackedAppFilePath = 'src/app/core.dart'; const testHelpersFilePath = 'lib/src/test/helpers/core_test.helpers.dart'; + const correctConfigPath = + 'No configuration file found. Please, correct the config path passed as argument.'; + const String customConfig = ''' { "stacked_app_file_path": "$stackedAppFilePath", @@ -34,131 +41,86 @@ void main() { group('resolveConfigFile -', () { test( - 'when called with output path and config file is present on output path should call fileExists on fileService 1 times', + 'when called with config filepath and file is present on path should call fileExists on custom config filepath', () async { final fileService = getAndRegisterFileService(); final service = _getService(); - await service.resolveConfigFile(path: 'output'); - verify( - fileService.fileExists(filePath: anyNamed('filePath')), - ).called(1); - }); - - test( - 'when called without output path and config file is present on current path should call fileExists on fileService 1 times', - () async { - final fileService = getAndRegisterFileService(); - final service = _getService(); - await service.resolveConfigFile(); - verify( - fileService.fileExists(filePath: anyNamed('filePath')), - ).called(1); - }); - - test( - 'when called without output path and config file is present on XDG_CONFIG_HOME path should call fileExists on fileService 2 times', - () async { - final fileService = getAndRegisterFileService(retryUntilFileExists: 1); - final service = _getService(); - await service.resolveConfigFile(); - verify( - fileService.fileExists(filePath: anyNamed('filePath')), - ).called(2); - }); - - test( - 'when called without output path and config file is present on current path with deprecated filename should call fileExists on fileService 3 times', - () async { - final fileService = getAndRegisterFileService(retryUntilFileExists: 2); - final service = _getService(); - await service.resolveConfigFile(); - verify( - fileService.fileExists(filePath: anyNamed('filePath')), - ).called(3); + await service.resolveConfigFile(path: customConfigFilePath); + verify(fileService.fileExists(filePath: customConfigFilePath)); }); test( - 'when called with output path and without config file should call fileExists on fileService 4 times', + 'when called with config filepath and file is present on path should return customConfigFilePath', () async { - final fileService = getAndRegisterFileService(fileExistsResult: false); + getAndRegisterFileService(); final service = _getService(); - await service.resolveConfigFile(path: 'output'); - verify( - fileService.fileExists(filePath: anyNamed('filePath')), - ).called(4); + final path = await service.resolveConfigFile( + path: customConfigFilePath, + ); + expect(path, customConfigFilePath); }); test( - 'when called with output path and without config file should call fileExists on fileService in priority order', + 'when called with config filepath and file is NOT present on path should throw ConfigFileNotFoundException', () async { - final fileService = getAndRegisterFileService(fileExistsResult: false); + getAndRegisterFileService(fileExistsResult: false); final service = _getService(); - await service.resolveConfigFile(path: 'output'); - verifyInOrder([ - fileService.fileExists(filePath: 'output/stacked.json'), - fileService.fileExists(filePath: 'stacked.json'), - fileService.fileExists( - filePath: '/Users/filledstacks/.config/stacked/stacked.json', - ), - fileService.fileExists(filePath: 'stacked.config.json'), - ]); + expect( + () => service.resolveConfigFile(path: customConfigFilePath), + throwsA(predicate( + (e) => + e is ConfigFileNotFoundException && + e.message == correctConfigPath && + e.shouldHaltCommand == true, + )), + ); }); test( - 'when called with output path and without config file should call fileExists on fileService 3 times', + 'when called without config filepath should call fileExists on XDG_CONFIG_HOME', () async { - final fileService = getAndRegisterFileService(fileExistsResult: false); + final fileService = getAndRegisterFileService(); final service = _getService(); await service.resolveConfigFile(); - verify( - fileService.fileExists(filePath: anyNamed('filePath')), - ).called(3); + verify(fileService.fileExists(filePath: xdgConfigFilePath)); }); test( - 'when called without output path and without config file should call fileExists on fileService in priority order', + 'when called without config filepath and file is present on XDG_CONFIG_HOME should return xdgConfigFilePath', () async { - final fileService = getAndRegisterFileService(fileExistsResult: false); + getAndRegisterFileService(); final service = _getService(); - await service.resolveConfigFile(); - verifyInOrder([ - fileService.fileExists(filePath: 'stacked.json'), - fileService.fileExists( - filePath: '/Users/filledstacks/.config/stacked/stacked.json', - ), - fileService.fileExists(filePath: 'stacked.config.json'), - ]); + final path = await service.resolveConfigFile(); + expect(path, xdgConfigFilePath); }); test( - 'when called without output path, without config file and HOME environment variable is not set' - 'should NOT call fileExists on fileService for XDG_CONFIG_HOME directory', + 'when called without config filepath and file is NOT present on XDG_CONFIG_HOME should return null', () async { - getAndRegisterPathService(throwStateError: true); - final fileService = getAndRegisterFileService(fileExistsResult: false); + getAndRegisterFileService(fileExistsResult: false); final service = _getService(); - await service.resolveConfigFile(); - verifyNever(fileService.fileExists( - filePath: '/Users/filledstacks/.config/stacked/stacked.json', - )); + final path = await service.resolveConfigFile(); + expect(path, isNull); }); }); group('loadConfig -', () { - test('when called, should call fileExists on FileService', () async { - getAndRegisterFileService(readFileResult: '{}'); + test( + 'when called, should call fileExists on FileService for XDG_CONFIG_HOME', + () async { + final fileService = getAndRegisterFileService(readFileResult: '{}'); final service = _getService(); await service.loadConfig(); - verify(service.resolveConfigFile()); + verify(fileService.fileExists(filePath: xdgConfigFilePath)); }); test( - 'when called with path, should call fileExists on FileService with path', + 'when called with filepath, should call fileExists on FileService with filepath', () async { - getAndRegisterFileService(readFileResult: '{}'); + final fileService = getAndRegisterFileService(readFileResult: '{}'); final service = _getService(); - await service.loadConfig(path: 'example'); - verify(service.resolveConfigFile(path: 'example')); + await service.loadConfig(path: customConfigFilePath); + verify(fileService.fileExists(filePath: customConfigFilePath)); }); test(