Skip to content

Commit ff389c5

Browse files
committed
feat(generators/with-postgres-typeorm): add pluralize module, pluralize model name
1 parent fe87de7 commit ff389c5

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

generators/with-postgres-typeorm/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@ module.exports = class extends Generator {
2222
return this.prompt(prompts).then((props) => {
2323
const compNameParamCase = changeCase.paramCase(props.compName);
2424
const compNamePascalCase = changeCase.pascalCase(props.compName);
25+
const compNameCamelCase = changeCase.camelCase(props.compName);
2526

2627
this.props = {
27-
...props,
28+
// param-case
2829
compNameParamCase,
29-
compNamePascalCase,
30+
// param-cases
3031
compNameParamCasePlural: pluralize(compNameParamCase),
32+
// PascalCase
33+
compNamePascalCase,
34+
// PasCalCases
35+
compNamePascalCasePlural: pluralize(compNamePascalCase),
36+
// camelCase
37+
compNameCamelCase,
38+
// camelCases
39+
compNameCamelCasePlural: pluralize(compNameCamelCase),
3140
};
3241
});
3342
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import pluralize from 'pluralize';
2+
13
const ENTITY = '<%= compNameParamCase %>';
2-
const RESOURCE = '<%= compNameParamCasePlural %>';
4+
const RESOURCE = pluralize(ENTITY);
35

46
export { ENTITY, RESOURCE };

generators/with-postgres-typeorm/templates/<%= compNameParamCasePlural %>/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
2+
import pluralize from 'pluralize';
23

34
import { <%= compNamePascalCase %> } from './types';
45
import { ENTITY } from './constants';
56

6-
@Entity(ENTITY)
7+
@Entity(pluralize(ENTITY))
78
class Model implements <%= compNamePascalCase %> {
89
@PrimaryGeneratedColumn()
910
id!: number;

generators/with-postgres-typeorm/templates/<%= compNameParamCasePlural %>/repository.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ const get = async (id: number): Promise<<%= compNamePascalCase %>> => {
2525
return document;
2626
};
2727

28-
const update = async (
29-
id: number,
30-
data: Omit<<%= compNamePascalCase %>, 'id'>,
31-
): Promise<<%= compNamePascalCase %>> => {
28+
const update = async (id: number, data: Omit<<%= compNamePascalCase %>, 'id'>): Promise<<%= compNamePascalCase %>> => {
3229
// get document
3330
const document = await getRepository(Model).findOne(id);
3431
if (document === undefined) {

0 commit comments

Comments
 (0)