1
0
Fork 0

Build for itch

This commit is contained in:
Pabloader 2025-08-25 12:06:21 +00:00
parent ee38d7f53c
commit 043378cfbb
3 changed files with 43 additions and 7 deletions

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<title><!--$TITLE$--></title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
overflow: hidden;
font-family: sans-serif;
}
/*$STYLE$*/
</style>
<!--$ICON$-->
</head>
<body>
<!--$SCRIPT$-->
</body>
</html>

View File

@ -9,9 +9,12 @@ import { isGame, getGames } from './isGame';
const outDir = path.resolve(import.meta.dir, '..', 'dist');
await fs.mkdir(outDir, { recursive: true });
let game = process.argv[2];
const publish = process.env.PUBLISH_LOCATION;
const args = process.argv.slice(2);
const itch = args.includes('--itch');
let game = args.find(a => !a.startsWith('-')) ?? '';
while (!await isGame(game)) {
game = await select({
message: 'Game to build:',
@ -19,7 +22,7 @@ while (!await isGame(game)) {
});
}
console.log(`Building ${game}...`);
const html = await buildHTML(game, { production: true });
const html = await buildHTML(game, { production: true, itch });
if (!html) {
process.exit(1);
@ -27,7 +30,7 @@ if (!html) {
const filePath = path.resolve(outDir, `${game}.html`);
await Bun.write(filePath, html);
if (publish) {
if (publish && !itch) {
console.log(`Publishing ${game}...`);
const result = await $`scp "${filePath}" "${publish}${game}.html"`;
if (result.exitCode === 0) {

View File

@ -13,10 +13,11 @@ import { getGames } from './isGame';
interface Args {
production?: boolean;
portable?: boolean;
mobile?: boolean
mobile?: boolean;
itch?: boolean;
}
export async function buildHTML(game: string, { production = false, portable = false, mobile = false }: Args = {}) {
const html = await Bun.file(path.resolve(import.meta.dir, 'assets', 'index.html')).text();
export async function buildHTML(game: string, { production = false, portable = false, mobile = false, itch = false }: Args = {}) {
const html = await Bun.file(path.resolve(import.meta.dir, 'assets', itch ? 'index-itch.html' : 'index.html')).text();
const bundle = await Bun.build({
outdir: '/tmp',
entrypoints: [path.resolve(import.meta.dir, '..', 'src', 'index.ts')],
@ -110,7 +111,7 @@ export async function buildHTML(game: string, { production = false, portable = f
.replace('<!--$TITLE$-->', () => title)
.replace('<!--$ICON$-->', () => icon)
.replace('<!--$MANIFEST$-->', () => manifest)
.replace('/*$STYLE$*/', () => style);
.replace('/*$STYLE$*/', () => style);
return minify(resultHTML, {
collapseWhitespace: production,