-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Allow new entity features to be selected
- Loading branch information
1 parent
e18784f
commit 74c69dd
Showing
7 changed files
with
185 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 5 additions & 26 deletions
31
packages/cli/src/commands/add/entity/codemods/add-entity-to-plugin/add-entity-to-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/cli/src/commands/add/entity/templates/entity-translation.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { LanguageCode } from '@vendure/common/lib/generated-types'; | ||
import { DeepPartial } from '@vendure/common/lib/shared-types'; | ||
import { HasCustomFields, Translation, VendureEntity } from '@vendure/core'; | ||
import { Column, Entity, Index, ManyToOne } from 'typeorm'; | ||
|
||
import { ScaffoldEntity } from './entity.template'; | ||
|
||
export class ScaffoldEntityCustomFieldsTranslation {} | ||
|
||
@Entity() | ||
export class ScaffoldTranslation | ||
extends VendureEntity | ||
implements Translation<ScaffoldEntity>, HasCustomFields | ||
{ | ||
constructor(input?: DeepPartial<Translation<ScaffoldTranslation>>) { | ||
super(input); | ||
} | ||
|
||
@Column('varchar') languageCode: LanguageCode; | ||
|
||
@Column() localizedName: string; | ||
|
||
@Index() | ||
@ManyToOne(type => ScaffoldEntity, base => base.translations, { onDelete: 'CASCADE' }) | ||
base: ScaffoldEntity; | ||
|
||
@Column(type => ScaffoldEntityCustomFieldsTranslation) | ||
customFields: ScaffoldEntityCustomFieldsTranslation; | ||
} |
22 changes: 18 additions & 4 deletions
22
packages/cli/src/commands/add/entity/templates/entity.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
import { VendureEntity, DeepPartial, HasCustomFields } from '@vendure/core'; | ||
import { Entity, Column } from 'typeorm'; | ||
import { | ||
DeepPartial, | ||
HasCustomFields, | ||
LocaleString, | ||
Translatable, | ||
Translation, | ||
VendureEntity, | ||
} from '@vendure/core'; | ||
import { Column, Entity, OneToMany } from 'typeorm'; | ||
|
||
import { ScaffoldTranslation } from './entity-translation.template'; | ||
|
||
export class ScaffoldEntityCustomFields {} | ||
|
||
@Entity() | ||
export class ScaffoldEntity extends VendureEntity implements HasCustomFields { | ||
export class ScaffoldEntity extends VendureEntity implements Translatable, HasCustomFields { | ||
constructor(input?: DeepPartial<ScaffoldEntity>) { | ||
super(input); | ||
} | ||
|
||
@Column() | ||
name: string; | ||
code: string; | ||
|
||
@Column(type => ScaffoldEntityCustomFields) | ||
customFields: ScaffoldEntityCustomFields; | ||
|
||
localizedName: LocaleString; | ||
|
||
@OneToMany(type => ScaffoldTranslation, translation => translation.base, { eager: true }) | ||
translations: Array<Translation<ScaffoldEntity>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters