@@ -9,12 +9,15 @@ const filePaths = {
9
9
'src' ,
10
10
'core' ,
11
11
'render' ,
12
- 'emojify -data.js'
12
+ 'emoji -data.js'
13
13
) ,
14
14
} ;
15
15
16
16
async function getEmojiData ( ) {
17
17
const emojiDataURL = 'https://api.github.com/emojis' ;
18
+
19
+ console . info ( `- Fetching emoji data from ${ emojiDataURL } ` ) ;
20
+
18
21
const response = await axios . get ( emojiDataURL ) ;
19
22
const baseURL = Object . values ( response . data )
20
23
. find ( url => / u n i c o d e \/ / )
@@ -26,16 +29,18 @@ async function getEmojiData() {
26
29
( [ key , value ] ) => ( data [ key ] = value . replace ( baseURL , '' ) )
27
30
) ;
28
31
32
+ console . info ( `- Retrieved ${ Object . keys ( data ) . length } emoji entries` ) ;
33
+
29
34
return {
30
35
baseURL,
31
36
data,
32
37
} ;
33
38
}
34
39
35
40
function writeEmojiPage ( emojiData ) {
41
+ const isExistingPage = fs . existsSync ( filePaths . emojiMarkdown ) ;
36
42
const emojiPage =
37
- ( fs . existsSync ( filePaths . emojiMarkdown ) &&
38
- fs . readFileSync ( filePaths . emojiMarkdown , 'utf8' ) ) ||
43
+ ( isExistingPage && fs . readFileSync ( filePaths . emojiMarkdown , 'utf8' ) ) ||
39
44
`<!-- START -->\n\n<!-- END -->` ;
40
45
const emojiRegEx = / ( < ! - - \s * S T A R T .* - - > \n ) ( [ \s \S ] * ) ( \n < ! - - \s * E N D .* - - > ) / ;
41
46
const emojiMatch = emojiPage . match ( emojiRegEx ) ;
@@ -53,39 +58,52 @@ function writeEmojiPage(emojiData) {
53
58
if ( emojiMarkdown !== newEmojiMarkdown ) {
54
59
const newEmojiPage = emojiPage . replace (
55
60
emojiMatch [ 0 ] ,
56
- `${ emojiMarkdownStart } \n${ newEmojiMarkdown } \n${ emojiMarkdownEnd } `
61
+ `${ emojiMarkdownStart } \n\n ${ newEmojiMarkdown } \n \n${ emojiMarkdownEnd } `
57
62
) ;
58
63
59
64
fs . writeFileSync ( filePaths . emojiMarkdown , newEmojiPage ) ;
60
- console . info ( `- Created new file: ${ filePaths . emojiMarkdown } ` ) ;
65
+
66
+ console . info (
67
+ `- ${ ! isExistingPage ? 'Created' : 'Updated' } : ${ filePaths . emojiMarkdown } `
68
+ ) ;
61
69
} else {
62
- console . info ( `- No changes to file : ${ filePaths . emojiMarkdown } ` ) ;
70
+ console . info ( `- No changes: ${ filePaths . emojiMarkdown } ` ) ;
63
71
}
64
72
}
65
73
66
74
function 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' ) ;
71
84
72
85
if ( ! emojiJS || emojiJS !== newEmojiJS ) {
73
86
fs . writeFileSync ( filePaths . emojiJS , newEmojiJS ) ;
74
- console . info ( `- Created new file: ${ filePaths . emojiJS } ` ) ;
87
+
88
+ console . info (
89
+ `- ${ ! isExistingPage ? 'Created' : 'Updated' } : ${ filePaths . emojiJS } `
90
+ ) ;
75
91
} else {
76
- console . info ( `- No changes to file : ${ filePaths . emojiJS } ` ) ;
92
+ console . info ( `- No changes: ${ filePaths . emojiJS } ` ) ;
77
93
}
78
94
}
79
95
80
96
( async ( ) => {
81
- console . log ( 'Build emoji' ) ;
97
+ console . info ( 'Build emoji' ) ;
82
98
83
99
try {
84
100
const emojiData = await getEmojiData ( ) ;
85
101
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 } ` ) ;
90
108
}
91
109
} ) ( ) ;
0 commit comments