Skip to content

Commit c2dc91b

Browse files
feat: add workspace flag support for monorepo packages (#1667)
Closes #1635 Co-authored-by: unicoderbot[bot] <269805761+unicoderbot[bot]@users.noreply.github.com> Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>
1 parent 34a499d commit c2dc91b

18 files changed

Lines changed: 337 additions & 7 deletions

lib/src/commands/create/commands/app_ui_package.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
44
/// {@template very_good_create_app_ui_package_command}
55
/// A [CreateSubCommand] for creating App UI packages.
66
/// {@endtemplate}
7-
class CreateAppUiPackage extends CreateSubCommand with Publishable {
7+
class CreateAppUiPackage extends CreateSubCommand with Publishable, Workspace {
88
/// {@macro very_good_create_app_ui_package_command}
99
CreateAppUiPackage({
1010
required super.logger,

lib/src/commands/create/commands/create_subcommand.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ typedef MasonGeneratorFromBundle = Future<MasonGenerator> Function(MasonBundle);
4242
///
4343
/// For sub commands that receive a publishable flag, sub classes must mix with
4444
/// [Publishable].
45+
///
46+
/// For sub commands that receive a workspace flag, sub classes must mix with
47+
/// [Workspace].
4548
abstract class CreateSubCommand extends Command<int> {
4649
/// {@macro create_subcommand}
4750
CreateSubCommand({
@@ -99,6 +102,16 @@ abstract class CreateSubCommand extends Command<int> {
99102
help: 'Whether the generated project is intended to be published.',
100103
);
101104
}
105+
106+
if (this is Workspace) {
107+
argParser.addFlag(
108+
'workspace',
109+
aliases: ['ws'],
110+
help:
111+
'Whether the generated project should resolve its dependencies '
112+
'from a parent Pub workspace.',
113+
);
114+
}
102115
}
103116

104117
/// The logger user to notify the user of the command's progress.
@@ -237,6 +250,7 @@ abstract class CreateSubCommand extends Command<int> {
237250
///
238251
/// For subcommands that mix with [OrgName], it includes 'org_name'.
239252
/// For subcommands that mix with [Publishable], it includes 'publishable'.
253+
/// For subcommands that mix with [Workspace], it includes 'workspace'.
240254
@mustCallSuper
241255
Map<String, dynamic> getTemplateVars() {
242256
final projectName = this.projectName;
@@ -247,6 +261,7 @@ abstract class CreateSubCommand extends Command<int> {
247261
'description': projectDescription,
248262
if (this is OrgName) 'org_name': (this as OrgName).orgName,
249263
if (this is Publishable) 'publishable': (this as Publishable).publishable,
264+
if (this is Workspace) 'workspace': (this as Workspace).workspace,
250265
};
251266
}
252267
}
@@ -318,3 +333,12 @@ mixin Publishable on CreateSubCommand {
318333
/// Gets the publishable flag.
319334
bool get publishable => argResults['publishable'] as bool? ?? false;
320335
}
336+
337+
/// Mixin for [CreateSubCommand] subclasses that receives the workspace flag.
338+
///
339+
/// Takes care of parsing it from [argResults] and pass it
340+
/// to the brick generator.
341+
mixin Workspace on CreateSubCommand {
342+
/// Gets the workspace flag.
343+
bool get workspace => argResults['workspace'] as bool? ?? false;
344+
}

lib/src/commands/create/commands/dart_cli.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
44
/// {@template very_good_create_dart_cli_command}
55
/// A [CreateSubCommand] for creating Dart command line interfaces.
66
/// {@endtemplate}
7-
class CreateDartCLI extends CreateSubCommand with Publishable {
7+
class CreateDartCLI extends CreateSubCommand with Publishable, Workspace {
88
/// {@macro very_good_create_dart_cli_command}
99
CreateDartCLI({
1010
required super.logger,

lib/src/commands/create/commands/dart_package.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
44
/// {@template very_good_create_dart_package_command}
55
/// A [CreateSubCommand] for creating Dart packages.
66
/// {@endtemplate}
7-
class CreateDartPackage extends CreateSubCommand with Publishable {
7+
class CreateDartPackage extends CreateSubCommand with Publishable, Workspace {
88
/// {@macro very_good_create_dart_package_command}
99
CreateDartPackage({
1010
required super.logger,

lib/src/commands/create/commands/flame_game.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
44
/// {@template very_good_create_flame_game_command}
55
/// A [CreateSubCommand] for creating Flame games.
66
/// {@endtemplate}
7-
class CreateFlameGame extends CreateSubCommand with OrgName, Publishable {
7+
class CreateFlameGame extends CreateSubCommand
8+
with OrgName, Publishable, Workspace {
89
/// {@macro very_good_create_flame_game_command}
910
CreateFlameGame({
1011
required super.logger,

lib/src/commands/create/commands/flutter_app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
55
/// A [CreateSubCommand] for creating Flutter apps.
66
/// {@endtemplate}
77
class CreateFlutterApp extends CreateSubCommand
8-
with OrgName, MultiTemplates, Publishable {
8+
with OrgName, MultiTemplates, Publishable, Workspace {
99
/// {@macro very_good_create_flutter_app_command}
1010
CreateFlutterApp({
1111
required super.logger,

lib/src/commands/create/commands/flutter_package.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
44
/// {@template very_good_create_flutter_package_command}
55
/// A [CreateSubCommand] for creating Flutter packages.
66
/// {@endtemplate}
7-
class CreateFlutterPackage extends CreateSubCommand with Publishable {
7+
class CreateFlutterPackage extends CreateSubCommand
8+
with Publishable, Workspace {
89
/// {@macro very_good_create_flutter_package_command}
910
CreateFlutterPackage({
1011
required super.logger,

lib/src/commands/create/commands/flutter_plugin.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
44
/// {@template very_good_create_flutter_plugin_command}
55
/// A [CreateSubCommand] for creating Flutter plugins.
66
/// {@endtemplate}
7-
class CreateFlutterPlugin extends CreateSubCommand with Publishable, OrgName {
7+
class CreateFlutterPlugin extends CreateSubCommand
8+
with Publishable, OrgName, Workspace {
89
/// {@macro very_good_create_flutter_plugin_command}
910
CreateFlutterPlugin({
1011
required super.logger,

lib/src/mcp/mcp_server.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ Only available for subcommands: flutter_plugin with all values) and flame_game (
138138
'publishable': BooleanSchema(
139139
description: '''
140140
Whether package is intended for publishing (flutter_package, dart_package only)''',
141+
),
142+
'workspace': BooleanSchema(
143+
description: '''
144+
Whether the generated project should resolve its dependencies from a parent Pub workspace.''',
141145
),
142146
'executable-name': StringSchema(
143147
description: '''
@@ -348,6 +352,11 @@ Only one value can be selected.
348352
if (args['publishable'] == true) {
349353
cliArgs.add('--publishable');
350354
}
355+
if (args['workspace'] == true) {
356+
cliArgs.add('--workspace');
357+
} else if (args['workspace'] == false) {
358+
cliArgs.add('--no-workspace');
359+
}
351360
if (args['executable-name'] != null) {
352361
cliArgs.addAll(['--executable-name', args['executable-name']! as String]);
353362
}

test/src/commands/create/commands/app_ui_package_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Usage: very_good create app_ui_package <project-name> [arguments]
3434
--description The description for this new project.
3535
(defaults to "A Very Good Project created by Very Good CLI.")
3636
--publishable Whether the generated project is intended to be published.
37+
--[no-]workspace Whether the generated project should resolve its dependencies from a parent Pub workspace.
3738
3839
Run "very_good help" to see global options.''',
3940
];
@@ -74,6 +75,7 @@ void main() {
7475
);
7576
expect(command.logger, equals(logger));
7677
expect(command, isA<Publishable>());
78+
expect(command, isA<Workspace>());
7779
});
7880
});
7981

@@ -184,6 +186,7 @@ void main() {
184186
'project_name': 'my_app_ui',
185187
'description': '',
186188
'publishable': false,
189+
'workspace': false,
187190
},
188191
onVarsChanged: any(named: 'onVarsChanged'),
189192
),
@@ -195,6 +198,7 @@ void main() {
195198
'project_name': 'my_app_ui',
196199
'description': '',
197200
'publishable': false,
201+
'workspace': false,
198202
},
199203
logger: logger,
200204
),

0 commit comments

Comments
 (0)