@@ -75,14 +75,73 @@ export const saveFile = async ({
7575 return response ;
7676} ;
7777
78- export const manifestFileComparer = async ( {
78+ const REGEX_TSV_BOOK_ABBREVIATION = / ^ \w * _ ( \w * ) \. t s v $ / i;
79+
80+ export const manifestFileComparer = ( {
7981 repository, item1, item2,
8082} ) => {
81- alert ( JSON . stringify ( repository ) ) ;
83+ let compare = 0 ;
84+
85+ if ( item1 && item2 && repository && repository . books )
86+ {
87+ const book1Matches = item1 . match ( REGEX_TSV_BOOK_ABBREVIATION ) ;
88+ const book2Matches = item2 . match ( REGEX_TSV_BOOK_ABBREVIATION ) ;
8289
83- return 0 ;
90+ const isTsvFiles = ( book1Matches && book2Matches ) ?true :false ;
91+ if ( isTsvFiles )
92+ {
93+ const book1 = book1Matches [ 1 ] ;
94+ const book2 = book2Matches [ 1 ] ;
95+
96+ let iiBook1 = 0 ;
97+ let iiBook2 = 0 ;
98+ for ( let ii = 0 ; ii < repository . books . length ; ii ++ )
99+ {
100+ if ( repository . books [ ii ] . toLowerCase ( ) == book1 . toLowerCase ( ) )
101+ {
102+ iiBook1 = ii ;
103+ }
104+ if ( repository . books [ ii ] . toLowerCase ( ) == book2 . toLowerCase ( ) )
105+ {
106+ iiBook2 = ii ;
107+ }
108+ }
109+
110+ if ( iiBook1 < iiBook2 )
111+ {
112+ compare = - 1 ;
113+ }
114+ else if ( iiBook2 < iiBook1 )
115+ {
116+ compare = 1 ;
117+ }
118+ else
119+ {
120+ compare = 0 ;
121+ }
122+ }
123+ else // BOTH are NOT TSV file: (could be manifest file).
124+ {
125+ if ( book1Matches )
126+ {
127+ // Book1 is a TSV, but book2 is a non-TSV file.
128+ return 1 ;
129+ }
130+ else if ( book2Matches )
131+ {
132+ // Book2 is the TSV file; but book1 is NOT.
133+ return - 1 ;
134+ }
135+ else
136+ {
137+ compare = item1 . localeCompare ( item2 ) ;
138+ }
139+ }
140+ }
141+ else // item1/item2 don't exist:
142+ {
143+ compare = 0 ;
144+ }
84145
85- // contentObject = await readContent({
86- // owner, repo, ref: branch, filepath, config,
87- // });
146+ return compare ;
88147} ;
0 commit comments