import { Rule, SchematicContext, Tree, chain, schematic } from '@angular-devkit/schematics'; import { BackendSchematics } from './backend-schematics'; import { ClassRelationEnum, Model, ModelRelation } from '@vmfvmf/ywtc-lib'; import { setModel } from '../../router.gen'; import { UcType } from '@vmfvmf/ywtc-lib/dist/model.enums'; export function gen(model: Model): Rule { return (tree: Tree, _context: SchematicContext) => { setModel(model); const schematics: Rule[] = [ schematic(BackendSchematics.ENTITY, model), schematic(BackendSchematics.DTO, model), schematic(BackendSchematics.CONTROLLER, model), schematic(BackendSchematics.REPOSITORY, model), schematic(BackendSchematics.SERVICE, model), schematic(BackendSchematics.MAPPER, model), schematic(BackendSchematics.CREATE_TABLE, model) ]; model.relations .filter((rel: ModelRelation) => rel.relation == ClassRelationEnum.ManyToMany) .forEach((rel: ModelRelation) => { schematics.push(schematic(BackendSchematics.CREATE_TABLE_MM, rel)); }); if ([UcType.STD, UcType.STDUBD].includes(model.ucType)) { schematics.push( schematic(BackendSchematics.INSERT_MENU, model), schematic(BackendSchematics.UNIT_TEST, model), ); } schematics.push( schematic(BackendSchematics.UPDATE_BACKEND_NEW_URLS, model), schematic(BackendSchematics.UPDATE_CREATE_RELATIONS_FKS_SQL, model), schematic(BackendSchematics.UPDATE_SWAGGER_CONFIG, model), schematic(BackendSchematics.UPDATE_INSERT_ALL_MENU, model), schematic(BackendSchematics.UPDATE_CALL_ALL_SCRIPTS_SQL, model) ); return chain(schematics)(tree, _context); }; }