@@ -37,26 +37,23 @@ 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 (
52- `Custom roles export completed. Total custom roles: ${ Object . keys ( this . customRoles ) . length } ` ,
53- this . exportConfig . context ,
54- ) ;
50+
51+ log . debug ( `Custom roles export completed. Total custom roles: ${ Object . keys ( this . customRoles ) . length } ` , this . exportConfig . context ) ;
5552 }
5653
5754 async getCustomRoles ( ) : Promise < void > {
5855 log . debug ( 'Fetching all roles from the stack...' , this . exportConfig . context ) ;
59-
56+
6057 const roles = await this . stack
6158 . role ( )
6259 . fetchAll ( { include_rules : true , include_permissions : true } )
@@ -68,12 +65,9 @@ export default class ExportCustomRoles extends BaseClass {
6865 log . debug ( 'An error occurred while fetching roles.' , this . exportConfig . context ) ;
6966 return handleAndLogError ( err , { ...this . exportConfig . context } ) ;
7067 } ) ;
71-
68+
7269 const customRoles = roles . items . filter ( ( role : any ) => ! this . existingRoles [ role . name ] ) ;
73- log . debug (
74- `Found ${ customRoles . length } custom roles from ${ roles . items ?. length || 0 } total roles.` ,
75- this . exportConfig . context ,
76- ) ;
70+ log . debug ( `Found ${ customRoles . length } custom roles from ${ roles . items ?. length || 0 } total roles.` , this . exportConfig . context ) ;
7771
7872 if ( ! customRoles . length ) {
7973 log . info ( messageHandler . parse ( 'ROLES_NO_CUSTOM_ROLES' ) , this . exportConfig . context ) ;
@@ -85,15 +79,15 @@ export default class ExportCustomRoles extends BaseClass {
8579 log . info ( messageHandler . parse ( 'ROLES_EXPORTING_ROLE' , role ?. name ) , this . exportConfig . context ) ;
8680 this . customRoles [ role . uid ] = role ;
8781 } ) ;
88-
82+
8983 const customRolesFilePath = pResolve ( this . rolesFolderPath , this . customRolesConfig . fileName ) ;
9084 log . debug ( `Writing custom roles to: ${ customRolesFilePath } .` , this . exportConfig . context ) ;
9185 fsUtil . writeFile ( customRolesFilePath , this . customRoles ) ;
9286 }
9387
9488 async getLocales ( ) {
9589 log . debug ( 'Fetching locales for custom roles mapping...' , this . exportConfig . context ) ;
96-
90+
9791 const locales = await this . stack
9892 . locale ( )
9993 . query ( { } )
@@ -106,28 +100,25 @@ export default class ExportCustomRoles extends BaseClass {
106100 log . debug ( 'An error occurred while fetching locales.' , this . exportConfig . context ) ;
107101 return handleAndLogError ( err , { ...this . exportConfig . context } ) ;
108102 } ) ;
109-
103+
110104 for ( const locale of locales . items ) {
111105 log . debug ( `Mapping locale: ${ locale ?. name } (${ locale ?. uid } )` , this . exportConfig . context ) ;
112106 this . sourceLocalesMap [ locale . uid ] = locale ;
113107 }
114-
108+
115109 log . debug ( `Mapped ${ Object . keys ( this . sourceLocalesMap ) . length } source locales.` , this . exportConfig . context ) ;
116110 }
117111
118112 async getCustomRolesLocales ( ) {
119113 log . debug ( 'Processing custom roles locales mapping...' , this . exportConfig . context ) ;
120-
114+
121115 for ( const role of values ( this . customRoles ) ) {
122116 const customRole = role as Record < string , any > ;
123117 log . debug ( `Processing locales for custom role: ${ customRole ?. name } ` , this . exportConfig . context ) ;
124-
118+
125119 const rulesLocales = find ( customRole . rules , ( rule : any ) => rule . module === 'locale' ) ;
126120 if ( rulesLocales ?. locales ?. length ) {
127- log . debug (
128- `Found ${ rulesLocales . locales . length } locales for the role: ${ customRole ?. name } .` ,
129- this . exportConfig . context ,
130- ) ;
121+ log . debug ( `Found ${ rulesLocales . locales . length } locales for the role: ${ customRole ?. name } .` , this . exportConfig . context ) ;
131122 forEach ( rulesLocales . locales , ( locale : any ) => {
132123 log . debug ( `Adding locale ${ locale } to the custom roles mapping.` , this . exportConfig . context ) ;
133124 this . localesMap [ locale ] = 1 ;
@@ -137,7 +128,7 @@ export default class ExportCustomRoles extends BaseClass {
137128
138129 if ( keys ( this . localesMap ) ?. length ) {
139130 log . debug ( `Processing ${ Object . keys ( this . localesMap ) . length } mapped locales.` , this . exportConfig . context ) ;
140-
131+
141132 for ( const locale in this . localesMap ) {
142133 if ( this . sourceLocalesMap [ locale ] !== undefined ) {
143134 const sourceLocale = this . sourceLocalesMap [ locale ] as Record < string , any > ;
@@ -146,7 +137,7 @@ export default class ExportCustomRoles extends BaseClass {
146137 }
147138 this . localesMap [ locale ] = this . sourceLocalesMap [ locale ] ;
148139 }
149-
140+
150141 log . debug ( `Writing custom roles locales to: ${ this . customRolesLocalesFilepath } .` , this . exportConfig . context ) ;
151142 fsUtil . writeFile ( this . customRolesLocalesFilepath , this . localesMap ) ;
152143 } else {
0 commit comments