|
| 1 | +const { default: axios } = require('axios') |
| 2 | +const fs = require('fs') |
| 3 | +const package = require('../package.json') |
| 4 | +const child_process = require('child_process') |
| 5 | +const os = require('os') |
| 6 | +const crypto = require('crypto') |
| 7 | + |
| 8 | +if (require.main === module) { |
| 9 | + main(); |
| 10 | +} |
| 11 | + |
| 12 | +async function main() { |
| 13 | + let placeholder = "" |
| 14 | + let releaseTime = "" |
| 15 | + if (process.argv[2] === "release") { |
| 16 | + const { data } = await axios.get("https://api.github.com/repos/HyperPlay-Gaming/hyperplay-desktop-client/releases/latest") |
| 17 | + const tarxz = data.assets.find((asset) => asset.browser_download_url.includes("tar.xz")) |
| 18 | + const outputFile = `${os.tmpdir()}/hyperplay.tar.xz` |
| 19 | + child_process.spawnSync("curl", ["-L", tarxz.browser_download_url, "-o", outputFile, "--create-dirs"]) |
| 20 | + const outputContent = fs.readFileSync(outputFile) |
| 21 | + const hashSum = crypto.createHash('sha512'); |
| 22 | + hashSum.update(outputContent); |
| 23 | + const sha512 = hashSum.digest('hex'); |
| 24 | + fs.rmSync(outputFile) |
| 25 | + |
| 26 | + placeholder = [ |
| 27 | + "type: file", |
| 28 | + `url: ${tarxz.browser_download_url}`, |
| 29 | + `sha512: ${sha512}` |
| 30 | + ].join("\n ") |
| 31 | + releaseTime = data.published_at.split('T')[0] |
| 32 | + } else { |
| 33 | + placeholder = [ |
| 34 | + "type: file", |
| 35 | + `path: "../dist/hyperplay-${package.version}.tar.xz"` |
| 36 | + ].join("\n ") |
| 37 | + releaseTime = new Date().toISOString().split('T')[0] |
| 38 | + } |
| 39 | + |
| 40 | + // generate flatpak-build |
| 41 | + if (!fs.existsSync("./flatpak-build")) { |
| 42 | + fs.mkdirSync('./flatpak-build', { recursive: true }) |
| 43 | + } |
| 44 | + |
| 45 | + // generate manifest |
| 46 | + let templateManifest = fs.readFileSync(`./flatpak/templates/xyz.hyperplay.HyperPlay.yml.template`, { encoding: 'utf-8' }) |
| 47 | + templateManifest = templateManifest.replace("${hyperplay-tarxz}", placeholder) |
| 48 | + fs.writeFileSync("./flatpak-build/xyz.hyperplay.HyperPlay.yml", templateManifest) |
| 49 | + |
| 50 | + // generate metainfo |
| 51 | + let templateMetaInfo = fs.readFileSync(`./flatpak/templates/xyz.hyperplay.HyperPlay.metainfo.xml.template`, { encoding: 'utf-8' }) |
| 52 | + templateMetaInfo = templateMetaInfo.replace("${hyperplay-version}", `v${package.version}`).replace("${hyperplay-release-date}", releaseTime) |
| 53 | + fs.writeFileSync("./flatpak-build/xyz.hyperplay.HyperPlay.metainfo.xml", templateMetaInfo) |
| 54 | + |
| 55 | + // copy extra files |
| 56 | + fs.copyFileSync("./flatpak/xyz.hyperplay.HyperPlay.desktop", "./flatpak-build/xyz.hyperplay.HyperPlay.desktop") |
| 57 | + fs.copyFileSync("./flatpak/xyz.hyperplay.HyperPlay.png", "./flatpak-build/xyz.hyperplay.HyperPlay.png") |
| 58 | + fs.copyFileSync("./flatpak/flathub.json", "./flatpak-build/flathub.json") |
| 59 | + fs.cpSync("./flatpak/patches", "./flatpak-build/patches", { recursive: true }) |
| 60 | +} |
0 commit comments