Herbs CLI
Inspired by VueJS, Angular, dotnet and others, I would like to suggest the creation of a CLI to help the new herbs adopters
Usually developer use CLIs to easily start an project and principally the jr developers use it to maintain the project in the same architecture proposed by the framework.
The main idea of this CLI is to facilitate the creation of new projects and modules in your project that use herbs. In the future I believe this CLI can be an tool to check your herbs quality code, help you to modeling your clean archtecture, analisy logs and more, but for now it will start being something like a semi-inteligent code generator.
Herbs start
Propose 1
My initial propose is to build an entry project by the CLI like an template
Herbs new app -βgraphql -βknex-pg
(We can use --rest --mongo --knex-sql-server and other)
This will create an app with graphql that use a knex-repository, the generated files will be something like this:
βΒ Β βββ herbs.json
βΒ Β βββ index.js
βΒ Β βββ knexfile.js
βΒ Β βββ package.json
βΒ Β βββ src
βΒ Β βββ domain
βΒ Β βΒ Β βββ entities
βΒ Β βΒ Β βΒ Β βββ entity.js
βΒ Β βΒ Β βΒ Β βββ entity.test.js
βΒ Β βΒ Β βββ usecases
βΒ Β βΒ Β βββ createEntity.js
βΒ Β βΒ Β βββ createEntity.test.js
βΒ Β βΒ Β βββ deleteEntity.js
βΒ Β βΒ Β βββ deleteEntity.test.js
βΒ Β βΒ Β βββ getEntity.js
βΒ Β βΒ Β βββ getEntity.test.js
βΒ Β βΒ Β βββ updateEntity.js
βΒ Β βΒ Β βββ updateEntity.test.js
βΒ Β βββ infra
βΒ Β βββ api
βΒ Β βΒ Β βββ graphql
βΒ Β βΒ Β βΒ Β βββ custom
βΒ Β βΒ Β βΒ Β βββ defaultResolver.js
βΒ Β βΒ Β βΒ Β βββ defaultResolver.test.js
βΒ Β βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βΒ Β βββ mutations.js
βΒ Β βΒ Β βΒ Β βββ queries.js
βΒ Β βΒ Β βΒ Β βββ types.js
βΒ Β βΒ Β βββ server.js
βΒ Β βββ config
βΒ Β βΒ Β βββ config.js
βΒ Β βββ db
βΒ Β βΒ Β βββ migrations
βΒ Β βΒ Β βββ 20210101000000_entity.js
βΒ Β βββ repl
βΒ Β βΒ Β βββ index.js
βΒ Β βββ repositories
βΒ Β βββ memDB
βΒ Β βΒ Β βββ inMemDB.js
βΒ Β βΒ Β βββ EntityRepository.js
βΒ Β βΒ Β βββ EntityRepository.test.js
βΒ Β βββ pg
βΒ Β βββ connection.js
βΒ Β βββ EntityRepository.js
note we have an herbs.json
, this json will be an control file to help the cli when it add new modules in the project.
Propose 2
my second propose is to build an modular project, so the first thing you need is to create your entities int the root project path:
βββ user.js
βββ item.js
so when we start our project we can generate all project using the entities
Herbs new app -βgraphql β-knex
This will create an app with graphql that use knex into repository, the generated files will be something like this:
βΒ Β βββ herbs.json
βΒ Β βββ index.js
βΒ Β βββ knexfile.js
βΒ Β βββ package.json
βΒ Β βββ src
βΒ Β βββ domain
βΒ Β βΒ Β βββ entities
βΒ Β βΒ Β βΒ Β βββ user.js
βΒ Β βΒ Β βΒ Β βββ user.test.js
βΒ Β βΒ Β βββ usecases
βΒ Β βΒ Β βββ createUser.js
βΒ Β βΒ Β βββ createUser.test.js
βΒ Β βΒ Β βββ deleteUser.js
βΒ Β βΒ Β βββ deleteUser.test.js
βΒ Β βΒ Β βββ getUser.js
βΒ Β βΒ Β βββ getUser.test.js
βΒ Β βΒ Β βββ updateUser.js
βΒ Β βΒ Β βββ updateUser.test.js
βΒ Β βΒ Β βββ createItem.js
βΒ Β βΒ Β βββ createItem.test.js
βΒ Β βΒ Β βββ deleteItem.js
βΒ Β βΒ Β βββ deleteItem.test.js
βΒ Β βΒ Β βββ getItem.js
βΒ Β βΒ Β βββ getItem.test.js
βΒ Β βΒ Β βββ updateItem.js
βΒ Β βΒ Β βββ updateItem.test.js
βΒ Β βββ infra
βΒ Β βββ api
βΒ Β βΒ Β βββ graphql
βΒ Β βΒ Β βΒ Β βββ custom
βΒ Β βΒ Β βΒ Β βββ UserResolver.js
βΒ Β βΒ Β βΒ Β βββ UserResolver.test.js
βΒ Β βΒ Β βΒ Β βββ ItemResolver.js
βΒ Β βΒ Β βΒ Β βββ ItemResolver.test.js
βΒ Β βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βΒ Β βββ mutations.js
βΒ Β βΒ Β βΒ Β βββ queries.js
βΒ Β βΒ Β βΒ Β βββ types.js
βΒ Β βΒ Β βββ server.js
βΒ Β βββ config
βΒ Β βΒ Β βββ config.js
βΒ Β βββ db
βΒ Β βΒ Β βββ migrations
βΒ Β βΒ Β βββ 20210101000000_User.js
βΒ Β βΒ Β βββ 20210101000000_item.js
βΒ Β βββ repl
βΒ Β βΒ Β βββ index.js
βΒ Β βββ repositories
βΒ Β βββ memDB
βΒ Β βΒ Β βββ inMemDB.js
βΒ Β βΒ Β βββ UserRepository.js
βΒ Β βΒ Β βββ UserRepository.test.js
βΒ Β βββ pg
βΒ Β βββ connection.js
βΒ Β βββ UserRepository.js
βΒ Β βββ UserRepository.test.js
βΒ Β βΒ Β βββ ItemRepository.js
βΒ Β βΒ Β βββ ItemRepository.test.js
note we have an herbs.json
, this json will be an control file to help the cli when it add new modules in the project.
Propose 3
Makes the propose-1 so grow the CLI to propose-2
Herbs Modules
After create your app, you can write an new entity in the project and generate a new crud for this entity, example:
herbs new entity ShoppingCart
(or you can specify the entity path with --path)
So we will in the entities path `src/entities/item.js, read the file and generate a CRUD usecase (create, delete, list, update), generate the repository and add this entity into graphql layer.
βΒ Β βββ herbs.json
βΒ Β βββ index.js
βΒ Β βββ knexfile.js
βΒ Β βββ package.json
βΒ Β βββ src
βΒ Β βββ domain
βΒ Β βΒ Β βββ entities
βΒ Β βΒ Β βΒ Β βββ user.js
βΒ Β βΒ Β βΒ Β βββ user.test.js
βΒ Β βΒ Β βββ usecases
βΒ Β βΒ Β βββ createUser.js
[...]
βΒ Β βΒ Β βββ createItem.js
βΒ Β βΒ Β [...]
βββ createShoppingCart.test.js
βΒ Β βΒ Β βββ deleteShoppingCart.js
βΒ Β βΒ Β βββ deleteShoppingCart.test.js
βΒ Β βΒ Β βββ getShoppingCart.js
βΒ Β βΒ Β βββ getShoppingCart.test.js
βΒ Β βΒ Β βββ updateShoppingCart.js
βΒ Β βΒ Β βββ updateShoppingCart.test.js
βΒ Β βββ infra
βΒ Β βββ api
βΒ Β βΒ Β βββ graphql
βΒ Β βΒ Β βΒ Β βββ custom
[...]
βΒ Β βΒ Β βΒ Β βββ ShoppingCart.js
βΒ Β βΒ Β βΒ Β βββ ShoppingCart.test.js
βΒ Β βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βΒ Β βββ mutations.js
βΒ Β βΒ Β βΒ Β βββ queries.js
βΒ Β βΒ Β βΒ Β βββ types.js
βΒ Β βΒ Β βββ server.js
βΒ Β βββ config
βΒ Β βΒ Β βββ config.js
βΒ Β βββ db
βΒ Β βΒ Β βββ migrations
[...]
βΒ Β βΒ Β βββ 20210101000000_ShoppingCart.js
βΒ Β βββ repl
βΒ Β βΒ Β βββ index.js
βΒ Β βββ repositories
βΒ Β memDB
βΒ Β Β Β βββ inMemDB.js
[...]
βΒ Β Β Β βββ 20210101000000_ShoppingCart.js
βΒ Β pg
βΒ Β βββ connection.js
βΒ Β βββ UserRepository.js
βΒ Β βββ UserRepository.test.js
βΒ Β Β Β βββ ItemRepository.js
βΒ Β Β Β βββ ShoppingCartRepository.test.js
βΒ Β Β Β βββ ShoppingCartRepository.test.js
other example is to create new presentation layer
herbjs new module --rest
so we add the herbs2rest into package.json and generate the rest layer
I believe we can have the commands:
beta stage
herbs new app < --graphql --rest --knex --mongo >
release 1.0
herbs add layer < --graphql --rest --knex --mongo >
herbs add entity <name or --path>