1
1
const { Octokit } = require ( "@octokit/rest" ) ;
2
2
const fs = require ( "fs" ) ;
3
- const createActionAuth = require ( "@octokit/auth-action" ) ;
3
+ const { createTokenAuth } = require ( "@octokit/auth-token" ) ;
4
+ const sharp = require ( "sharp" ) ;
4
5
5
6
const fullLogo = {
6
7
light : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long.svg" ,
@@ -21,14 +22,15 @@ async function main() {
21
22
fs . mkdirSync ( "public/generated" , { recursive : true } ) ;
22
23
}
23
24
24
- downloadThemedImage ( fullLogo , "public/generated/Logo-Long.svg" , true ) ;
25
- downloadThemedImage ( shortLogo , "public/generated/Logo-Short.svg" , true ) ;
26
- downloadThemedImage ( githubLogo , "public/generated/github-logo.svg" , false ) ;
27
- download ( "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Derpy-Outlined.svg" , "public/generated/derpy.svg" ) ;
25
+ await downloadThemedImage ( fullLogo , "public/generated/Logo-Long.svg" , true ) ;
26
+ await downloadThemedImage ( shortLogo , "public/generated/Logo-Short.svg" , true ) ;
27
+ await downloadThemedImage ( githubLogo , "public/generated/github-logo.svg" , false ) ;
28
+ await downloadAndConvertSvgToPng ( "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted-Outline.svg" , "public/generated/Logo-Short-Inverted-Outline.png" ) ;
29
+ await download ( "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Derpy-Outlined.svg" , "public/generated/derpy.svg" ) ;
28
30
emojis . push ( "derpy" ) ;
29
31
let octokit ;
30
32
if ( process . env . GITHUB_TOKEN !== undefined && process . env . GITHUB_TOKEN . length > 0 ) {
31
- const auth = createActionAuth ( ) ;
33
+ const auth = createTokenAuth ( process . env . GITHUB_TOKEN ) ;
32
34
const authentication = await auth ( ) ;
33
35
octokit = new Octokit ( {
34
36
auth : authentication . token
@@ -43,15 +45,16 @@ async function main() {
43
45
path : "Resources/Emojis"
44
46
} ) ;
45
47
46
- for ( let i = 0 ; i < response . data . length ; i ++ ) {
47
- const element = response . data [ i ] ;
48
+ const promises = response . data . map ( async element => {
48
49
console . log ( `Downloading ${ element . name } ...` ) ;
49
50
const resp = await fetch ( element . download_url ) ;
50
51
const emoji = await resp . text ( ) ;
51
52
await fs . promises . writeFile ( `public/generated/${ element . name } ` , emoji ) ;
52
- }
53
+ } ) ;
54
+ await Promise . all ( promises ) ;
55
+
53
56
response . data
54
- . map ( s => ` ${ s . name . replace ( / \. [ ^ / . ] + $ / , "" ) } ` )
57
+ . map ( s => s . name . replace ( / \. [ ^ / . ] + $ / , "" ) )
55
58
. forEach ( s => emojis . push ( s ) ) ;
56
59
await fs . promises . writeFile (
57
60
"src/generated/emojiTypes.ts" ,
@@ -130,4 +133,11 @@ ${logoLight}
130
133
</svg>
131
134
` ;
132
135
return logoSvg ;
136
+ }
137
+
138
+ async function downloadAndConvertSvgToPng ( url , outputPath ) {
139
+ const resp = await fetch ( url ) ;
140
+ const svgContent = await resp . text ( ) ;
141
+ await sharp ( Buffer . from ( svgContent ) ) . png ( ) . toFile ( outputPath ) ;
142
+ console . log ( `SVG converted and saved as ${ outputPath } ` ) ;
133
143
}
0 commit comments