Skip to content

Commit 5167d27

Browse files
committed
v6.7.0
1 parent 523f200 commit 5167d27

File tree

10 files changed

+833
-30
lines changed

10 files changed

+833
-30
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [6.7.0] - 2025-04-08
2+
3+
* Added: `make:command` to metro cli so you can create custom commands in Nylo 🚀
4+
* Added: New stub for creating commands
5+
* Update metro cli to support custom commands
6+
* New ny_cli.dart file to handle custom commands
7+
* Update pubspec.yaml
8+
19
## [6.6.5] - 2025-04-01
210

311
* Update pubspec.yaml

bin/main.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@ import 'package:nylo_framework/metro/metro.dart' as metro_cli;
55
import 'package:nylo_support/metro/metro_service.dart';
66

77
void main(List<String> arguments) async {
8+
// Discover custom commands
9+
final customCommands = await MetroService.discoverCustomCommands();
10+
11+
// Merge with built-in commands
12+
final allCommands = [...metro_cli.allCommands, ...customCommands];
13+
14+
String commandMenu = metroMenu;
15+
if (customCommands.isNotEmpty) {
16+
commandMenu += '\n[Custom Commands]\n';
17+
for (var customCommand in customCommands) {
18+
commandMenu += ' ${customCommand.category}:${customCommand.name}\n';
19+
}
20+
}
21+
22+
// Run with the combined command set
823
await MetroService.runCommand(arguments,
9-
allCommands: metro_cli.allCommands, menu: metroMenu);
24+
allCommands: allCommands, menu: commandMenu);
1025
exit(0);
1126
}

example/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,15 @@ packages:
427427
path: ".."
428428
relative: true
429429
source: path
430-
version: "6.6.4"
430+
version: "6.7.0"
431431
nylo_support:
432432
dependency: transitive
433433
description:
434434
name: nylo_support
435-
sha256: "6c7fdb11a68b6e0fed128edfd7d7d6459db43ad35df5613a0b2387062f3641a2"
435+
sha256: "1f41ccec96265131563da22af17228c0001cfd9de23fbd5b556bf9d594f11d78"
436436
url: "https://pub.dev"
437437
source: hosted
438-
version: "6.23.0"
438+
version: "6.25.0"
439439
path:
440440
dependency: transitive
441441
description:

lib/metro/menu.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ All commands:
2929
make:route_guard
3030
make:config
3131
make:interceptor
32+
make:command
3233
""";

lib/metro/metro.dart

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@ import 'dart:convert';
44
import 'dart:io';
55

66
import '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';
1516
import 'package:nylo_support/metro/models/metro_project_file.dart';
1617
import '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';
3031
import 'package:nylo_support/metro/constants/strings.dart';
3132
import 'package:nylo_support/metro/metro_console.dart';
3233
import '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.\ne.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

Comments
 (0)