-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create command to create lifecycle component
- Loading branch information
Showing
4 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
..._server/lib/cli/commands/create/create_components/create_lifecycle_component_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'package:change_case/change_case.dart'; | ||
import 'package:mason_logger/mason_logger.dart'; | ||
import 'package:revali_server/cli/commands/create/create_components/create_a_component_command.dart'; | ||
|
||
class CreateLifecycleComponentCommand extends CreateAComponentCommand { | ||
CreateLifecycleComponentCommand({ | ||
required super.fs, | ||
required super.logger, | ||
}) { | ||
argParser.addOption( | ||
'name', | ||
abbr: 'n', | ||
help: 'The name of the lifecycle component', | ||
valueHelp: 'name', | ||
); | ||
} | ||
|
||
@override | ||
String get description => 'creates a new lifecycle component'; | ||
|
||
@override | ||
String get name => 'lifecycle Component'; | ||
|
||
@override | ||
String get fileName => '${_name.toSnakeCase()}.dart'; | ||
|
||
@override | ||
String get directory => config.createPaths.lifecycleComponent; | ||
|
||
String _name = ''; | ||
void namePrompt() { | ||
var name = argResults?['name'] as String?; | ||
|
||
while (name == null || name.isEmpty) { | ||
name = logger.prompt( | ||
"What is the name of the ${green.wrap("Lifecycle Component")}?", | ||
); | ||
} | ||
|
||
_name = name.trim(); | ||
} | ||
|
||
@override | ||
void prompt() { | ||
namePrompt(); | ||
} | ||
|
||
@override | ||
String content() => ''' | ||
import 'package:revali_router/revali_router.dart'; | ||
class ${_name.toPascalCase()} implements LifecycleComponent { | ||
const ${_name.toPascalCase()}(); | ||
GuardResult guard() { | ||
// TODO: implement guard | ||
throw UnimplementedError(); | ||
} | ||
MiddlewareResult middleware() { | ||
// TODO: implement middleware | ||
throw UnimplementedError(); | ||
} | ||
InterceptorPreResult preInterceptor() { | ||
// TODO: implement preInterceptor | ||
throw UnimplementedError(); | ||
} | ||
InterceptorPostResult postInterceptor() { | ||
// TODO: implement postInterceptor | ||
throw UnimplementedError(); | ||
} | ||
ExceptionCatcherResult<Exception> exceptionCatcher() { | ||
// TODO: implement exceptionCatcher | ||
throw UnimplementedError(); | ||
} | ||
} | ||
'''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.