@@ -9,12 +9,15 @@ const filePaths = {
99    'src' , 
1010    'core' , 
1111    'render' , 
12-     'emojify -data.js' 
12+     'emoji -data.js' 
1313  ) , 
1414} ; 
1515
1616async  function  getEmojiData ( )  { 
1717  const  emojiDataURL  =  'https://api.github.com/emojis' ; 
18+ 
19+   console . info ( `- Fetching emoji data from ${ emojiDataURL }  ) ; 
20+ 
1821  const  response  =  await  axios . get ( emojiDataURL ) ; 
1922  const  baseURL  =  Object . values ( response . data ) 
2023    . find ( url  =>  / u n i c o d e \/ / ) 
@@ -26,16 +29,18 @@ async function getEmojiData() {
2629    ( [ key ,  value ] )  =>  ( data [ key ]  =  value . replace ( baseURL ,  '' ) ) 
2730  ) ; 
2831
32+   console . info ( `- Retrieved ${ Object . keys ( data ) . length }  ) ; 
33+ 
2934  return  { 
3035    baseURL, 
3136    data, 
3237  } ; 
3338} 
3439
3540function  writeEmojiPage ( emojiData )  { 
41+   const  isExistingPage  =  fs . existsSync ( filePaths . emojiMarkdown ) ; 
3642  const  emojiPage  = 
37-     ( fs . existsSync ( filePaths . emojiMarkdown )  && 
38-       fs . readFileSync ( filePaths . emojiMarkdown ,  'utf8' ) )  || 
43+     ( isExistingPage  &&  fs . readFileSync ( filePaths . emojiMarkdown ,  'utf8' ) )  || 
3944    `<!-- START -->\n\n<!-- END -->` ; 
4045  const  emojiRegEx  =  / ( < ! - - \s * S T A R T .* - - > \n ) ( [ \s \S ] * ) ( \n < ! - - \s * E N D .* - - > ) / ; 
4146  const  emojiMatch  =  emojiPage . match ( emojiRegEx ) ; 
@@ -53,39 +58,52 @@ function writeEmojiPage(emojiData) {
5358  if  ( emojiMarkdown  !==  newEmojiMarkdown )  { 
5459    const  newEmojiPage  =  emojiPage . replace ( 
5560      emojiMatch [ 0 ] , 
56-       `${ emojiMarkdownStart } ${ newEmojiMarkdown } ${ emojiMarkdownEnd }  
61+       `${ emojiMarkdownStart } \n ${ newEmojiMarkdown } \n \n${ emojiMarkdownEnd }  
5762    ) ; 
5863
5964    fs . writeFileSync ( filePaths . emojiMarkdown ,  newEmojiPage ) ; 
60-     console . info ( `- Created new file: ${ filePaths . emojiMarkdown }  ) ; 
65+ 
66+     console . info ( 
67+       `- ${ ! isExistingPage  ? 'Created'  : 'Updated' } ${ filePaths . emojiMarkdown }  
68+     ) ; 
6169  }  else  { 
62-     console . info ( `- No changes to file : ${ filePaths . emojiMarkdown }  ) ; 
70+     console . info ( `- No changes: ${ filePaths . emojiMarkdown }  ) ; 
6371  } 
6472} 
6573
6674function  writeEmojiJS ( emojiData )  { 
67-   const  emojiJS  = 
68-     fs . existsSync ( filePaths . emojiJS )  && 
69-     fs . readFileSync ( filePaths . emojiJS ,  'utf8' ) ; 
70-   const  newEmojiJS  =  `export default ${ JSON . stringify ( emojiData ,  { } ,  2 ) }  ; 
75+   const  isExistingPage  =  fs . existsSync ( filePaths . emojiJS ) ; 
76+   const  emojiJS  =  isExistingPage  &&  fs . readFileSync ( filePaths . emojiJS ,  'utf8' ) ; 
77+   const  newEmojiJS  =  [ 
78+     '/* eslint-disable */\n' , 
79+     '// =============================================================================' , 
80+     '// DO NOT EDIT: This file is auto-generated by an /build/emoji.js' , 
81+     '// =============================================================================\n' , 
82+     `export default ${ JSON . stringify ( emojiData ,  { } ,  2 ) }  , 
83+   ] . join ( '\n' ) ; 
7184
7285  if  ( ! emojiJS  ||  emojiJS  !==  newEmojiJS )  { 
7386    fs . writeFileSync ( filePaths . emojiJS ,  newEmojiJS ) ; 
74-     console . info ( `- Created new file: ${ filePaths . emojiJS }  ) ; 
87+ 
88+     console . info ( 
89+       `- ${ ! isExistingPage  ? 'Created'  : 'Updated' } ${ filePaths . emojiJS }  
90+     ) ; 
7591  }  else  { 
76-     console . info ( `- No changes to file : ${ filePaths . emojiJS }  ) ; 
92+     console . info ( `- No changes: ${ filePaths . emojiJS }  ) ; 
7793  } 
7894} 
7995
8096( async  ( )  =>  { 
81-   console . log ( 'Build emoji' ) ; 
97+   console . info ( 'Build emoji' ) ; 
8298
8399  try  { 
84100    const  emojiData  =  await  getEmojiData ( ) ; 
85101
86-     writeEmojiPage ( emojiData ) ; 
87-     writeEmojiJS ( emojiData ) ; 
88-   }  catch  ( e )  { 
89-     console . error ( e ) ; 
102+     if  ( emojiData )  { 
103+       writeEmojiPage ( emojiData ) ; 
104+       writeEmojiJS ( emojiData ) ; 
105+     } 
106+   }  catch  ( err )  { 
107+     console . warn ( `- Error: ${ err . message }  ) ; 
90108  } 
91109} ) ( ) ; 
0 commit comments