Skip to content

Commit

Permalink
v5.31.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agordn52 committed Jul 1, 2024
1 parent 07f7ab7 commit dda4ef1
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 22 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [5.31.0] - 2024-07-02

* Ability to create Forms using Metro. E.g. `metro make:form register`
* New stub for creating Forms
* Small refactor to model stub
* Refactor `slate` command to `metro slate:publish`
* New `metro slate:install` command to install the slate package and publish all the files

## [5.30.0] - 2024-06-16

* Update stubs
Expand Down
58 changes: 53 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
base58check:
dependency: transitive
description:
name: base58check
sha256: "6c300dfc33e598d2fe26319e13f6243fea81eaf8204cb4c6b69ef20a625319a5"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
bech32:
dependency: transitive
description:
name: bech32
sha256: "156cbace936f7720c79a79d16a03efad343b1ef17106716e04b8b8e39f99f7f7"
url: "https://pub.dev"
source: hosted
version: "0.2.2"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -57,6 +73,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
dart_console:
dependency: transitive
description:
Expand All @@ -65,6 +97,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.0"
date_field:
dependency: transitive
description:
name: date_field
sha256: "8643c8e5f2ee55b4b389fc567ee27186c5a63570f545b291d61f02ab6ca7981d"
url: "https://pub.dev"
source: hosted
version: "5.2.1"
dio:
dependency: transitive
description:
Expand Down Expand Up @@ -131,6 +171,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_multi_formatter:
dependency: transitive
description:
name: flutter_multi_formatter
sha256: "3495dc0056c96e467039a05bd184a5285c271a0efb2024a7030c7e84ba828994"
url: "https://pub.dev"
source: hosted
version: "2.12.8"
flutter_secure_storage:
dependency: transitive
description:
Expand Down Expand Up @@ -291,15 +339,15 @@ packages:
path: ".."
relative: true
source: path
version: "5.30.0"
version: "5.31.0"
nylo_support:
dependency: transitive
description:
name: nylo_support
sha256: "56d7f9f598715320a2ff95050b0d138b9bd0b108d3eb549160869ec64ac609ed"
sha256: "8d070b707ebc12c31ee4f82b7e4c77a3eb578ffa66da4114788e83c244344444"
url: "https://pub.dev"
source: hosted
version: "5.76.0"
version: "5.77.0"
page_transition:
dependency: transitive
description:
Expand Down Expand Up @@ -408,10 +456,10 @@ packages:
dependency: transitive
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
sha256: "5c3004a4a8dbb94bd4bf5412a4def4acdaa12e12f269737a5751369e12d1a962"
url: "https://pub.dev"
source: hosted
version: "0.27.7"
version: "0.28.0"
shared_preferences:
dependency: transitive
description:
Expand Down
6 changes: 4 additions & 2 deletions lib/metro/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ All commands:
make:api_service
make:interceptor
make:theme
make:form
make:route_guard
make:config
publish
publish:slate
slate
slate:publish
slate:install
""";
71 changes: 66 additions & 5 deletions lib/metro/metro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:args/args.dart';
import 'package:nylo_framework/cli_dialog/cli_dialog.dart';
import 'package:nylo_framework/json_dart_generator/dart_code_generator.dart';
import 'package:nylo_framework/metro/stubs/config_stub.dart';
import 'package:nylo_framework/metro/stubs/form_stub.dart';
import 'package:nylo_framework/metro/stubs/interceptor_stub.dart';
import 'package:nylo_framework/metro/stubs/page_bottom_nav_stub.dart';
import 'package:nylo_framework/metro/stubs/route_guard_stub.dart';
Expand Down Expand Up @@ -98,35 +99,66 @@ List<NyCommand> allCommands = [
arguments: ["-h", "-f"],
category: "make",
action: _makeRouteGuard),
NyCommand(
name: "form",
options: 1,
arguments: ["-h", "-f"],
category: "make",
action: _makeForm),
NyCommand(
name: "config",
options: 1,
arguments: ["-h", "-f"],
category: "make",
action: _makeConfig),
NyCommand(
name: "slate",
name: "install",
options: 1,
arguments: ["-h", "-f"],
category: "slate",
action: _installSlate),
NyCommand(
name: "publish",
options: 1,
arguments: ["-h", "-f"],
category: "publish",
category: "slate",
action: _publishSlate),
];

/// Publishes the contents from a Slate package into a Nylo project.
/// E.g. run: `dart run nylo_framework:main publish:slate example_slate`
/// E.g. run: `dart run nylo_framework:main slate:publish example_slate`
_publishSlate(List<String> arguments) async {
parser.addFlag(helpFlag,
abbr: 'h', help: 'e.g. publish:slate example_slate', negatable: false);
abbr: 'h', help: 'e.g. slate:publish example_slate', negatable: false);

final ArgResults argResults = parser.parse(arguments);

MetroService.hasHelpFlag(argResults[helpFlag], parser.usage);

MetroService.checkArguments(arguments,
'You are missing the \'name\' of the slate package.\ne.g. slate:publish example_slate');

String slateName = argResults.arguments.first;

await MetroService.runProcess("dart run $slateName:main publish:all");
}

/// Installs the contents from a Slate package into a Nylo project.
/// E.g. run: `dart run nylo_framework:main slate:install example_slate`
_installSlate(List<String> arguments) async {
parser.addFlag(helpFlag,
abbr: 'h', help: 'e.g. slate:install example_slate', negatable: false);

final ArgResults argResults = parser.parse(arguments);

MetroService.hasHelpFlag(argResults[helpFlag], parser.usage);

MetroService.checkArguments(arguments,
'You are missing the \'name\' of the slate package.\ne.g. publish:slate example_slate');
'You are missing the \'name\' of the slate package.\ne.g. slate:install example_slate');

String slateName = argResults.arguments.first;

await MetroService.runProcess("dart pub add $slateName");
await MetroService.runProcess("dart run $slateName:main publish:all");
}

Expand Down Expand Up @@ -159,6 +191,35 @@ _makeConfig(List<String> arguments) async {
forceCreate: hasForceFlag ?? false);
}

/// Creates a config file for Nylo projects
/// E.g. run: `dart run nylo_framework:main make:form register_form`
_makeForm(List<String> arguments) async {
parser.addFlag(helpFlag,
abbr: 'h', help: 'e.g. make:form register_form', negatable: false);
parser.addFlag(forceFlag,
abbr: 'f',
help: 'Creates a new form file even if it already exists.',
negatable: false);

final ArgResults argResults = parser.parse(arguments);

bool? hasForceFlag = argResults[forceFlag];

MetroService.hasHelpFlag(argResults[helpFlag], parser.usage);

MetroService.checkArguments(arguments,
'You are missing the \'name\' of the form you want to create.\ne.g. make:form login_form');

String formName =
argResults.arguments.first.snakeCase.replaceAll(RegExp(r'(_?form)'), "");

ReCase classReCase = ReCase(formName);

String stubForm = formStub(classReCase);
await MetroService.makeForm(classReCase.snakeCase, stubForm,
forceCreate: hasForceFlag ?? false);
}

/// Creates a Stateful Widget file for Nylo projects
/// E.g. run: `dart run nylo_framework:main make:stateful_widget video_player_widget`
_makeStatefulWidget(List<String> arguments) async {
Expand Down
58 changes: 58 additions & 0 deletions lib/metro/stubs/form_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:recase/recase.dart';

/// This stub is used to create a new NyForm.
String formStub(ReCase className) => '''
import 'package:nylo_framework/nylo_framework.dart';
class ${className.pascalCase}Form extends NyFormData {
${className.pascalCase}Form({String? name}) : super(name ?? "${className.snakeCase}");
@override
fields() => [
Field("Name", value: "Customize your form ⚡️"),
[
Field("Price"),
Field("Favourite Color", value: ["Red", "Blue", "Green"], selected: "Green"),
],
];
/// Cast the fields to their respective types
/// All available types are below
/// https://nylo.dev/docs/5.20.0/form#casts
@override
Map<String, dynamic> cast() => {
"Name": FormCast(),
"Price": FormCast.currency("usd"),
"Favourite Color": FormCast.picker(),
};
/// Validate the fields
/// All available validations are below
/// https://nylo.dev/docs/5.20.0/validation#validation-rules
@override
Map<String, dynamic> validate() => {
"Name": FormValidator("not_empty|max:20"),
"Price": FormValidator("not_empty"),
"Favourite Color": FormValidator("not_empty"),
};
/// Dummy data for the form
/// This is used to populate the form with dummy data
/// It will be removed when your .env file is set to production
@override
Map<String, dynamic> dummyData() => {
// "Name": "John Doe",
// "Price": 123.45,
};
/// Style the TextFields
/// This is used to style the fields
/// Options: compact
@override
Map<String, dynamic> style() => {
// "Name": "compact",
// "Price": "compact",
};
}
''';
2 changes: 0 additions & 2 deletions lib/metro/stubs/model_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
String modelStub({String? modelName}) => '''
import 'package:nylo_framework/nylo_framework.dart';
/// $modelName Model.
class $modelName extends Model {
$modelName();
Expand Down
6 changes: 4 additions & 2 deletions lib/nylo_framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export 'package:nylo_support/events/sync_auth_to_backpack.dart';
export 'package:nylo_support/validation/ny_validator.dart';
export 'package:nylo_support/validation/rules.dart';
export 'package:nylo_support/widgets/ny_future_builder.dart';
export 'package:nylo_support/widgets/ny_form.dart';
export 'package:nylo_support/widgets/ny_rich_text.dart';
export 'package:nylo_support/widgets/ny_text_field.dart';
export 'package:nylo_support/widgets/fields/form_picker.dart';
export 'package:nylo_support/router/models/nyrouter_route_guard.dart';
export 'package:nylo_support/router/observers/ny_route_history_observer.dart';
export 'package:nylo_support/nylo.dart';
Expand All @@ -43,8 +45,8 @@ export 'package:nylo_support/networking/ny_api_service.dart';
export 'package:nylo_support/networking/ny_base_api_service.dart';
export 'package:error_stack/error_stack.dart';
export 'package:skeletonizer/skeletonizer.dart';
export 'package:dio/dio.dart';
export 'package:flutter_secure_storage/flutter_secure_storage.dart';
export 'package:dio/dio.dart';

/// Nylo version
const String nyloVersion = 'v5.30.0';
const String nyloVersion = 'v5.31.0';
Loading

0 comments on commit dda4ef1

Please sign in to comment.