Skip to content

Commit

Permalink
feat(plugin-core): add injectable option in generators
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Oct 5, 2021
1 parent 1a457d2 commit 54f20f0
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { <%= entity.className %>MockMapper } from './mapper/<%= entity.fileName
import { <%= entity.className %>MockDto } from './dto/<%= entity.fileName %>-mock.dto';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
<% if (injectable) { %>
import { Injectable } from '@nx-clean/core';
<% } %>

<% if (injectable) { %>
@Injectable()
<% } %>
export class <%= entity.className %>InMemoryRepository implements <%= entity.className %>Repository {
constructor(private data: <%= entity.className %>MockDto[] = []) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { <%= entity.className %>Entity } from '../entity/<%= entity.fileName %>.entity';
import { Observable } from 'rxjs';
<% if (injectable) { %>
import { Injectable } from '@nx-clean/core';
<% } %>

<% if (injectable) { %>
@Injectable()
<% } %>
export abstract class <%= entity.className %>Repository {
public abstract getAll<%= entity.className %>s(): Observable<<%= entity.className %>Entity[]>;
public abstract add<%= entity.className %>(<%= entity.propertyName %>: Pick<<%= entity.className %>Entity, 'name'>): Observable<<%= entity.className %>Entity>;
Expand Down
5 changes: 5 additions & 0 deletions libs/plugin/core/src/generators/domain/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"description": "Would you like to add a repository?",
"default": false
},
"injectable": {
"type": "boolean",
"description": "Would you like to use dependency injection?",
"default": true
},
"usecases": {
"type": "boolean",
"description": "Would you like to add a usecases?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import {
GetAll<%= entity.className %>sUseCase,
Remove<%= entity.className %>UseCase,
} from '<%= projectDomain %>';
<% if (injectable) { %>
import { Injectable } from '@nx-clean/core';
<% } %>

<% if (injectable) { %>
@Injectable()
<% } %>
export class <%= entity.className %>DefaultPresenter implements <%= entity.className %>Presenter {
<%= entity.propertyName %>s$: Observable<<%= entity.className %>VM[]>;
filter$: Observable<string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { <%= entity.className %>VM } from '../viewmodel/<%= entity.fileName %>s.viewmodel';
import { Observable } from 'rxjs';
<% if (injectable) { %>
import { Injectable } from '@nx-clean/core';
<% } %>

<% if (injectable) { %>
@Injectable()
<% } %>
export abstract class <%= entity.className %>Presenter {
abstract <%= entity.propertyName %>s$: Observable<<%= entity.className %>VM[]>;
abstract filter$: Observable<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { <%= entity.className %><%= type.className %>Mapper } from './mapper/<%=
import { <%= entity.className %><%= type.className %>Dto } from './dto/<%= entity.fileName %>-<%= type.fileName %>.dto';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
<% if (injectable) { %>
import { Injectable } from '@nx-clean/core';
<% } %>

<% if (injectable) { %>
@Injectable()
<% } %>
export class <%= entity.className %><%= type.className %>Repository implements <%= entity.className %>Repository {
constructor(private data: <%= entity.className %><%= type.className %>Dto[] = []) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { <%= entity.className %>Entity } from '../entity/<%= entity.fileName %>.entity';
import { Observable } from 'rxjs';
<% if (injectable) { %>
import { Injectable } from '@nx-clean/core';
<% } %>

<% if (injectable) { %>
@Injectable()
<% } %>
export abstract class <%= entity.className %>Repository {
public abstract getAll<%= entity.className %>s(): Observable<<%= entity.className %>Entity[]>;
public abstract add<%= entity.className %>(<%= entity.propertyName %>: Pick<<%= entity.className %>Entity, 'name'>): Observable<<%= entity.className %>Entity>;
Expand Down
5 changes: 5 additions & 0 deletions libs/plugin/core/src/generators/repository/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"$default": {
"$source": "projectName"
}
},
"injectable": {
"type": "boolean",
"description": "Would you like to use dependency injection?",
"default": true
}
},
"required": ["name", "domain"]
Expand Down
3 changes: 2 additions & 1 deletion libs/plugin/core/src/utils/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export function normalizeOptions(host: Tree, options: any): unknown {
? options.tags.split(',').map((s) => s.trim())
: [];

options.injectable = options.injectable ? options.injectable : false;
options.repository = options.repository ? options.repository : false;
options.usecases = options.usecases ? options.usecases : false;
options.inmemory = options.inmemory ? options.inmemory : false;

if (options.domain) {
const config = readProjectConfiguration(host, options.domain);
options.projectDomain = config
Expand Down

0 comments on commit 54f20f0

Please sign in to comment.