Skip to content

Commit

Permalink
feat: add more arguments to create app command (#27)
Browse files Browse the repository at this point in the history
Add more arguments to create app command

- Added `empty` argument
- Added `description` argument
- Added `org` argument
- Added `platforms` argument
  • Loading branch information
ferrarafer committed Jun 22, 2023
1 parent 47a5623 commit 10cdefb
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 39 deletions.
89 changes: 57 additions & 32 deletions lib/src/commands/create/create_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ColorizedLogService>();
final _analyticsService = locator<AnalyticsService>();
final _configService = locator<ConfigService>();
final _fileService = locator<FileService>();
final _log = locator<ColorizedLogService>();
final _processService = locator<ProcessService>();
final _templateService = locator<TemplateService>();
final _analyticsService = locator<AnalyticsService>();

@override
String get description =>
Expand All @@ -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
Expand All @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions lib/src/constants/command_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions lib/src/constants/message_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.';

Expand Down
23 changes: 20 additions & 3 deletions lib/src/services/process_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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<String>): The platforms supported by this project.
Future<void> runCreateApp({
required String appName,
bool shouldUseMinimalTemplate = true,
String? description,
String? organization,
List<String>? 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(",")}',
],
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/templates/template_constants.dart
Original file line number Diff line number Diff line change
@@ -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 --------
Expand Down
16 changes: 14 additions & 2 deletions test/helpers/test_helpers.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,24 @@ class MockProcessService extends _i1.Mock implements _i16.ProcessService {
returnValueForMissingStub: null,
);
@override
_i6.Future<void> runCreateApp({required String? appName}) =>
_i6.Future<void> runCreateApp({
required String? appName,
bool? shouldUseMinimalTemplate = true,
String? description,
String? organization,
List<String>? platforms,
}) =>
(super.noSuchMethod(
Invocation.method(
#runCreateApp,
[],
{#appName: appName},
{
#appName: appName,
#shouldUseMinimalTemplate: shouldUseMinimalTemplate,
#description: description,
#organization: organization,
#platforms: platforms,
},
),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
Expand Down

0 comments on commit 10cdefb

Please sign in to comment.