@@ -48,6 +48,7 @@ if (!fs.existsSync(path.join(cwd, '.git'))) {
4848
4949try {
5050 generate ( DataDirectory ) ;
51+ const aggregatedTokens = { }
5152 for ( const chain in perChain ) {
5253 //load the existing list
5354 const previousLists = fs . existsSync ( path . join ( DataDirectory , chain , IndexName ) )
6768 version : previousLists . version ,
6869 tokens : perChain [ chain ]
6970 } ;
71+ aggregatedTokens [ Number ( chain ) ] = perChain [ chain ] ;
7072 //compare the new list with the old one
7173 if ( JSON . stringify ( previousLists . tokens ) === JSON . stringify ( newList . tokens ) ) {
7274 console . log ( `No changes detected for chain ${ chain } ` ) ;
8991
9092 fs . writeFileSync ( path . join ( DataDirectory , chain , IndexName ) , JSON . stringify ( newList , null , 4 ) ) ;
9193 }
94+
95+ const previousAggrLists = fs . existsSync ( path . join ( DataDirectory , IndexName ) )
96+ ? JSON . parse ( fs . readFileSync ( path . join ( DataDirectory , IndexName ) ) )
97+ : { } ;
98+ if ( ! previousAggrLists . version ) {
99+ previousAggrLists . version = {
100+ major : 0 ,
101+ minor : 0 ,
102+ patch : 0
103+ } ;
104+ }
105+ if ( ! previousAggrLists . tokens ) {
106+ previousAggrLists . tokens = [ ] ;
107+ }
108+ const newList = {
109+ version : previousAggrLists . version ,
110+ tokens : aggregatedTokens
111+ } ;
112+
113+ //compare the new list with the old one
114+ if ( JSON . stringify ( previousAggrLists . tokens ) === JSON . stringify ( newList . tokens ) ) {
115+ console . log ( `No changes detected for general list` ) ;
116+ } else if ( previousAggrLists . tokens . length > newList . tokens . length ) {
117+ // At least one token was removed
118+ newList . version . major = previousAggrLists . version . major + 1 ;
119+ newList . version . minor = 0 ;
120+ newList . version . patch = 0 ;
121+ } else if ( previousAggrLists . tokens . length < newList . tokens . length ) {
122+ // At least one token was added
123+ newList . version . major = previousAggrLists . version . major ;
124+ newList . version . minor = previousAggrLists . version . minor + 1 ;
125+ newList . version . patch = 0 ;
126+ } else {
127+ // The list has the same length, but at least one token was changed. This should never happen somehown
128+ newList . version . major = previousAggrLists . version . major ;
129+ newList . version . minor = previousAggrLists . version . minor ;
130+ newList . version . patch = previousAggrLists . version . patch + 1 ;
131+ }
132+
133+
134+ fs . writeFileSync ( path . join ( DataDirectory , IndexName ) , JSON . stringify ( newList , null , 4 ) ) ;
92135} catch ( error ) {
93136 console . error ( error ) ;
94137 process . exit ( 1 ) ;
0 commit comments