@@ -15,11 +15,25 @@ export class IdentitiesJsonformsService extends AbstractService {
1515 //this.validateSchema = this.ajv.compile(validSchema);
1616 }
1717
18- async generate ( schema : string ) : Promise < any > {
18+ private resolveJsonFormPath ( schema : string ) : string | null {
19+ if ( ! schema . endsWith ( '.yml' ) ) schema += '.yml' ;
20+ const hardConfigPath = `./src/management/identities/jsonforms/_config/${ schema } ` ;
21+ const dynamicConfigPath = `./configs/identities/jsonforms/${ schema } ` ;
22+ if ( existsSync ( dynamicConfigPath ) ) {
23+ return dynamicConfigPath ;
24+ }
25+ if ( existsSync ( hardConfigPath ) ) {
26+ return hardConfigPath ;
27+ }
28+ return null ;
29+ }
30+
31+ async generate ( { schema, path } ) : Promise < any > {
1932 if ( schema ) {
2033 console . log ( `Generating jsonforms for schema: ${ schema } ` ) ;
21- const filePath = `./src/management/identities/validations/_config/${ schema } .yml` ;
22-
34+ if ( ! schema . endsWith ( '.yml' ) ) schema += '.yml' ;
35+ const filePath = `${ path } /${ schema } ` ;
36+ console . log ( `File path: ${ filePath } ` ) ;
2337 if ( ! existsSync ( filePath ) ) {
2438 console . log ( `File not found: ${ filePath } ` ) ;
2539 const message = `File not found: ${ filePath } ` ;
@@ -71,45 +85,56 @@ export class IdentitiesJsonformsService extends AbstractService {
7185 } , [ ] )
7286 . map ( ( group ) => group ) , // Flatten the structure
7387 } ;
74-
75- writeFileSync ( `./src/management/identities/jsonforms/_config/${ schema } .ui.yml` , stringify ( jsonForm ) ) ;
88+ if ( ! schema . endsWith ( '.ui.yml' ) ) schema = schema . replace ( '.yml' , '.ui.yml' ) ;
89+ const jsonFormPath = `${ path . replace ( 'validations' , 'jsonforms' ) } /${ schema } ` ;
90+ console . log ( `Writing jsonform to: ${ jsonFormPath } ` ) ;
91+ writeFileSync ( `${ jsonFormPath } ` , stringify ( jsonForm ) ) ;
7692 return jsonForm ;
7793 }
7894 }
7995
8096 async generateAll ( ) : Promise < any > {
81- const configPath = './src/management/identities/validations/_config' ;
82- const files = readdirSync ( configPath ) ;
97+ const hardConfigPath = './src/management/identities/validations/_config' ;
98+ const dynamicConfigPath = './configs/identities/validations' ;
99+ const hardConfigFiles = readdirSync ( hardConfigPath ) . map ( ( file ) => ( { schema : file , path : hardConfigPath } ) ) ;
100+ const dynamicConfigFiles = readdirSync ( dynamicConfigPath ) . map ( ( file ) => ( {
101+ schema : file ,
102+ path : dynamicConfigPath ,
103+ } ) ) ;
104+
105+ console . log ( 'Generating jsonforms for all schemas' ) ;
106+ console . log ( 'Hard config files:' , hardConfigFiles ) ;
107+ console . log ( 'Dynamic config files:' , dynamicConfigFiles ) ;
108+ const files = [ ...hardConfigFiles , ...dynamicConfigFiles ] . filter ( ( file ) => file . schema . endsWith ( '.yml' ) ) ;
83109 for ( const file of files ) {
84110 this . generate ( file ) ;
85111 }
86112 return files . length ;
87113 }
88114
89115 async findAll ( ) : Promise < any > {
90- // eslint-disable-next-line prefer-rest-params
91- this . logger . debug ( [ 'findAll' , JSON . stringify ( Object . values ( arguments ) ) ] . join ( ' ' ) ) ;
92- const configPath = './src/management/identities/jsonforms/_config' ;
93- const files = readdirSync ( configPath ) ;
116+ const hardConfigPath = './src/management/identities/jsonforms/_config' ;
117+ const dynamicConfigPath = './configs/identities/jsonforms' ;
118+ const hardConfigFiles = readdirSync ( hardConfigPath ) . map ( ( file ) => ( { file, path : hardConfigPath } ) ) ;
119+ const dynamicConfigFiles = readdirSync ( dynamicConfigPath ) . map ( ( file ) => ( { file, path : dynamicConfigPath } ) ) ;
120+
121+ const files = [ ...hardConfigFiles , ...dynamicConfigFiles ] ;
94122 const result = [ ] ;
95- for ( const file of files ) {
96- const filePath = `${ configPath } /${ file } ` ;
123+ for ( const fileObj of files ) {
124+ const filePath = `${ fileObj . path } /${ fileObj . file } ` ;
97125 const data = parse ( readFileSync ( filePath , 'utf-8' ) ) ;
98- const key = file . replace ( '.ui.yml' , '' ) ;
126+ const key = fileObj . file . replace ( '.ui.yml' , '' ) ;
99127 result . push ( { [ key ] : data } ) ;
100128 }
101129 return [ result , files . length ] ;
102130 }
103131
104132 async findOne ( schema ) : Promise < any > {
105- // eslint-disable-next-line prefer-rest-params
106- this . logger . debug ( [ 'findOne' , JSON . stringify ( Object . values ( arguments ) ) ] . join ( ' ' ) ) ;
107- const filePath = `./src/management/identities/jsonforms/_config/${ schema } .ui.yml` ;
108- if ( ! existsSync ( filePath ) ) {
109- const message = `File not found: ${ filePath } ` ;
110- throw new ValidationConfigException ( { message } ) ;
133+ if ( schema . endsWith ( '.yml' ) ) schema = schema . replace ( '.yml' , '' ) ;
134+ const filePath = this . resolveJsonFormPath ( schema + '.ui' ) ;
135+ if ( ! filePath ) {
136+ throw new ValidationConfigException ( { message : `File not found: ${ schema } .ui.yml` } ) ;
111137 }
112-
113138 return parse ( readFileSync ( filePath , 'utf-8' ) ) ;
114139 }
115140}
0 commit comments