Angular Schematics

Scaffolding library for Angular applications using Akita.

Schematics provides CLI commands for generating files when building new features with Akita. Built on top of Schematics, this tool integrates with the Angular CLI.

ng add @datorama/akita

Default Schematics Collection

To use @datorama/akita as the default collection in your Angular CLI project, add it to your angular.json:

ng config cli.defaultCollection @datorama/akita

The package extend the default @schematics/angular collection. If you want to set defaults for schematics such as generating components with scss file, you must change the schematics package name from @schematics/angular to @datorama/akita in angular.json:

angular.json
"schematics": {
"@datorama/akita:component": {
"styleext": "scss"
}
}

Create a New Feature

ng g @datorama/akita:feature todos/todos

The defauls feature will output an entity feature, you can choose between different kind of EntityService:

You can also generate the normal feature with the plain option:

ng g @datorama/akita:feature auth/auth --plain
options:
--withActive="Active" / "MultiActive" // decides which interface the store will implement, ActiveState or MultiActiveState
tip

The akita-schematics: prefix is only needed when the default collection isn't set to akita-schematics

Generate a Store

ng g @datorama/akita:as todos
ng g @datorama/akita:aes todos // entity store
options:
--withActive="Active" / "MultiActive" // decides which interface the store will implement, ActiveState or MultiActiveState

Generate a Query

ng g @datorama/akita:query todos
ng g @datorama/akita:entity-query todos
Alias:
ng g @datorama/akita:aq todos
ng g @datorama/akita:aeq todos // entity query

Generate a Model

ng g @datorama/akita:model todo
Alias:
ng g @datorama/akita:am todo

Generate a Service

ng g @datorama/akita:service todos
Alias:
ng g @datorama/akita:asr todos

Generate an NgEntityService

ng g @datorama/akita:http-entity-service todos
Alias:
ng g @datorama/akita:ahes todos

Generate Tests

Add the --spec option. For example:

ng g af products/products --spec

Generate Module

Add the --withModule to generate module and Akita component. (only for entity store)

Generate several stores under the same state folder

There might be a case when you need to have more than one store per feature. For example, you have a module "CRM", where you have a few entities, like addresses or contacts. So you want to have one single state folder under "CRM" and under that, for every store, a subfolder. Like this:

CRM
โ””โ”€โ”€ state
โ”œโ”€โ”€ address
โ”‚ โ”œโ”€โ”€ address.model.ts
โ”‚ โ”œโ”€โ”€ address.query.ts
โ”‚ โ”œโ”€โ”€ address.service.ts
โ”‚ โ””โ”€โ”€ address.store.ts
โ””โ”€โ”€ contacts
โ”œโ”€โ”€ contact.model.ts
โ”œโ”€โ”€ contacts.query.ts
โ”œโ”€โ”€ contacts.service.ts
โ””โ”€โ”€ contacts.store.ts

To do so, add the --flat false to your commands:

ng g af CRM/address --flat false
ng g af CRM/contacts --flat false