feat: Implemented AppImage building
This commit is contained in:
parent
d8f471dadc
commit
6a288f765e
38 changed files with 1036 additions and 147 deletions
91
scripts/build-appimage.ts
Normal file
91
scripts/build-appimage.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import { $ } from "bun";
|
||||
import pkg from "../package.json";
|
||||
import fs from 'node:fs/promises';
|
||||
import { appBuilderPath, } from 'app-builder-bin';
|
||||
import path from 'node:path';
|
||||
import { ensureDir } from "fs-extra";
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// CONFIGURE THESE FOR YOUR APP
|
||||
// ─────────────────────────────────────────────
|
||||
const APP_DIR = "./build/linux";
|
||||
const BINARY_NAME = pkg.bin;
|
||||
const ICON = "./src/mainview/assets/256x256.png";
|
||||
const DESKTOP = "./flatpak/com.simeonradivoev.gameflow-deck.desktop";
|
||||
const TMP_FOLDER = ".";
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
const APP_NAME = pkg.displayName ?? pkg.name;
|
||||
const APP_ID = pkg.name;
|
||||
const APPDIR = path.resolve(path.join(TMP_FOLDER, `${APP_ID}.AppDir`));
|
||||
|
||||
console.log(`>>> Building AppImage for ${APP_NAME} (${APP_ID})...`);
|
||||
|
||||
await ensureDir(path.join(APPDIR, `usr`, 'bin'));
|
||||
await ensureDir("build");
|
||||
|
||||
// Copy app dir
|
||||
await fs.cp(`${APP_DIR}/.`, path.join(APPDIR, `usr`, 'share'), { recursive: true });
|
||||
await fs.rename(path.join(APPDIR, `usr`, 'share', BINARY_NAME), path.join(APPDIR, `usr`, 'bin', BINARY_NAME));
|
||||
|
||||
await fs.writeFile(path.join(APPDIR, `${APP_ID}.desktop`), `[Desktop Entry]
|
||||
Version=${pkg.version}
|
||||
X-AppImage-Name=${APP_NAME}
|
||||
X-AppImage-Version=${pkg.version}
|
||||
X-AppImage-Arch=${process.arch}
|
||||
Name=${APP_NAME}
|
||||
Comment=${pkg.description}
|
||||
Exec=${APP_ID}.AppImage
|
||||
Icon=.DirIcon
|
||||
Type=Application
|
||||
Categories=Game;
|
||||
`);
|
||||
|
||||
await Bun.write(path.join(APPDIR, "AppRun"), `#!/bin/bash
|
||||
APPDIR="$(dirname "$(readlink -f "$0")")"
|
||||
APPIMAGE=true
|
||||
exec "$APPDIR/usr/bin/${BINARY_NAME}" "$@"
|
||||
`);
|
||||
await $`chmod +x ${APPDIR}/AppRun`;
|
||||
|
||||
console.log(">>> Building AppImage...");
|
||||
const config = {
|
||||
productName: pkg.displayName,
|
||||
productFilename: pkg.name,
|
||||
executableName: BINARY_NAME,
|
||||
desktopEntry: DESKTOP,
|
||||
icons: [
|
||||
{
|
||||
file: ICON,
|
||||
size: 256
|
||||
}
|
||||
],
|
||||
fileAssociations: [
|
||||
|
||||
]
|
||||
};
|
||||
|
||||
const OUTPUT = path.resolve(path.join("build", `${APP_NAME}.AppImage`));
|
||||
const STAGE = path.resolve(path.join(TMP_FOLDER, `${APP_ID}.stage`));
|
||||
|
||||
await ensureDir(STAGE);
|
||||
|
||||
const proc = Bun.spawn([
|
||||
appBuilderPath,
|
||||
'appimage',
|
||||
`--app=${APPDIR}`,
|
||||
`--output=${OUTPUT}`,
|
||||
`--stage=${STAGE}`,
|
||||
`--arch=${process.arch}`,
|
||||
`--configuration=${JSON.stringify(config)}`
|
||||
], {
|
||||
stdout: "inherit",
|
||||
stderr: "inherit"
|
||||
});
|
||||
|
||||
const code = await proc.exited;
|
||||
await fs.rm(APPDIR, { recursive: true, force: true });
|
||||
await fs.rm(STAGE, { recursive: true, force: true });
|
||||
if (code !== 0) process.exit(code);
|
||||
|
||||
console.log(`\n✅ Done!`);
|
||||
|
|
@ -21,6 +21,10 @@ function spawnServer ()
|
|||
events.emit('exitapp');
|
||||
}
|
||||
},
|
||||
onExit (subprocess, exitCode, signalCode)
|
||||
{
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -35,5 +39,5 @@ function spawnBrowser ()
|
|||
};
|
||||
}
|
||||
|
||||
spawnServer();
|
||||
spawnBrowser();
|
||||
const server = spawnServer();
|
||||
spawnBrowser()?.then(e => server.send({ type: 'exitapp' }));
|
||||
45
scripts/generate-flatpak-sources.ts
Normal file
45
scripts/generate-flatpak-sources.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { $ } from "bun";
|
||||
|
||||
const lockfile = Bun.argv[2] ?? "bun.lockb";
|
||||
const output = Bun.argv[3] ?? ".config/flatpak/sources.gen.json";
|
||||
|
||||
const text = await $`bun ./bun.lockb --hash: 0000000000000000-0000000000000000-0000000000000000-0000000000000000`.text();
|
||||
|
||||
interface FlatpakSource
|
||||
{
|
||||
type: "file";
|
||||
url: string;
|
||||
dest: string;
|
||||
"dest-filename": string;
|
||||
sha512?: string;
|
||||
sha256?: string;
|
||||
}
|
||||
|
||||
const sources: FlatpakSource[] = [];
|
||||
|
||||
for (const block of text.split("\n\n"))
|
||||
{
|
||||
const resolved = block.match(/\s+resolved "([^"]+)"/)?.[1];
|
||||
const integrity = block.match(/\s+integrity (\S+)/)?.[1];
|
||||
|
||||
if (!resolved || !integrity) continue;
|
||||
|
||||
const [algo, b64] = integrity.split("-");
|
||||
const hex = Buffer.from(b64, "base64").toString("hex");
|
||||
const url = new URL(resolved);
|
||||
const filename = url.pathname.split("/").pop()!;
|
||||
const dest = `flatpak-node/npm-cache${url.pathname.replace(filename, "")}`;
|
||||
|
||||
sources.push({
|
||||
type: "file",
|
||||
url: resolved,
|
||||
dest,
|
||||
"dest-filename": filename,
|
||||
...(algo === "sha512" ? { sha512: hex } : { sha256: hex }),
|
||||
});
|
||||
}
|
||||
|
||||
await Bun.write(output, JSON.stringify(sources, null, 2));
|
||||
console.log(`Wrote ${sources.length} entries to ${output}`);
|
||||
|
||||
export { };
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import fs from "node:fs/promises";
|
||||
import path, { } from "node:path";
|
||||
import os from "node:os";
|
||||
import { Glob } from "bun";
|
||||
|
||||
const system = getPlatform();
|
||||
const buildSubDir = process.env.BUILD_DIR ?? `./build/${system.platform}`;
|
||||
|
|
@ -12,7 +11,7 @@ const compileOption: Bun.CompileBuildOptions = {
|
|||
autoloadTsconfig: true,
|
||||
autoloadPackageJson: true,
|
||||
autoloadDotenv: true,
|
||||
autoloadBunfig: true
|
||||
autoloadBunfig: true,
|
||||
};
|
||||
|
||||
if (process.env.TARGET)
|
||||
|
|
@ -23,7 +22,7 @@ if (process.env.TARGET)
|
|||
await Bun.build({
|
||||
entrypoints: ["./src/bun/index.ts", `./src/bun/webview/${system.platform}.ts`],
|
||||
metafile: true,
|
||||
compile: compileOption,
|
||||
compile: process.env.NON_COMPILED ? undefined : compileOption,
|
||||
outdir: buildSubDir,
|
||||
root: './src/bun',
|
||||
define: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue