@@ -4,112 +4,115 @@ const { createTokenAuth } = require("@octokit/auth-token");
4
4
const sharp = require ( "sharp" ) ;
5
5
6
6
const fullLogo = {
7
- light : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long.svg" ,
8
- dark : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long-Inverted.svg"
7
+ light : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long.svg" ,
8
+ dark : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Long-Inverted.svg" ,
9
9
} ;
10
10
const shortLogo = {
11
- light : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short.svg" ,
12
- dark : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted.svg"
11
+ light : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short.svg" ,
12
+ dark : "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted.svg" ,
13
13
} ;
14
14
const githubLogo = {
15
- light : "prebuild_assets/github-mark.svg" ,
16
- dark : "prebuild_assets/github-mark-white.svg"
15
+ light : "prebuild_assets/github-mark.svg" ,
16
+ dark : "prebuild_assets/github-mark-white.svg" ,
17
17
} ;
18
18
const emojis = [ ] ;
19
19
20
20
async function main ( ) {
21
- if ( ! fs . existsSync ( "public/generated" ) ) {
22
- fs . mkdirSync ( "public/generated" , { recursive : true } ) ;
23
- }
21
+ if ( ! fs . existsSync ( "public/generated" ) ) {
22
+ fs . mkdirSync ( "public/generated" , { recursive : true } ) ;
23
+ }
24
24
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" ) ;
30
- emojis . push ( "derpy" ) ;
31
- let octokit ;
32
- if ( process . env . GITHUB_TOKEN !== undefined && process . env . GITHUB_TOKEN . length > 0 ) {
33
- const auth = createTokenAuth ( process . env . GITHUB_TOKEN ) ;
34
- const authentication = await auth ( ) ;
35
- octokit = new Octokit ( {
36
- auth : authentication . token
37
- } ) ;
38
- } else {
39
- octokit = new Octokit ( ) ;
40
- }
41
-
42
- const response = await octokit . repos . getContent ( {
43
- owner : "Draco-lang" ,
44
- repo : "Language-suggestions" ,
45
- path : "Resources/Emojis"
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 (
29
+ "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Logo-Short-Inverted-Outline.svg" ,
30
+ "public/generated/Logo-Short-Inverted-Outline.png"
31
+ ) ;
32
+ await download (
33
+ "https://raw.githubusercontent.com/Draco-lang/Language-suggestions/main/Resources/Derpy-Outlined.svg" ,
34
+ "public/generated/derpy.svg"
35
+ ) ;
36
+ emojis . push ( "derpy" ) ;
37
+ let octokit ;
38
+ if ( process . env . GITHUB_TOKEN !== undefined && process . env . GITHUB_TOKEN . length > 0 ) {
39
+ const auth = createTokenAuth ( process . env . GITHUB_TOKEN ) ;
40
+ const authentication = await auth ( ) ;
41
+ octokit = new Octokit ( {
42
+ auth : authentication . token ,
46
43
} ) ;
44
+ } else {
45
+ octokit = new Octokit ( ) ;
46
+ }
47
47
48
- const promises = response . data . map ( async element => {
49
- console . log ( `Downloading ${ element . name } ...` ) ;
50
- const resp = await fetch ( element . download_url ) ;
51
- const emoji = await resp . text ( ) ;
52
- await fs . promises . writeFile ( `public/generated/${ element . name } ` , emoji ) ;
53
- } ) ;
54
- await Promise . all ( promises ) ;
48
+ const response = await octokit . repos . getContent ( {
49
+ owner : "Draco-lang" ,
50
+ repo : "Language-suggestions" ,
51
+ path : "Resources/Emojis" ,
52
+ } ) ;
55
53
56
- response . data
57
- . map ( s => s . name . replace ( / \. [ ^ / . ] + $ / , "" ) )
58
- . forEach ( s => emojis . push ( s ) ) ;
59
- await fs . promises . writeFile (
60
- "src/generated/emojiTypes.ts" ,
61
- `export type EmojiName = ${ emojis . map ( s => `"${ s } "` ) . join ( " | " ) } ;`
62
- ) ;
54
+ const promises = response . data . map ( async ( element ) => {
55
+ console . log ( `Downloading ${ element . name } ...` ) ;
56
+ const resp = await fetch ( element . download_url ) ;
57
+ const emoji = await resp . text ( ) ;
58
+ await fs . promises . writeFile ( `public/generated/${ element . name } ` , emoji ) ;
59
+ } ) ;
60
+ await Promise . all ( promises ) ;
61
+
62
+ response . data . map ( ( s ) => s . name . replace ( / \. [ ^ / . ] + $ / , "" ) ) . forEach ( ( s ) => emojis . push ( s ) ) ;
63
+ await fs . promises . writeFile (
64
+ "src/generated/emojiTypes.ts" ,
65
+ `export type EmojiName = ${ emojis . map ( ( s ) => `"${ s } "` ) . join ( " | " ) } ;`
66
+ ) ;
63
67
}
64
68
main ( ) ;
65
69
66
70
async function download ( url , path ) {
67
- const resp = await fetch ( url ) ;
68
- const text = await resp . text ( ) ;
69
- await fs . promises . writeFile ( path , text ) ;
71
+ const resp = await fetch ( url ) ;
72
+ const text = await resp . text ( ) ;
73
+ await fs . promises . writeFile ( path , text ) ;
70
74
}
71
75
72
76
async function downloadThemedImage ( urls , outputPath , isUrl ) {
73
- const svg = await createThemeBasedLogo ( urls . light , urls . dark , isUrl ) ;
74
- await fs . promises . writeFile ( outputPath , svg ) ;
75
- console . log ( `Image downloaded and saved as ${ outputPath } ` ) ;
77
+ const svg = await createThemeBasedLogo ( urls . light , urls . dark , isUrl ) ;
78
+ await fs . promises . writeFile ( outputPath , svg ) ;
79
+ console . log ( `Image downloaded and saved as ${ outputPath } ` ) ;
76
80
}
77
81
78
82
function stripXMLHeader ( xml ) {
79
- const regex = / < \? ? x m l [ ^ > ] * > / ;
80
- return xml . replace ( regex , "" ) ;
83
+ const regex = / < \? ? x m l [ ^ > ] * > / ;
84
+ return xml . replace ( regex , "" ) ;
81
85
}
82
86
83
87
function stripViewBox ( xml ) {
84
- const regex = / v i e w B o x = " [ ^ " ] * " / ;
85
- return xml . replace ( regex , "" ) ;
88
+ const regex = / v i e w B o x = " [ ^ " ] * " / ;
89
+ return xml . replace ( regex , "" ) ;
86
90
}
87
91
88
92
function extractOpeningSvgTag ( svgContent ) {
89
- const openingSvgTagRegex = / < s v g \b [ ^ > ] * > / ;
90
- const openingSvgTagMatch = svgContent . match ( openingSvgTagRegex ) ;
91
- return openingSvgTagMatch ? openingSvgTagMatch [ 0 ] : " <svg xmlns=\ "http://www.w3.org/2000/svg\">" ;
93
+ const openingSvgTagRegex = / < s v g \b [ ^ > ] * > / ;
94
+ const openingSvgTagMatch = svgContent . match ( openingSvgTagRegex ) ;
95
+ return openingSvgTagMatch ? openingSvgTagMatch [ 0 ] : ' <svg xmlns="http://www.w3.org/2000/svg">' ;
92
96
}
93
97
94
98
async function createThemeBasedLogo ( lightUrl , darkUrl , isUrl ) {
95
- let bodyLight , bodyDark ;
96
- if ( isUrl ) {
97
- const responseLight = await fetch ( lightUrl ) ;
98
- const responseDark = await fetch ( darkUrl ) ;
99
- bodyLight = await responseLight . text ( ) ;
100
- bodyDark = await responseDark . text ( ) ;
101
- } else {
102
- bodyLight = await fs . promises . readFile ( lightUrl , "utf-8" ) ;
103
- bodyDark = await fs . promises . readFile ( darkUrl , "utf-8" ) ;
104
- }
99
+ let bodyLight , bodyDark ;
100
+ if ( isUrl ) {
101
+ const responseLight = await fetch ( lightUrl ) ;
102
+ const responseDark = await fetch ( darkUrl ) ;
103
+ bodyLight = await responseLight . text ( ) ;
104
+ bodyDark = await responseDark . text ( ) ;
105
+ } else {
106
+ bodyLight = await fs . promises . readFile ( lightUrl , "utf-8" ) ;
107
+ bodyDark = await fs . promises . readFile ( darkUrl , "utf-8" ) ;
108
+ }
105
109
106
- let logoLight = stripXMLHeader ( bodyLight ) ;
107
- logoLight = stripViewBox ( logoLight ) ;
108
- let logoDark = stripXMLHeader ( bodyDark ) ;
109
- logoDark = stripViewBox ( logoDark ) ;
110
- const openingSvgTag = extractOpeningSvgTag ( bodyLight ) ;
111
- const logoSvg =
112
- `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
110
+ let logoLight = stripXMLHeader ( bodyLight ) ;
111
+ logoLight = stripViewBox ( logoLight ) ;
112
+ let logoDark = stripXMLHeader ( bodyDark ) ;
113
+ logoDark = stripViewBox ( logoDark ) ;
114
+ const openingSvgTag = extractOpeningSvgTag ( bodyLight ) ;
115
+ const logoSvg = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
113
116
${ openingSvgTag }
114
117
<style>
115
118
@media (prefers-color-scheme: dark) {
@@ -132,12 +135,12 @@ ${logoLight}
132
135
</g>
133
136
</svg>
134
137
` ;
135
- return logoSvg ;
138
+ return logoSvg ;
136
139
}
137
140
138
141
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 } ` ) ;
143
- }
142
+ const resp = await fetch ( url ) ;
143
+ const svgContent = await resp . text ( ) ;
144
+ await sharp ( Buffer . from ( svgContent ) ) . png ( ) . toFile ( outputPath ) ;
145
+ console . log ( `SVG converted and saved as ${ outputPath } ` ) ;
146
+ }
0 commit comments