Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Use config files instead of hardcoded vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanl21 committed Jul 12, 2023
1 parent 183bb56 commit 3542fd3
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>wasmGBA</title>
</head>
<body>
<div id="root"></div>
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "wasmgba",
"repository": {
"type": "git",
"url": "https://github.com/ethanl21/wasmGBA.git"
},
"license": "MIT",
"private": true,
"version": "0.0.0",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
13 changes: 4 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ function App() {
const [aboutDialogIsOpen, setAboutDialogIsOpen] = useState(false);
const [usageDialogIsOpen, setUsageDialogIsOpen] = useState(false);

// todo: use a config file instead of hardcoding these
const mGBARepoURL = new URL(
"https://github.com/thenick775/mgba/tree/c3d5ca5d5ffd47b2866fe6e40a7d551d845e512a"
);
const sourceRepoURL = new URL("https://github.com/ethanl21/wasmGBA");

return (
<>
<AboutDialog
open={aboutDialogIsOpen}
setIsOpen={setAboutDialogIsOpen}
upstreamRepo={mGBARepoURL}
repo={sourceRepoURL}
upstreamRepo={MGBA_UPSTREAM_REPO_URL}
repo={WASMGBA_REPO_URL}
/>
<UsageDialog open={usageDialogIsOpen} setIsOpen={setUsageDialogIsOpen} />

Expand All @@ -30,7 +24,8 @@ function App() {
<TopMenuBar
onOpenAboutDialog={() => setAboutDialogIsOpen(true)}
onOpenUsageDialog={() => setUsageDialogIsOpen(true)}
repo={sourceRepoURL}
repo={WASMGBA_REPO_URL}
licenses={WASMGBA_OSS_LICENSES_URL}
/>
</header>

Expand Down
13 changes: 6 additions & 7 deletions src/components/wasmgba/aboutdialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import {
import { Github } from "lucide-react";

interface AboutDialogProps {
upstreamRepo?: string | URL;
repo?: string | URL;
upstreamRepo?: string;
repo?: string;
open?: boolean;
setIsOpen?: (open: boolean) => void;
}
export default function AboutDialog(props: AboutDialogProps) {
if (typeof props.upstreamRepo === "string")
props.upstreamRepo = new URL(props.upstreamRepo);

let upstream = "";
let commit = "";
if (props.upstreamRepo != null) {
const parts = props.upstreamRepo?.pathname.split("/");
// copy string to prevent mutation of env var
const upstream_url = new URL(("" + props.upstreamRepo).slice(1));
const parts = upstream_url?.pathname.split("/");
upstream = `${parts[1]}/${parts[2]}`;
commit = `${parts[4]}`.slice(0, 10);
}
Expand All @@ -40,7 +39,7 @@ export default function AboutDialog(props: AboutDialogProps) {
target="_blank"
rel="noopener noreferrer"
>
{upstream} @ {commit}
{upstream}@{commit}
</a>
</DialogDescription>
)}
Expand Down
12 changes: 2 additions & 10 deletions src/components/wasmgba/topmenubar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,10 @@ interface TopMenuBarProps {
onOpenUsageDialog: () => void;
version?: string;
upstream?: string;
repo?: string | URL;
licenses?: string | URL;
repo?: string;
licenses?: string;
}
export default function TopMenuBar(props: TopMenuBarProps) {
if (typeof props.repo === "string") {
props.repo = new URL(props.repo);
}

if (typeof props.licenses === "string") {
props.licenses = new URL(props.licenses);
}

return (
<>
<Menubar>
Expand Down
2 changes: 1 addition & 1 deletion src/components/wasmgba/usagedialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function UsageDialog(props: UsageDialogProps) {
</TableHeader>
<TableBody>
{keybinds.map((keybind) => (
<TableRow>
<TableRow key={`gba-button-${keybind.gba}`}>
<td className="px-4 border-slate-200 border-r">
{keybind.gba}
</td>
Expand Down
16 changes: 9 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";

ReactDOM.createRoot(document.getElementById('root')!).render(
document.title = `wasmGBA v${WASMGBA_VERSION}-${import.meta.env.MODE}`;

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
</React.StrictMode>
);
4 changes: 4 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/// <reference types="vite/client" />
declare const WASMGBA_VERSION: string;
declare const WASMGBA_REPO_URL: string;
declare const WASMGBA_OSS_LICENSES_URL: string;
declare const MGBA_UPSTREAM_REPO_URL: string;
20 changes: 15 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import path from "path"
import react from "@vitejs/plugin-react-swc"
import { defineConfig } from "vite"
import path from "path";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";

export default defineConfig({
base: '/wasmGBA/',
base: "/wasmGBA/",
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
})
define: {
WASMGBA_VERSION: JSON.stringify(process.env.npm_package_version),
WASMGBA_REPO_URL: JSON.stringify(process.env.npm_package_repository_url),
WASMGBA_OSS_LICENSES_URL: JSON.stringify(
`${process.env.npm_package_repository_url}#Dependencies`
),
MGBA_UPSTREAM_REPO_URL: JSON.stringify(
"https://github.com/thenick775/mgba/tree/c3d5ca5d5ffd47b2866fe6e40a7d551d845e512a"
),
},
});

0 comments on commit 3542fd3

Please sign in to comment.