diff --git a/lib/src/commands/create/create_app_command.dart b/lib/src/commands/create/create_app_command.dart index af5350a..eee2f03 100644 --- a/lib/src/commands/create/create_app_command.dart +++ b/lib/src/commands/create/create_app_command.dart @@ -15,12 +15,12 @@ import 'package:stacked_cli/src/services/template_service.dart'; import 'package:stacked_cli/src/templates/template_constants.dart'; class CreateAppCommand extends Command { - final _log = locator(); + final _analyticsService = locator(); final _configService = locator(); final _fileService = locator(); + final _log = locator(); final _processService = locator(); final _templateService = locator(); - final _analyticsService = locator(); @override String get description => @@ -30,35 +30,54 @@ class CreateAppCommand extends Command { String get name => kTemplateNameApp; CreateAppCommand() { - argParser.addFlag( - ksV1, - aliases: [ksUseBuilder], - defaultsTo: null, - help: kCommandHelpV1, - ); - - argParser.addOption( - ksLineLength, - abbr: 'l', - help: kCommandHelpLineLength, - valueHelp: '80', - ); - - argParser.addOption( - ksTemplateType, - abbr: 't', - // TODO (Create App Templates): Generate a constant with these values when - // running the compile command - allowed: ['mobile', 'web'], - defaultsTo: 'mobile', - help: kCommandHelpCreateAppTemplate, - ); - - argParser.addOption( - ksConfigPath, - abbr: 'c', - help: kCommandHelpConfigFilePath, - ); + argParser + ..addOption( + ksConfigPath, + abbr: 'c', + help: kCommandHelpConfigFilePath, + ) + ..addOption( + ksLineLength, + abbr: 'l', + help: kCommandHelpLineLength, + valueHelp: '80', + ) + ..addOption( + ksAppDescription, + help: kCommandHelpAppDescription, + ) + ..addOption( + ksAppOrganization, + defaultsTo: 'com.example', + help: kCommandHelpAppOrganization, + ) + ..addMultiOption( + ksAppPlatforms, + allowed: ['ios', 'android', 'windows', 'linux', 'macos', 'web'], + defaultsTo: ['ios', 'android', 'windows', 'linux', 'macos', 'web'], + help: kCommandHelpAppPlatforms, + ) + ..addOption( + ksTemplateType, + abbr: 't', + // TODO (Create App Templates): Generate a constant with these values when + // running the compile command + allowed: ['mobile', 'web'], + defaultsTo: 'mobile', + help: kCommandHelpCreateAppTemplate, + ) + ..addFlag( + ksAppMinimalTemplate, + abbr: 'e', + defaultsTo: true, + help: kCommandHelpAppMinimalTemplate, + ) + ..addFlag( + ksV1, + aliases: [ksUseBuilder], + defaultsTo: null, + help: kCommandHelpV1, + ); } @override @@ -74,7 +93,13 @@ class CreateAppCommand extends Command { unawaited(_analyticsService.createAppEvent(name: appName)); _processService.formattingLineLength = argResults![ksLineLength]; - await _processService.runCreateApp(appName: workingDirectory); + await _processService.runCreateApp( + appName: workingDirectory, + shouldUseMinimalTemplate: argResults![ksAppMinimalTemplate], + description: argResults![ksAppDescription], + organization: argResults![ksAppOrganization], + platforms: argResults![ksAppPlatforms], + ); _log.stackedOutput(message: 'Add Stacked Magic ... ', isBold: true); diff --git a/lib/src/constants/command_constants.dart b/lib/src/constants/command_constants.dart index 8cc8793..8a9845e 100644 --- a/lib/src/constants/command_constants.dart +++ b/lib/src/constants/command_constants.dart @@ -30,6 +30,10 @@ const String ksModel = 'model'; const String ksConfigPath = 'config-path'; const String ksWatch = 'watch'; const String ksPath = 'path'; +const String ksAppMinimalTemplate = 'empty'; +const String ksAppDescription = 'description'; +const String ksAppOrganization = 'org'; +const String ksAppPlatforms = 'platforms'; /// A list of strings that are used to run the run build_runner /// [build or watch] --delete-conflicting-outputs command. diff --git a/lib/src/constants/message_constants.dart b/lib/src/constants/message_constants.dart index dea4201..9437290 100644 --- a/lib/src/constants/message_constants.dart +++ b/lib/src/constants/message_constants.dart @@ -35,6 +35,18 @@ const String kCommandHelpExcludeRoute = const String kCommandHelpV1 = 'When v1 or use-builder is provided, ViewModelBuilder will be used instead of StackedView.'; +const String kCommandHelpAppMinimalTemplate = + 'Specifies creating using an application template with a main.dart that is minimal, including no comments.'; + +const String kCommandHelpAppDescription = + 'The description to use for your new Flutter project. This string ends up in the pubspec.yaml file.'; + +const String kCommandHelpAppOrganization = + 'The organization responsible for your new Flutter project, in reverse domain name notation.'; + +const String kCommandHelpAppPlatforms = + 'The platforms supported by this project. Platform folders (e.g. android/) will be generated in the target project.'; + const String kCommandHelpModel = 'When model is provided, StackedView will be used instead of StatelessWidget and a Model will be created.'; diff --git a/lib/src/services/process_service.dart b/lib/src/services/process_service.dart index 2a38427..6d98679 100644 --- a/lib/src/services/process_service.dart +++ b/lib/src/services/process_service.dart @@ -23,14 +23,31 @@ class ProcessService { _formattingLineLength = length ?? _configService.lineLength.toString(); } - /// It creates a new flutter app. + /// Creates a new flutter app. /// /// Args: /// appName (String): The name of the app that's going to be create. - Future runCreateApp({required String appName}) async { + /// shouldUseMinimalTempalte (bool): Uses minimal app template. + /// description (String): The description to use for your new Flutter project. + /// organization (String): The organization responsible for your new Flutter project. + /// platforms (List): The platforms supported by this project. + Future runCreateApp({ + required String appName, + bool shouldUseMinimalTemplate = true, + String? description, + String? organization, + List? platforms, + }) async { await _runProcess( programName: ksFlutter, - arguments: [ksCreate, appName], + arguments: [ + ksCreate, + appName, + shouldUseMinimalTemplate ? '-e' : '--no-empty', + if (description != null) '--description="$description"', + if (organization != null) '--org="$organization"', + if (platforms != null) '--platforms=${platforms.join(",")}', + ], ); } diff --git a/lib/src/templates/template_constants.dart b/lib/src/templates/template_constants.dart index 4a5ef47..03df448 100644 --- a/lib/src/templates/template_constants.dart +++ b/lib/src/templates/template_constants.dart @@ -1,11 +1,11 @@ // ------- Template names -------- -const String kTemplateNameView = 'view'; -const String kTemplateNameService = 'service'; const String kTemplateNameApp = 'app'; const String kTemplateNameBottomSheet = 'bottom_sheet'; const String kTemplateNameDialog = 'dialog'; const String kTemplateNameGenerate = 'generate'; +const String kTemplateNameService = 'service'; const String kTemplateNameUpdate = 'update'; +const String kTemplateNameView = 'view'; const String kTemplateNameWidget = 'widget'; // ------- Template Types -------- diff --git a/test/helpers/test_helpers.mocks.dart b/test/helpers/test_helpers.mocks.dart index b79178c..b19dacd 100644 --- a/test/helpers/test_helpers.mocks.dart +++ b/test/helpers/test_helpers.mocks.dart @@ -1146,12 +1146,24 @@ class MockProcessService extends _i1.Mock implements _i16.ProcessService { returnValueForMissingStub: null, ); @override - _i6.Future runCreateApp({required String? appName}) => + _i6.Future runCreateApp({ + required String? appName, + bool? shouldUseMinimalTemplate = true, + String? description, + String? organization, + List? platforms, + }) => (super.noSuchMethod( Invocation.method( #runCreateApp, [], - {#appName: appName}, + { + #appName: appName, + #shouldUseMinimalTemplate: shouldUseMinimalTemplate, + #description: description, + #organization: organization, + #platforms: platforms, + }, ), returnValue: _i6.Future.value(), returnValueForMissingStub: _i6.Future.value(),