JS Arch CLI

Code generator to facilitate development

Get Start:

dart pub global activate js_cli

Overview

To make it easier and more intuitive to implement Uncle Bob's Clean Architecture. This CLI provides the base structure, where it will dynamically generate the Classes as shown in the examples below.


Commands:

# Generate Feature
js_cli g layer complete /lib/src/features/home
Result


# Generate Entity
js_cli g entity /lib/src/features/home Home
Result
// home.entitiy.dart 
class HomeEntity {

  HomeEntity();

}


# Generate UseCase
js_cli g usecase /lib/src/features/home GetHomeCards
Result
//get_home_cards.usecase.dart
abstract class GetHomeCardsUsecase {
  Future<void> call();
}
//get_home_cards_imp.usecase.dart
import 'get_home_cards_usecase.dart';

class GetHomeCardsImpUsecase implements GetHomeCardsUsecase {
  @override
  Future<void> call() {
    // TODO: implement call
    throw UnimplementedError();
  }
  
}
  


# Generate Repository
js_cli g repository /lib/src/features/home GetHomeCards
Result
// domain/repositories/get_home_cards.repository.dart
abstract class GetHomeCardsRepository {
  Future<void> call();
}
// data/repositories/get_home_cards_imp.repository.dart
import '../../domain/repositories/get_home_cards_repository.dart';

class GetHomeCardsImpRepository implements GetHomeCardsRepository {
  @override
  Future<void> call() {
    // TODO: implement call
    throw UnimplementedError();
  }
}


# Generate Dto
js_cli g dto /lib/src/features/home Home
Result
// home_dto.dart
import '../../domain/models/entities/home_entity.dart';

class HomeDto extends HomeEntity {

  HomeDto() : super();

}


# Generate Error
js_cli g error /lib/src/core/errors Generic  
Result
// generic.error.dart
class GenericError implements Exception {
  final String _message;
  final Exception innerException;

  GenericError(String message, this.innerException) : _message = message;

  String get message => _message;
}



$ js_cli g layer complete ./teste/features/dashboard
################### Clean Arch CLI ###################
generating complete layer....
COMPLETE layer created

$ js_cli g entity ./teste/features/dashboard Viewer
################### Clean Arch CLI ###################
generating usecase Viewer....
Viewer created

$ js_cli g usecase ./teste/features/dashboard getViewer
################### Clean Arch CLI ###################
generating usecase getViewer....
getViewer created

$ js_cli g repository ./teste/features/dashboard getViewer
################### Clean Arch CLI ###################
generating repository getViewer....
getViewer created

$ js_cli g dto ./teste/features/dashboard Viewer
################### Clean Arch CLI ###################
generating dto Viewer....
ViewerDto created


Reserved words

Reserved words can be used in the templet files that are generated in .js_cli/templete the reserved words must be used inside mustaches {{}} example {{name}}, can also be used in reserved words an extension, example {{name.pascalCase}} whose extension will format the word as needed, you can check the lists below for all reserved words and extensions

  • Reserved words can be edited in my_project\.js_cli\configs.json
reserved wordsdefault
nameinput input by the terminal, this value is the last parameter of the expression to generate the templates
pathinput input via terminal, path where the new file will be generated
moduleinput input by the terminal, name of the module that will generate the new files
fileExtensiondart
repositoryPathInterfacedomain/repositories
repositoryNameFileInterface{{name.snakeCase}}_repository
repositoryPathdata/repositories
repositoryNameFile{{name.snakeCase}}_imp_repository
repositoryNameClassInterface{{name.pascalCase}}Repository
repositoryNameClass{{name.pascalCase}}ImpRepository
datasourcePathInterfacedata/datasources
datasourceNameFileInterface{{name.snakeCase}}_datasource
datasourcePathexternal/datasources
datasourceNameFile{{name.snakeCase}}_imp_datasource
datasourceNameClassInterface{{name.pascalCase}}Datasource
datasourceNameClass{{name.pascalCase}}ImpDatasource
usecasePathInterfacedomain/usecases
usecaseNameFileInterface{{name.snakeCase}}_usecase
usecasePathdomain/usecases
usecaseNameFile{{name.snakeCase}}_imp_usecase
usecaseNameClassInterface{{name.pascalCase}}Usecase
usecaseNameClass{{name.pascalCase}}ImpUsecase
pagePathpresentation/ui/pages/{{name.snakeCase}}
pageNameFile{{name.snakeCase}}_page
pageNameClass{{name.pascalCase}}Page
controllerPathpresentation/ui/pages/{{name.snakeCase}}
controllerNameFile{{name.snakeCase}}_controller
controllerNameClass{{name.pascalCase}}Controller

Extensions

extensionExemple
camelCasetesteCase
constantCaseTESTE_CASE
sentenceCaseTeste case
snakeCaseteste_case
dotCaseteste.case
paramCaseteste-case
pathCaseteste/case
pascalCaseTesteCase
headerCaseTeste-Case
titleCaseTeste Case

Triggers

Replace

in .js_cli/templete a {{term}}_replace_trigger.json file is generated where from your annotation it can apply a replace to any input expression, for example:

[
    {
        "pathFile": "{{path}}\\{{module}}_module.dart",
        "from": "//imports",
        "to": "//imports\nimport '{{controllerPath}}/{{controllerNameFile}}.dart';"
    },
    {
        "pathFile": "{{path}}\\{{module}}_module.dart",
        "from": "//Dependence",
        "to": "//Dependence\nfinal {{controllerNameClass.camelCase}} = {{controllerNameClass.pascalCase}};"
    }
]

where will generate a variable from the expression

Create new file

in .js_cli / templete, a file {{term}} _ new_file_trigger.json is generated where, from his annotation, he can create a new file with the pre-defined templete, for example:

Note, the generate variable must be true to generate the file.

[
    {
        "pathFile": "{{path}}\\{{module}}_module",
        "pathTemplete": ".js_cli/template/layer/complete_new_file_exemple.template",
        "generate": true
    }
]

Templete file

.js_cli/template/layer/complete_new_file_exemple.template

class {{module.pascalCase}}Module extends Module {
  @override
  final List<Bind> binds = [
    //Usercases

    //Repositories

    //Datasources
      
    //Controllers
  ];

  @override
  final List<ModularRoute> routes = [
    //Pages
  ];
}

where will generate a variable from the expression

Libraries

app_module
common_commands_controller
common_module
configs_file
constants
directory_utils
dto_template
entity_template
error_template
file_exists_error
folder_structure
generate_complete
generate_controller
generate_controller_file
generate_data
generate_datasource_file
generate_datasources
generate_domain
generate_domain_controller
generate_dto
generate_entity
generate_error
generate_external
generate_layer_controller
generate_module
generate_new_file
generate_page
generate_page_file
generate_presentation
generate_replace_file
generate_repositories
generate_repository_file
generate_usecase_file
generate_usecases
get_version
help_command
igenerate_controller
igenerate_datasources
igenerate_dto
igenerate_entity
igenerate_error
igenerate_layers
igenerate_page
igenerate_repositories
igenerate_usecases
iget_version_cli
ihelp_command
new_file_dto
output_utils
replace_dto
replace_utils
reserved_words
validate_arguments
wellcome_message