1
0
Fork 0

Refactor directories layout

This commit is contained in:
Pabloader 2024-07-09 12:51:37 +00:00
parent df8a4af0e9
commit adb8b4549e
14 changed files with 39 additions and 32 deletions

View File

@ -11,10 +11,10 @@ import { getGames } from './isGame';
import audioPlugin from './audioPlugin';
export async function buildHTML(game: string, production = false, portable = false) {
const html = await Bun.file(path.resolve(import.meta.dir, '..', 'assets', 'index.html')).text();
const html = await Bun.file(path.resolve(import.meta.dir, 'assets', 'index.html')).text();
const bundle = await Bun.build({
outdir: '/tmp',
entrypoints: [path.resolve(import.meta.dir, '..', 'index.ts')],
entrypoints: [path.resolve(import.meta.dir, '..', 'src', 'index.ts')],
sourcemap: production ? 'none' : 'inline',
define: {
global: 'window',

View File

@ -4,7 +4,7 @@ import fs from 'fs/promises';
export async function isGame(name: string | null | undefined) {
if (!name || name === 'index') return false;
const dir = path.resolve(import.meta.dir, '..', 'games', name);
const dir = path.resolve(import.meta.dir, '..', 'src', 'games', name);
if (!await fs.exists(dir)) return false;
@ -14,7 +14,7 @@ export async function isGame(name: string | null | undefined) {
}
export async function getGames() {
const dir = path.resolve(import.meta.dir, '..', 'games');
const dir = path.resolve(import.meta.dir, '..', 'src', 'games');
if (!await fs.exists(dir)) return [];
const stat = await fs.stat(dir);

View File

@ -29,8 +29,9 @@ Bun.serve({
}
} catch (e) {
console.error(e);
return new Response(`Error building HTML: ${e}`, { status: 500 });
}
return new Response(null, { status: 500 });
return new Response(`Error building HTML`, { status: 500 });
default:
console.log(`Pathname: ${pathname}`);
return new Response(null, { status: 404 });

View File

@ -1,10 +1,11 @@
{
"name": "tsgames",
"module": "index.ts",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "bun --hot src/build/server.ts",
"build": "bun src/build/build.ts"
"start": "bun --hot build/server.ts",
"build": "bun build/build.ts"
},
"dependencies": {
"classnames": "2.5.1",

24
src/common/types.d.ts vendored
View File

@ -1,24 +0,0 @@
declare module "*.png" {
const image: HTMLImageElement;
export default image;
}
declare module "*.jpg" {
const image: HTMLImageElement;
export default image;
}
declare module "*.jpeg" {
const image: HTMLImageElement;
export default image;
}
declare module "*.wav" {
const audio: HTMLAudioElement;
export default audio;
}
declare module "*.mp3" {
const audio: HTMLAudioElement;
export default audio;
}
declare module "*.ogg" {
const audio: HTMLAudioElement;
export default audio;
}

View File

@ -1,3 +1,7 @@
export function awoo(a: i32, b: i32): void {
console.log((a * b).toString());
}
export function testTemplate(a: i32, f: f64): string {
return `${a} + ${f} = ${a + f}`;
}

View File

@ -1,9 +1,10 @@
import { awoo } from "./awoo.wasm";
import { awoo, testTemplate } from "./awoo.wasm";
import { render } from "preact";
import attack from './assets/attack.wav';
export default function main() {
awoo(42, 69);
console.log(testTemplate(420, 69));
render(
<button onClick={() => attack.play()}>

24
src/types.d.ts vendored
View File

@ -10,4 +10,28 @@ declare module '*.module.css' {
declare module '*.module.scss' {
const classes: { [key: string]: string };
export default classes;
}
declare module "*.png" {
const image: HTMLImageElement;
export default image;
}
declare module "*.jpg" {
const image: HTMLImageElement;
export default image;
}
declare module "*.jpeg" {
const image: HTMLImageElement;
export default image;
}
declare module "*.wav" {
const audio: HTMLAudioElement;
export default audio;
}
declare module "*.mp3" {
const audio: HTMLAudioElement;
export default audio;
}
declare module "*.ogg" {
const audio: HTMLAudioElement;
export default audio;
}