M0.4: frontend with Vue 3, Pinia, ESLint, vue-tsc and Vitest
Empty workbench (main area and status bar) themed only through --lt-* tokens. ipc.ts wraps Tauri invoke so engine calls never reject; the app store loads app.about. Type-aware ESLint bans floating promises, any and inline comments. Requires Node 22.12+ for Vite 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
acc055c063
commit
50bcc95006
15 changed files with 456 additions and 2 deletions
43
ui/eslint.config.js
Normal file
43
ui/eslint.config.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* ESLint flat configuration of the Lutra frontend.
|
||||
*
|
||||
* Type-aware TypeScript rules apply to `.ts` and `.vue` files. Floating and
|
||||
* misused promises are errors so that no rejection goes unhandled, `any`
|
||||
* is an error, and inline comments are banned in favour of TSDoc blocks.
|
||||
*/
|
||||
import js from "@eslint/js";
|
||||
import { defineConfig } from "eslint/config";
|
||||
import pluginVue from "eslint-plugin-vue";
|
||||
import globals from "globals";
|
||||
import tseslint from "typescript-eslint";
|
||||
import vueParser from "vue-eslint-parser";
|
||||
|
||||
export default defineConfig(
|
||||
{ ignores: ["dist/**", "node_modules/**", "coverage/**"] },
|
||||
js.configs.recommended,
|
||||
tseslint.configs.strictTypeChecked,
|
||||
pluginVue.configs["flat/recommended"],
|
||||
{
|
||||
languageOptions: {
|
||||
parser: vueParser,
|
||||
parserOptions: {
|
||||
parser: tseslint.parser,
|
||||
projectService: true,
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
extraFileExtensions: [".vue"],
|
||||
},
|
||||
globals: { ...globals.browser },
|
||||
},
|
||||
rules: {
|
||||
"@typescript-eslint/no-floating-promises": "error",
|
||||
"@typescript-eslint/no-misused-promises": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"no-inline-comments": "error",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.js"],
|
||||
extends: [tseslint.configs.disableTypeChecked],
|
||||
languageOptions: { globals: { ...globals.node } },
|
||||
},
|
||||
);
|
||||
12
ui/index.html
Normal file
12
ui/index.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Lutra</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -4,6 +4,10 @@
|
|||
"version": "0.0.0",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=22.12"
|
||||
},
|
||||
"packageManager": "pnpm@10.34.7",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
|
|
|
|||
49
ui/src/App.vue
Normal file
49
ui/src/App.vue
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* Root component: the empty workbench of milestone M0, a main area and the
|
||||
* status bar. Loads product information from the engine on mount.
|
||||
*/
|
||||
import { onMounted } from "vue";
|
||||
import StatusBar from "./components/StatusBar.vue";
|
||||
import { useAppStore } from "./stores/app";
|
||||
|
||||
const app = useAppStore();
|
||||
|
||||
onMounted(() => {
|
||||
void app.loadAbout();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="workbench">
|
||||
<main
|
||||
class="workbench__main"
|
||||
data-test="main"
|
||||
>
|
||||
<p class="workbench__hint">
|
||||
{{ app.about?.slogan ?? "" }}
|
||||
</p>
|
||||
</main>
|
||||
<StatusBar />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.workbench {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.workbench__main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--lt-editor-bg);
|
||||
}
|
||||
|
||||
.workbench__hint {
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
</style>
|
||||
45
ui/src/components/StatusBar.vue
Normal file
45
ui/src/components/StatusBar.vue
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* Status bar along the bottom of the main window. Shows the product name and
|
||||
* version, or the last engine error.
|
||||
*/
|
||||
import { computed } from "vue";
|
||||
import { useAppStore } from "../stores/app";
|
||||
|
||||
const app = useAppStore();
|
||||
|
||||
/** Text on the left side of the bar. */
|
||||
const label = computed(() => {
|
||||
if (app.lastError) {
|
||||
return app.lastError.message;
|
||||
}
|
||||
return app.about ? `${app.about.name} ${app.about.version}` : "";
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<footer
|
||||
class="status-bar"
|
||||
:class="{ 'status-bar--error': app.lastError }"
|
||||
data-test="status-bar"
|
||||
>
|
||||
<span>{{ label }}</span>
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.status-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 24px;
|
||||
padding: 0 8px;
|
||||
background: var(--lt-statusbar-bg);
|
||||
color: var(--lt-statusbar-fg);
|
||||
border-top: 1px solid var(--lt-border);
|
||||
font-size: var(--lt-font-size-small);
|
||||
}
|
||||
|
||||
.status-bar--error {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
</style>
|
||||
10
ui/src/env.d.ts
vendored
Normal file
10
ui/src/env.d.ts
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Module declaration for single-file components, so that tools without Vue
|
||||
* support (the ESLint type checker) see `.vue` imports as components.
|
||||
* `vue-tsc` resolves the real component types.
|
||||
*/
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
const component: DefineComponent;
|
||||
export default component;
|
||||
}
|
||||
95
ui/src/ipc.ts
Normal file
95
ui/src/ipc.ts
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* Bridge from the frontend to the engine.
|
||||
*
|
||||
* Every user-visible action runs as an engine command through {@link run}.
|
||||
* Calls never reject: failures come back as `{ ok: false, error }` so that
|
||||
* every caller has to handle them.
|
||||
*/
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
/** A JSON value as exchanged with the engine. */
|
||||
export type JsonValue =
|
||||
| null
|
||||
| boolean
|
||||
| number
|
||||
| string
|
||||
| JsonValue[]
|
||||
| { [key: string]: JsonValue };
|
||||
|
||||
/** An error reported by the engine, with a stable machine-readable code. */
|
||||
export interface EngineError {
|
||||
/** Stable code such as `unknown_command`, `invalid_params` or `internal`. */
|
||||
code: string;
|
||||
/** Message for the user. */
|
||||
message: string;
|
||||
}
|
||||
|
||||
/** Outcome of an engine call. */
|
||||
export type RunResult<T> = { ok: true; value: T } | { ok: false; error: EngineError };
|
||||
|
||||
/** Static description of a command, as listed by the engine. */
|
||||
export interface CommandInfo {
|
||||
/** Command id, e.g. `app.about`. */
|
||||
id: string;
|
||||
/** Label shown in menus and the command palette. */
|
||||
label: string;
|
||||
/** Menu path such as `Help/About Lutra`, or null if not in a menu. */
|
||||
menuPath: string | null;
|
||||
/** Default shortcut in Lutra notation (`Mod+Q`), or null. */
|
||||
defaultShortcut: string | null;
|
||||
/** Documentation of the params object. */
|
||||
params: string;
|
||||
/** Whether the command can run in the current state. */
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns whatever a failed `invoke` rejected with into an {@link EngineError}.
|
||||
*
|
||||
* @param reason - the rejection value; the shell sends `{ code, message }`.
|
||||
* @returns the engine error, or an `ipc` error for anything else (for example
|
||||
* when the page runs outside the Tauri shell).
|
||||
*/
|
||||
export function toEngineError(reason: unknown): EngineError {
|
||||
if (typeof reason === "object" && reason !== null && "code" in reason && "message" in reason) {
|
||||
const { code, message } = reason;
|
||||
if (typeof code === "string" && typeof message === "string") {
|
||||
return { code, message };
|
||||
}
|
||||
}
|
||||
const message = reason instanceof Error ? reason.message : String(reason);
|
||||
return { code: "ipc", message };
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an engine command.
|
||||
*
|
||||
* @param commandId - the command id, e.g. `app.about`.
|
||||
* @param params - the command's params object.
|
||||
* @returns the command's result, or the error it failed with.
|
||||
*/
|
||||
export async function run<T = JsonValue>(
|
||||
commandId: string,
|
||||
params: JsonValue = {},
|
||||
): Promise<RunResult<T>> {
|
||||
try {
|
||||
const value = await invoke<T>("engine_execute", { command: commandId, params });
|
||||
return { ok: true, value };
|
||||
} catch (reason: unknown) {
|
||||
return { ok: false, error: toEngineError(reason) };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists every command the engine knows, with its current enabled state.
|
||||
*
|
||||
* @returns the commands, or the error the call failed with.
|
||||
*/
|
||||
export async function listCommands(): Promise<RunResult<CommandInfo[]>> {
|
||||
try {
|
||||
const value = await invoke<CommandInfo[]>("engine_list_commands");
|
||||
return { ok: true, value };
|
||||
} catch (reason: unknown) {
|
||||
return { ok: false, error: toEngineError(reason) };
|
||||
}
|
||||
}
|
||||
10
ui/src/main.ts
Normal file
10
ui/src/main.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Entry point of the Lutra frontend: creates the Vue app with Pinia and
|
||||
* mounts it on `#app`.
|
||||
*/
|
||||
import { createPinia } from "pinia";
|
||||
import { createApp } from "vue";
|
||||
import App from "./App.vue";
|
||||
import "./styles/base.css";
|
||||
|
||||
createApp(App).use(createPinia()).mount("#app");
|
||||
38
ui/src/stores/app.ts
Normal file
38
ui/src/stores/app.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Application-wide state: product information from `app.about` and the
|
||||
* last error the shell reported.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { run, type EngineError } from "../ipc";
|
||||
|
||||
/** Result of the `app.about` command. */
|
||||
export interface AboutInfo {
|
||||
/** Product name. */
|
||||
name: string;
|
||||
/** Version of the running build. */
|
||||
version: string;
|
||||
/** Slogan shown in the About window. */
|
||||
slogan: string;
|
||||
}
|
||||
|
||||
/** Store holding product information and the last engine error. */
|
||||
export const useAppStore = defineStore("app", () => {
|
||||
/** Product information, null until loaded. */
|
||||
const about = ref<AboutInfo | null>(null);
|
||||
/** Last error from the engine, null if none. */
|
||||
const lastError = ref<EngineError | null>(null);
|
||||
|
||||
/** Loads product information from the engine; on failure records the error. */
|
||||
async function loadAbout(): Promise<void> {
|
||||
const result = await run<AboutInfo>("app.about");
|
||||
if (result.ok) {
|
||||
about.value = result.value;
|
||||
lastError.value = null;
|
||||
} else {
|
||||
lastError.value = result.error;
|
||||
}
|
||||
}
|
||||
|
||||
return { about, lastError, loadAbout };
|
||||
});
|
||||
19
ui/src/styles/base.css
Normal file
19
ui/src/styles/base.css
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* Base layout of the Lutra window. Colours and fonts come only from the
|
||||
* theme tokens (`--lt-*`) that the desktop shell injects before first paint.
|
||||
*/
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--lt-bg);
|
||||
color: var(--lt-fg);
|
||||
font-family: var(--lt-font-ui);
|
||||
font-size: var(--lt-font-size-ui);
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
}
|
||||
36
ui/tests/App.test.ts
Normal file
36
ui/tests/App.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Tests for the root component: it loads product information on mount and
|
||||
* shows it, or the error, in the status bar.
|
||||
*/
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
|
||||
import App from "../src/App.vue";
|
||||
|
||||
describe("App", () => {
|
||||
beforeEach(() => {
|
||||
invoke.mockReset();
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
it("shows name and version in the status bar", async () => {
|
||||
invoke.mockResolvedValue({ name: "Lutra", version: "0.0.0", slogan: "An otterly perfect IDE" });
|
||||
const wrapper = mount(App);
|
||||
await flushPromises();
|
||||
expect(wrapper.get("[data-test=status-bar]").text()).toBe("Lutra 0.0.0");
|
||||
expect(wrapper.get("[data-test=main]").text()).toBe("An otterly perfect IDE");
|
||||
});
|
||||
|
||||
it("shows the engine error when the call fails", async () => {
|
||||
invoke.mockRejectedValue({ code: "internal", message: "engine unavailable" });
|
||||
const wrapper = mount(App);
|
||||
await flushPromises();
|
||||
const bar = wrapper.get("[data-test=status-bar]");
|
||||
expect(bar.text()).toBe("engine unavailable");
|
||||
expect(bar.classes()).toContain("status-bar--error");
|
||||
});
|
||||
});
|
||||
55
ui/tests/ipc.test.ts
Normal file
55
ui/tests/ipc.test.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Tests for the engine bridge: results and every kind of rejection map to
|
||||
* a `RunResult` instead of a rejected promise.
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
|
||||
import { listCommands, run, toEngineError } from "../src/ipc";
|
||||
|
||||
describe("run", () => {
|
||||
beforeEach(() => {
|
||||
invoke.mockReset();
|
||||
});
|
||||
|
||||
it("passes command and params to the shell", async () => {
|
||||
invoke.mockResolvedValue({ name: "Lutra" });
|
||||
const result = await run("app.about", { verbose: true });
|
||||
expect(invoke).toHaveBeenCalledWith("engine_execute", {
|
||||
command: "app.about",
|
||||
params: { verbose: true },
|
||||
});
|
||||
expect(result).toEqual({ ok: true, value: { name: "Lutra" } });
|
||||
});
|
||||
|
||||
it("returns engine errors instead of rejecting", async () => {
|
||||
invoke.mockRejectedValue({ code: "unknown_command", message: "no such command: x" });
|
||||
const result = await run("x");
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: { code: "unknown_command", message: "no such command: x" },
|
||||
});
|
||||
});
|
||||
|
||||
it("wraps unexpected rejections", async () => {
|
||||
invoke.mockRejectedValue(new Error("window.__TAURI_INTERNALS__ is undefined"));
|
||||
const result = await run("app.about");
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.ok ? null : result.error.code).toBe("ipc");
|
||||
});
|
||||
|
||||
it("lists commands", async () => {
|
||||
invoke.mockResolvedValue([]);
|
||||
expect(await listCommands()).toEqual({ ok: true, value: [] });
|
||||
expect(invoke).toHaveBeenCalledWith("engine_list_commands");
|
||||
});
|
||||
});
|
||||
|
||||
describe("toEngineError", () => {
|
||||
it("handles strings and malformed objects", () => {
|
||||
expect(toEngineError("boom")).toEqual({ code: "ipc", message: "boom" });
|
||||
expect(toEngineError({ code: 1, message: "x" }).code).toBe("ipc");
|
||||
});
|
||||
});
|
||||
22
ui/tsconfig.json
Normal file
22
ui/tsconfig.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"types": ["node", "vite/client"],
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
"exactOptionalPropertyTypes": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"isolatedModules": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"useDefineForClassFields": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve"
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.vue", "tests/**/*.ts", "vite.config.ts"]
|
||||
}
|
||||
15
ui/vite.config.ts
Normal file
15
ui/vite.config.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* Vite and Vitest configuration of the Lutra frontend.
|
||||
*
|
||||
* The dev server port is fixed because the Tauri shell loads it as `devUrl`.
|
||||
*/
|
||||
import { defineConfig } from "vitest/config";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
clearScreen: false,
|
||||
server: { port: 5173, strictPort: true },
|
||||
build: { target: "es2022", outDir: "dist" },
|
||||
test: { environment: "jsdom", include: ["tests/**/*.test.ts"] },
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue