@@ -32,7 +32,12 @@ const appriseDirs = [
3232 extension : '.ts' ,
3333 } ,
3434 {
35- directory : path . resolve ( process . cwd ( ) , 'shared' , 'validators' ) ,
35+ directory : path . resolve (
36+ process . cwd ( ) ,
37+ 'shared' ,
38+ 'validators' ,
39+ 'notifications'
40+ ) ,
3641 extension : '.js' ,
3742 } ,
3843] ;
@@ -41,7 +46,7 @@ appriseDirs.forEach(({ directory, extension }) => {
4146 if ( ! fs . existsSync ( directory ) ) {
4247 fs . mkdirSync ( directory , { recursive : true } ) ;
4348 }
44- const filePath = path . join ( directory , fileName + extension ) ;
49+ const filePath = path . join ( directory , fileName . toLowerCase ( ) + extension ) ;
4550 try {
4651 fs . writeFileSync ( filePath , '' , { flag : 'wx' } ) ;
4752 logger . info ( `File created: ${ filePath } ` ) ;
@@ -53,3 +58,42 @@ appriseDirs.forEach(({ directory, extension }) => {
5358 }
5459 }
5560} ) ;
61+
62+ const notificationJson = path . resolve (
63+ process . cwd ( ) ,
64+ 'app' ,
65+ 'constant' ,
66+ 'notifications.json'
67+ ) ;
68+
69+ const data = fs . readFileSync ( notificationJson , 'utf-8' ) ;
70+ const notifications = JSON . parse ( data ) ;
71+
72+ const notificationName =
73+ fileName . charAt ( 0 ) . toUpperCase ( ) + fileName . slice ( 1 ) . toLowerCase ( ) ;
74+
75+ if ( ! notifications [ notificationName ] ) {
76+ notifications [ notificationName ] = {
77+ id : notificationName ,
78+ name : notificationName ,
79+ icon : `${ notificationName . toLowerCase ( ) } .svg` ,
80+ } ;
81+
82+ fs . writeFileSync (
83+ notificationJson ,
84+ JSON . stringify (
85+ Object . keys ( notifications )
86+ . sort ( )
87+ . reduce ( ( obj , key ) => {
88+ obj [ key ] = notifications [ key ] ;
89+ return obj ;
90+ } , { } ) ,
91+ null ,
92+ 2
93+ ) ,
94+ 'utf-8'
95+ ) ;
96+ logger . info (
97+ `Notification entry added for ${ notificationName } in notifications.json. Please add ${ notificationName . toLowerCase ( ) } .svg`
98+ ) ;
99+ }
0 commit comments