Refactor directories layout
This commit is contained in:
parent
df8a4af0e9
commit
adb8b4549e
|
|
@ -11,10 +11,10 @@ import { getGames } from './isGame';
|
||||||
import audioPlugin from './audioPlugin';
|
import audioPlugin from './audioPlugin';
|
||||||
|
|
||||||
export async function buildHTML(game: string, production = false, portable = false) {
|
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({
|
const bundle = await Bun.build({
|
||||||
outdir: '/tmp',
|
outdir: '/tmp',
|
||||||
entrypoints: [path.resolve(import.meta.dir, '..', 'index.ts')],
|
entrypoints: [path.resolve(import.meta.dir, '..', 'src', 'index.ts')],
|
||||||
sourcemap: production ? 'none' : 'inline',
|
sourcemap: production ? 'none' : 'inline',
|
||||||
define: {
|
define: {
|
||||||
global: 'window',
|
global: 'window',
|
||||||
|
|
@ -4,7 +4,7 @@ import fs from 'fs/promises';
|
||||||
export async function isGame(name: string | null | undefined) {
|
export async function isGame(name: string | null | undefined) {
|
||||||
if (!name || name === 'index') return false;
|
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;
|
if (!await fs.exists(dir)) return false;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ export async function isGame(name: string | null | undefined) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGames() {
|
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 [];
|
if (!await fs.exists(dir)) return [];
|
||||||
|
|
||||||
const stat = await fs.stat(dir);
|
const stat = await fs.stat(dir);
|
||||||
|
|
@ -29,8 +29,9 @@ Bun.serve({
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(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:
|
default:
|
||||||
console.log(`Pathname: ${pathname}`);
|
console.log(`Pathname: ${pathname}`);
|
||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"name": "tsgames",
|
"name": "tsgames",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "bun --hot src/build/server.ts",
|
"start": "bun --hot build/server.ts",
|
||||||
"build": "bun src/build/build.ts"
|
"build": "bun build/build.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"classnames": "2.5.1",
|
"classnames": "2.5.1",
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
export function awoo(a: i32, b: i32): void {
|
export function awoo(a: i32, b: i32): void {
|
||||||
console.log((a * b).toString());
|
console.log((a * b).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function testTemplate(a: i32, f: f64): string {
|
||||||
|
return `${a} + ${f} = ${a + f}`;
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { awoo } from "./awoo.wasm";
|
import { awoo, testTemplate } from "./awoo.wasm";
|
||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
import attack from './assets/attack.wav';
|
import attack from './assets/attack.wav';
|
||||||
|
|
||||||
export default function main() {
|
export default function main() {
|
||||||
awoo(42, 69);
|
awoo(42, 69);
|
||||||
|
console.log(testTemplate(420, 69));
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<button onClick={() => attack.play()}>
|
<button onClick={() => attack.play()}>
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,27 @@ declare module '*.module.scss' {
|
||||||
const classes: { [key: string]: string };
|
const classes: { [key: string]: string };
|
||||||
export default classes;
|
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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue