@@ -25,12 +25,40 @@ const readHead = (file) => {
2525 }
2626}
2727
28+ const getMissingTokens = ( base , head ) => {
29+ const missingTokens = [ ] ;
30+
31+ const isLeaf = ( obj ) =>
32+ Object . keys ( obj ) . length === 2 && ! ! obj . value && ! ! obj . type ;
33+ const crawlObject = ( base , head , path ) => {
34+ const keys = Object . keys ( base ) ;
35+ for ( let i = 0 ; i < keys . length ; i ++ ) {
36+ const key = keys [ i ] ;
37+ if ( ! isLeaf ( base ) && ! ! head [ key ] ) {
38+ crawlObject ( base [ key ] , head [ key ] , `${ path ? path + "." : "" } ${ key } ` ) ;
39+ }
40+ if ( ! isLeaf ( base ) && ! head [ key ] ) {
41+ missingTokens . push ( `${ path ? path + "." : "" } ${ key } ` ) ;
42+ }
43+ }
44+ } ;
45+
46+ crawlObject ( base , head , "" ) ;
47+ return missingTokens ;
48+ } ;
49+
2850console . log ( `${ files . length } token file(s) changed:` )
2951for ( const file of files ) {
3052 const base = readBase ( file )
3153 const head = readHead ( file )
3254 const status = base === null ? 'added' : head === null ? 'deleted' : 'modified'
3355 console . log ( ` ${ file } (${ status } ) base=${ base ?. length ?? 0 } b head=${ head ?. length ?? 0 } b` )
56+
57+ if ( status === "modified" ) {
58+ const missingTokens = getMissingTokens ( JSON . parse ( base ) , JSON . parse ( head ) ) ;
59+ console . log ( "missing token(s)" ) ;
60+ missingTokens . forEach ( ( token ) => console . log ( token ) ) ;
61+ }
3462}
3563
3664// Real checks go here. Exit non-zero to fail the PR.
0 commit comments