-
Notifications
You must be signed in to change notification settings - Fork 20
/
vite.config.js
187 lines (152 loc) · 4.94 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import fs from 'fs'
import sharp from 'sharp'
import tga2png from 'tga2png'
import request from 'sync-request'
if (!fs.existsSync('./icons')) fs.mkdirSync('./icons')
function getDirContents(p) {
return fs.readdirSync(p, function (err, files) {
var retArr = []
files.forEach(f => retArr.push(f))
return retArr
})
}
function getImages(p, type) {
return getDirContents(p).map(x => {
if (x.endsWith(`.${type}`)) return path.basename(x,`.${type}`)
}).filter(x => x)
}
function outputSharpImage(inputPath, outputPath, outputFormat) {
let img = sharp(inputPath)
if (outputFormat == 'jpeg') img.jpeg({ quality: 100 })
if (outputFormat == 'png') img.png()
else if (outputFormat == 'webp') img.webp({ quality: 100 })
else if (outputFormat == 'avif') img.avif({ quality: 70 })
img.toFile(outputPath, (err,) => {
if (err) console.log(err)
})
}
const tgaArr = getImages('./src/icons','tga')
const pngArr = getImages('./src/icons','png').filter(x => !tgaArr.includes(x))
for (const titleid of tgaArr) {
const tgaPath = `./src/icons/${titleid}.tga`
const pngPath = `./icons/${titleid}.png`
tga2png(tgaPath, pngPath).then(buf=> {
for (const format of ['jpeg','webp','avif']) {
outputSharpImage(
pngPath,
`./icons/${titleid}.${format}`,
format
)
}
}, err => {
console.log('error', err)
})
}
for (const titleid of pngArr) for (const format of ['jpeg','png','webp','avif']) {
outputSharpImage(
`./src/icons/${titleid}.png`,
`./icons/${titleid}.${format}`,
format
)
}
function getLatestReleases() {
return JSON.parse(request('GET','https://api.github.com/repos/cemu-project/Cemu/releases', { headers: { 'Content-Type': 'application/json', 'User-Agent': 'emiyl' } }).getBody())
}
async function getLatestWorkflow() {
let ret
let commits = JSON.parse(request('GET','https://api.github.com/repos/cemu-project/Cemu/commits', { headers: { 'Content-Type': 'application/json', 'User-Agent': 'emiyl' } }).getBody())
let runs = JSON.parse(request('GET','https://api.github.com/repos/cemu-project/Cemu/actions/runs', { headers: { 'Content-Type': 'application/json', 'User-Agent': 'emiyl' } }).getBody())
let i = -1
while (!ret) {
i++
const commit = commits[i]
if (!commit) break
const run = runs.workflow_runs.find(x => x.head_sha == commit.sha && x.workflow_id == 34555033)
if (run && run.conclusion == 'success') ret = run
}
return ret
}
async function getCachedEntries() {
let latestReleases = await getLatestReleases()
let releases = [{
overwriteMe: true,
label: 'Latest release',
version: '',
url: 'https://github.com/cemu-project/Cemu/releases/latest',
target: '_blank',
}]
function getRelease(release) {
let obj = {}
if (release) {
obj = {
label: `Latest ${release.prerelease ? 'pre-' : ''}release`,
version: release.tag_name,
ghurl: release.html_url,
ghtarget: '_blank'
}
}
else return
let macosAsset = release.assets.find(x => x.name.includes('macos'))
if (!macosAsset) {
releases.push(obj)
return
}
obj.url = macosAsset.browser_download_url
obj.target = ''
if (releases[0].overwriteMe) releases = []
releases.push(obj)
}
getRelease(latestReleases.filter(x => !x.prerelease)[0])
getRelease(latestReleases.filter(x => x.prerelease)[0])
let latestWorkflow = await getLatestWorkflow()
if (latestWorkflow) {
if (releases[0].overwriteMe) releases = []
releases.push({
label: 'Latest commit',
commit: latestWorkflow.head_sha,
url: latestWorkflow.html_url,
target: '_blank'
})
}
if (releases) fs.writeFile('./cachedReleases.json', JSON.stringify(releases.map(x => {
x.overwriteMe = true
return x
})), err => { if (err) console.log(err) })
else console.log(releases)
}
getCachedEntries()
function getAllFiles(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function(file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(path.join(dirPath, "/", file))
}
})
return arrayOfFiles
}
const titles = getAllFiles('./tests')
.filter(file => file.endsWith('.json'))
.map(x => require(`./${x}`))
let titleObj = {}
for (const title of titles) {
const tid = title.titleID
delete title.titleID
titleObj[tid] = title
}
fs.writeFileSync('./titles.json', JSON.stringify(titleObj))
export default defineConfig({
plugins: [vue(), vueJsx()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})