From 56a2e09e77e53a301369062a093a94b4423864ec Mon Sep 17 00:00:00 2001 From: Pebkac03 Date: Sat, 14 Dec 2024 02:43:16 +0100 Subject: [PATCH 1/2] fix: enforce snake case app name --- lib/src/commands/create/create_app_command.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/commands/create/create_app_command.dart b/lib/src/commands/create/create_app_command.dart index 7c170ca..17f500f 100644 --- a/lib/src/commands/create/create_app_command.dart +++ b/lib/src/commands/create/create_app_command.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:args/command_runner.dart'; +import 'package:recase/recase.dart'; import 'package:stacked_cli/src/constants/command_constants.dart'; import 'package:stacked_cli/src/constants/config_constants.dart'; import 'package:stacked_cli/src/constants/message_constants.dart'; @@ -80,8 +81,12 @@ class CreateAppCommand extends Command { configFilePath: argResults![ksConfigPath], ); - final workingDirectory = argResults!.rest.first; - final appName = workingDirectory.split('/').last; + final List workingDirectoryList = + argResults!.rest.first.split('/'); + workingDirectoryList + .add(ReCase(workingDirectoryList.removeLast()).snakeCase); + final String appName = workingDirectoryList.last; + final String workingDirectory = workingDirectoryList.join('/'); final templateType = argResults![ksTemplateType]; _processService.formattingLineLength = argResults![ksLineLength]; From b8e6813f49146988f3d3640dc017a058fee07165 Mon Sep 17 00:00:00 2001 From: Pebkac03 Date: Sat, 4 Jan 2025 03:07:36 +0100 Subject: [PATCH 2/2] feat: prompt user if app name is not snake case --- .../commands/create/create_app_command.dart | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/src/commands/create/create_app_command.dart b/lib/src/commands/create/create_app_command.dart index 17f500f..8c46ba4 100644 --- a/lib/src/commands/create/create_app_command.dart +++ b/lib/src/commands/create/create_app_command.dart @@ -81,13 +81,25 @@ class CreateAppCommand extends Command { configFilePath: argResults![ksConfigPath], ); + final templateType = argResults![ksTemplateType]; + + // appName validation and recasing final List workingDirectoryList = argResults!.rest.first.split('/'); - workingDirectoryList - .add(ReCase(workingDirectoryList.removeLast()).snakeCase); - final String appName = workingDirectoryList.last; - final String workingDirectory = workingDirectoryList.join('/'); - final templateType = argResults![ksTemplateType]; + final String originalAppName = workingDirectoryList.removeLast(); + final String appName = ReCase(originalAppName).snakeCase; + if (originalAppName != appName) { + _log.info( + message: + '$originalAppName is not snake_case as required by dart, did you mean $appName? [Y/N]'); + String input; + do { + input = stdin.readLineSync()?.toUpperCase().trim() ?? ''; + } while (!(input == 'Y' || input == 'N')); + input == 'N' ? throw 'error: project name not snake_case' : {}; + } + workingDirectoryList.add(appName); + final workingDirectory = workingDirectoryList.join('/'); _processService.formattingLineLength = argResults![ksLineLength]; await _processService.runCreateApp(