@@ -37,23 +37,26 @@ export default class ExportCustomRoles extends BaseClass {
3737 this . customRolesConfig . dirName ,
3838 ) ;
3939 log . debug ( `Custom roles folder path is: ${ this . rolesFolderPath } ` , this . exportConfig . context ) ;
40-
40+
4141 await fsUtil . makeDirectory ( this . rolesFolderPath ) ;
4242 log . debug ( 'Custom roles directory created.' , this . exportConfig . context ) ;
43-
43+
4444 this . customRolesLocalesFilepath = pResolve ( this . rolesFolderPath , this . customRolesConfig . customRolesLocalesFileName ) ;
4545 log . debug ( `Custom roles locales file path is: ${ this . customRolesLocalesFilepath } ` , this . exportConfig . context ) ;
46-
46+
4747 await this . getCustomRoles ( ) ;
4848 await this . getLocales ( ) ;
4949 await this . getCustomRolesLocales ( ) ;
50-
51- log . debug ( `Custom roles export completed. Total custom roles: ${ Object . keys ( this . customRoles ) . length } ` , this . exportConfig . context ) ;
50+
51+ log . debug (
52+ `Custom roles export completed. Total custom roles: ${ Object . keys ( this . customRoles ) . length } ` ,
53+ this . exportConfig . context ,
54+ ) ;
5255 }
5356
5457 async getCustomRoles ( ) : Promise < void > {
5558 log . debug ( 'Fetching all roles from the stack...' , this . exportConfig . context ) ;
56-
59+
5760 const roles = await this . stack
5861 . role ( )
5962 . fetchAll ( { include_rules : true , include_permissions : true } )
@@ -65,9 +68,12 @@ export default class ExportCustomRoles extends BaseClass {
6568 log . debug ( 'An error occurred while fetching roles.' , this . exportConfig . context ) ;
6669 return handleAndLogError ( err , { ...this . exportConfig . context } ) ;
6770 } ) ;
68-
71+
6972 const customRoles = roles . items . filter ( ( role : any ) => ! this . existingRoles [ role . name ] ) ;
70- log . debug ( `Found ${ customRoles . length } custom roles from ${ roles . items ?. length || 0 } total roles.` , this . exportConfig . context ) ;
73+ log . debug (
74+ `Found ${ customRoles . length } custom roles from ${ roles . items ?. length || 0 } total roles.` ,
75+ this . exportConfig . context ,
76+ ) ;
7177
7278 if ( ! customRoles . length ) {
7379 log . info ( messageHandler . parse ( 'ROLES_NO_CUSTOM_ROLES' ) , this . exportConfig . context ) ;
@@ -79,15 +85,15 @@ export default class ExportCustomRoles extends BaseClass {
7985 log . info ( messageHandler . parse ( 'ROLES_EXPORTING_ROLE' , role ?. name ) , this . exportConfig . context ) ;
8086 this . customRoles [ role . uid ] = role ;
8187 } ) ;
82-
88+
8389 const customRolesFilePath = pResolve ( this . rolesFolderPath , this . customRolesConfig . fileName ) ;
8490 log . debug ( `Writing custom roles to: ${ customRolesFilePath } .` , this . exportConfig . context ) ;
8591 fsUtil . writeFile ( customRolesFilePath , this . customRoles ) ;
8692 }
8793
8894 async getLocales ( ) {
8995 log . debug ( 'Fetching locales for custom roles mapping...' , this . exportConfig . context ) ;
90-
96+
9197 const locales = await this . stack
9298 . locale ( )
9399 . query ( { } )
@@ -100,25 +106,28 @@ export default class ExportCustomRoles extends BaseClass {
100106 log . debug ( 'An error occurred while fetching locales.' , this . exportConfig . context ) ;
101107 return handleAndLogError ( err , { ...this . exportConfig . context } ) ;
102108 } ) ;
103-
109+
104110 for ( const locale of locales . items ) {
105111 log . debug ( `Mapping locale: ${ locale ?. name } (${ locale ?. uid } )` , this . exportConfig . context ) ;
106112 this . sourceLocalesMap [ locale . uid ] = locale ;
107113 }
108-
114+
109115 log . debug ( `Mapped ${ Object . keys ( this . sourceLocalesMap ) . length } source locales.` , this . exportConfig . context ) ;
110116 }
111117
112118 async getCustomRolesLocales ( ) {
113119 log . debug ( 'Processing custom roles locales mapping...' , this . exportConfig . context ) ;
114-
120+
115121 for ( const role of values ( this . customRoles ) ) {
116122 const customRole = role as Record < string , any > ;
117123 log . debug ( `Processing locales for custom role: ${ customRole ?. name } ` , this . exportConfig . context ) ;
118-
124+
119125 const rulesLocales = find ( customRole . rules , ( rule : any ) => rule . module === 'locale' ) ;
120126 if ( rulesLocales ?. locales ?. length ) {
121- log . debug ( `Found ${ rulesLocales . locales . length } locales for the role: ${ customRole ?. name } .` , this . exportConfig . context ) ;
127+ log . debug (
128+ `Found ${ rulesLocales . locales . length } locales for the role: ${ customRole ?. name } .` ,
129+ this . exportConfig . context ,
130+ ) ;
122131 forEach ( rulesLocales . locales , ( locale : any ) => {
123132 log . debug ( `Adding locale ${ locale } to the custom roles mapping.` , this . exportConfig . context ) ;
124133 this . localesMap [ locale ] = 1 ;
@@ -128,7 +137,7 @@ export default class ExportCustomRoles extends BaseClass {
128137
129138 if ( keys ( this . localesMap ) ?. length ) {
130139 log . debug ( `Processing ${ Object . keys ( this . localesMap ) . length } mapped locales.` , this . exportConfig . context ) ;
131-
140+
132141 for ( const locale in this . localesMap ) {
133142 if ( this . sourceLocalesMap [ locale ] !== undefined ) {
134143 const sourceLocale = this . sourceLocalesMap [ locale ] as Record < string , any > ;
@@ -137,7 +146,7 @@ export default class ExportCustomRoles extends BaseClass {
137146 }
138147 this . localesMap [ locale ] = this . sourceLocalesMap [ locale ] ;
139148 }
140-
149+
141150 log . debug ( `Writing custom roles locales to: ${ this . customRolesLocalesFilepath } .` , this . exportConfig . context ) ;
142151 fsUtil . writeFile ( this . customRolesLocalesFilepath , this . localesMap ) ;
143152 } else {
0 commit comments