@@ -4,29 +4,30 @@ import 'dart:convert';
44import 'dart:io' ;
55
66import 'package:args/args.dart' ;
7- import 'package:nylo_framework/cli_dialog/cli_dialog.dart' ;
8- import 'package:nylo_framework/json_dart_generator/dart_code_generator.dart' ;
9- import 'package:nylo_framework/metro/stubs/config_stub.dart' ;
10- import 'package:nylo_framework/metro/stubs/form_stub.dart' ;
11- import 'package:nylo_framework/metro/stubs/interceptor_stub.dart' ;
12- import 'package:nylo_framework/metro/stubs/navigation_hub_stub.dart' ;
13- import 'package:nylo_framework/metro/stubs/route_guard_stub.dart' ;
14- import 'package:nylo_framework/metro/stubs/widget_state_managed_stub.dart' ;
7+ import 'package:nylo_framework/metro/stubs/custom_command_stub.dart' ;
8+ import '/cli_dialog/cli_dialog.dart' ;
9+ import '/json_dart_generator/dart_code_generator.dart' ;
10+ import '/metro/stubs/config_stub.dart' ;
11+ import '/metro/stubs/form_stub.dart' ;
12+ import '/metro/stubs/interceptor_stub.dart' ;
13+ import '/metro/stubs/navigation_hub_stub.dart' ;
14+ import '/metro/stubs/route_guard_stub.dart' ;
15+ import '/metro/stubs/widget_state_managed_stub.dart' ;
1516import 'package:nylo_support/metro/models/metro_project_file.dart' ;
1617import 'package:nylo_support/metro/models/ny_command.dart' ;
17- import 'package:nylo_framework /metro/stubs/api_service_stub.dart' ;
18- import 'package:nylo_framework /metro/stubs/controller_stub.dart' ;
19- import 'package:nylo_framework /metro/stubs/event_stub.dart' ;
20- import 'package:nylo_framework /metro/stubs/model_stub.dart' ;
21- import 'package:nylo_framework /metro/stubs/network_method_stub.dart' ;
22- import 'package:nylo_framework /metro/stubs/page_stub.dart' ;
23- import 'package:nylo_framework /metro/stubs/page_w_controller_stub.dart' ;
24- import 'package:nylo_framework /metro/stubs/postman_api_service_stub.dart' ;
25- import 'package:nylo_framework /metro/stubs/provider_stub.dart' ;
26- import 'package:nylo_framework /metro/stubs/theme_colors_stub.dart' ;
27- import 'package:nylo_framework /metro/stubs/theme_stub.dart' ;
28- import 'package:nylo_framework /metro/stubs/widget_stateful_stub.dart' ;
29- import 'package:nylo_framework /metro/stubs/widget_stateless_stub.dart' ;
18+ import '/metro/stubs/api_service_stub.dart' ;
19+ import '/metro/stubs/controller_stub.dart' ;
20+ import '/metro/stubs/event_stub.dart' ;
21+ import '/metro/stubs/model_stub.dart' ;
22+ import '/metro/stubs/network_method_stub.dart' ;
23+ import '/metro/stubs/page_stub.dart' ;
24+ import '/metro/stubs/page_w_controller_stub.dart' ;
25+ import '/metro/stubs/postman_api_service_stub.dart' ;
26+ import '/metro/stubs/provider_stub.dart' ;
27+ import '/metro/stubs/theme_colors_stub.dart' ;
28+ import '/metro/stubs/theme_stub.dart' ;
29+ import '/metro/stubs/widget_stateful_stub.dart' ;
30+ import '/metro/stubs/widget_stateless_stub.dart' ;
3031import 'package:nylo_support/metro/constants/strings.dart' ;
3132import 'package:nylo_support/metro/metro_console.dart' ;
3233import 'package:nylo_support/metro/metro_service.dart' ;
@@ -124,6 +125,12 @@ List<NyCommand> allCommands = [
124125 arguments: ["-h" , "-f" ],
125126 category: "make" ,
126127 action: _makeConfig),
128+ NyCommand (
129+ name: "command" ,
130+ options: 1 ,
131+ arguments: ["-h" , "-f" ],
132+ category: "make" ,
133+ action: _makeCommand),
127134];
128135
129136/// Creates a config file for Nylo projects
@@ -155,6 +162,40 @@ _makeConfig(List<String> arguments) async {
155162 forceCreate: hasForceFlag ?? false );
156163}
157164
165+ /// Creates a command file for Nylo projects
166+ /// E.g. run: `dart run nylo_framework:main make:command OptimizeAssets`
167+ _makeCommand (List <String > arguments) async {
168+ parser.addFlag (helpFlag,
169+ abbr: 'h' , help: 'e.g. make:command OptimizeAssets' , negatable: false );
170+ parser.addFlag (forceFlag,
171+ abbr: 'f' ,
172+ help: 'Creates a new command file even if it already exists.' ,
173+ negatable: false );
174+ parser.addOption (commandCategoryOption,
175+ abbr: 'c' , help: 'The category for the command.' , defaultsTo: "app" );
176+
177+ final ArgResults argResults = parser.parse (arguments);
178+
179+ // options
180+ bool ? hasForceFlag = argResults[forceFlag];
181+ String categoryValue = argResults[commandCategoryOption] ?? "app" ;
182+
183+ MetroService .hasHelpFlag (argResults[helpFlag], parser.usage);
184+
185+ MetroService .checkArguments (arguments,
186+ 'You are missing the \' name\' of the command file that you want to create.\n e.g. make:command update_cocopods' );
187+
188+ String commandName = argResults.arguments.first.snakeCase
189+ .replaceAll (RegExp (r'(_?command)' ), "" );
190+
191+ ReCase classReCase = ReCase (commandName);
192+
193+ String stubCommand =
194+ customCommandStub (customCommand: classReCase, category: categoryValue);
195+ await MetroService .makeCommand (classReCase.snakeCase, stubCommand,
196+ forceCreate: hasForceFlag ?? false , category: categoryValue);
197+ }
198+
158199/// Creates a config file for Nylo projects
159200/// E.g. run: `dart run nylo_framework:main make:form register_form`
160201_makeForm (List <String > arguments) async {
0 commit comments