diff --git a/packages/wrapper/src/index.js b/packages/wrapper/src/index.js index 70b7dc4b..f7f8752a 100755 --- a/packages/wrapper/src/index.js +++ b/packages/wrapper/src/index.js @@ -24,6 +24,22 @@ function checkDistIntegrity() { return true } +function fetchDistManifest() { + if (!fs.existsSync(global.distPath)) { + return null + } + + const pkgPath = path.join(global.distPath, "manifest.json") + + if (!fs.existsSync(pkgPath)) { + return null + } + + const pkg = require(pkgPath) + + return pkg +} + async function runServer() { const app = express() @@ -39,6 +55,16 @@ async function runServer() { app.use(express.static(global.distPath)) + app.get("/_dist_manifest", async (req, res) => { + const manifest = fetchDistManifest() + + if (!manifest) { + return res.status(500).send("Dist not found") + } + + return res.json(manifest) + }) + app.get("*", function (req, res) { res.sendFile(path.join(global.distPath, "index.html")) }) diff --git a/packages/wrapper/src/lib/setupDist.js b/packages/wrapper/src/lib/setupDist.js index c4bb78c0..aad625bf 100755 --- a/packages/wrapper/src/lib/setupDist.js +++ b/packages/wrapper/src/lib/setupDist.js @@ -8,14 +8,28 @@ const octokit = new Octokit({ // auth: process.env.GITHUB_TOKEN }) -async function getLatestReleaseBundleFromGithub() { - console.log("Getting latest release bundle from github...") +async function getLatestReleaseFromGithub() { + console.log("Getting latest release from github...") const release = await octokit.repos.getLatestRelease({ owner: global.remoteRepo.split("/")[0], repo: global.remoteRepo.split("/")[1] }) + return release.data +} + +async function getBundleFromRelease(release) { + const bundle = release.assets.find(asset => asset.name === "app_dist.7z") + + return bundle +} + +async function getLatestReleaseBundleFromGithub() { + console.log("Getting latest release bundle from github...") + + const release = await getLatestReleaseFromGithub() + const bundle = release.data.assets.find(asset => asset.name === "app_dist.7z") return bundle @@ -68,7 +82,18 @@ async function setupLatestRelease() { fs.mkdirSync(global.distPath) } - const bundle = await getLatestReleaseBundleFromGithub() + const release = await getLatestReleaseFromGithub() + + const bundle = await getBundleFromRelease(release) + + // wirte a manifest file with bundle version and other info + fs.writeFileSync(path.join(global.distPath, "manifest.json"), JSON.stringify( + { + version: release.tag_name, + date: release.published_at, + stable: !release.prerelease, + } + )) await downloadBundle(bundle)