npm run format

This commit is contained in:
Ilion Beyst 2021-12-31 11:38:06 +01:00
parent 74d0189d37
commit 8d3b8fd8aa
10 changed files with 207 additions and 210 deletions

View file

@ -1,20 +1,20 @@
module.exports = { module.exports = {
root: true, root: true,
parser: '@typescript-eslint/parser', parser: "@typescript-eslint/parser",
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
plugins: ['svelte3', '@typescript-eslint'], plugins: ["svelte3", "@typescript-eslint"],
ignorePatterns: ['*.cjs'], ignorePatterns: ["*.cjs"],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], overrides: [{ files: ["*.svelte"], processor: "svelte3/svelte3" }],
settings: { settings: {
'svelte3/typescript': () => require('typescript') "svelte3/typescript": () => require("typescript"),
}, },
parserOptions: { parserOptions: {
sourceType: 'module', sourceType: "module",
ecmaVersion: 2020 ecmaVersion: 2020,
}, },
env: { env: {
browser: true, browser: true,
es2017: true, es2017: true,
node: true node: true,
} },
}; };

View file

@ -1,6 +1,6 @@
{ {
"useTabs": false, "useTabs": false,
"singleQuote": false, "singleQuote": false,
"trailingComma": "es5", "trailingComma": "es5",
"printWidth": 100 "printWidth": 100
} }

View file

@ -1,13 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="description" content="" /> <meta name="description" content="" />
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
%svelte.head% %svelte.head%
</head> </head>
<body> <body>
<div id="svelte">%svelte.body%</div> <div id="svelte">%svelte.body%</div>
</body> </body>
</html> </html>

View file

@ -1,7 +1,7 @@
export function set_session_token(token: string) { export function set_session_token(token: string) {
window.localStorage.setItem('session', token); window.localStorage.setItem("session", token);
} }
export function get_session_token(): string | null { export function get_session_token(): string | null {
return window.localStorage.getItem('session'); return window.localStorage.getItem("session");
} }

View file

@ -1,6 +1,6 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import { get_session_token } from "$lib/auth"; import { get_session_token } from "$lib/auth";
import { mount_component } from "svelte/internal"; import { mount_component } from "svelte/internal";
export async function load({ page }) { export async function load({ page }) {
const token = get_session_token(); const token = get_session_token();
@ -30,7 +30,7 @@ import { mount_component } from "svelte/internal";
<script lang="ts"> <script lang="ts">
import dayjs from "dayjs"; import dayjs from "dayjs";
export let bot: object; export let bot: object;
export let bundles: object[]; export let bundles: object[];

View file

@ -1,71 +1,71 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import { get_session_token } from '$lib/auth'; import { get_session_token } from "$lib/auth";
/** @type {import('@sveltejs/kit').Load} */ /** @type {import('@sveltejs/kit').Load} */
export async function load({ params, fetch, session, stuff }) { export async function load({ params, fetch, session, stuff }) {
const token = get_session_token(); const token = get_session_token();
const res = await fetch('/api/bots/my_bots', { const res = await fetch("/api/bots/my_bots", {
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`,
} },
}); });
if (res.ok) { if (res.ok) {
return { return {
props: { props: {
bots: await res.json() bots: await res.json(),
} },
}; };
} }
return { return {
status: res.status, status: res.status,
error: new Error('Could not load bots') error: new Error("Could not load bots"),
}; };
} }
</script> </script>
<script lang="ts"> <script lang="ts">
import { goto } from '$app/navigation'; import { goto } from "$app/navigation";
export let bots: object[]; export let bots: object[];
let name: string | undefined; let name: string | undefined;
async function createBot() { async function createBot() {
const token = get_session_token(); const token = get_session_token();
const res = await fetch('/api/bots', { const res = await fetch("/api/bots", {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
name: name name: name,
}) }),
}); });
if (res.ok) { if (res.ok) {
let bot = await res.json(); let bot = await res.json();
goto(`/bots/${bot['id']}`); goto(`/bots/${bot["id"]}`);
} else { } else {
new Error('creation failed'); new Error("creation failed");
} }
} }
</script> </script>
<form on:submit|preventDefault={createBot}> <form on:submit|preventDefault={createBot}>
<label for="name">Name</label> <label for="name">Name</label>
<input name="name" bind:value={name}/> <input name="name" bind:value={name} />
<button type="submit">Create</button> <button type="submit">Create</button>
</form> </form>
<ul> <ul>
{#each bots as bot} {#each bots as bot}
<li> <li>
<a target="_blank" href={`bots/${bot['id']}`}> <a target="_blank" href={`bots/${bot["id"]}`}>
{bot['name']} {bot["name"]}
</a> </a>
</li> </li>
{/each} {/each}
</ul> </ul>

View file

@ -1,46 +1,46 @@
<script lang="ts"> <script lang="ts">
import { get_session_token, set_session_token } from '$lib/auth'; import { get_session_token, set_session_token } from "$lib/auth";
import { goto } from '$app/navigation'; import { goto } from "$app/navigation";
let username: string | undefined; let username: string | undefined;
let password: string | undefined; let password: string | undefined;
const onSubmit = () => { const onSubmit = () => {
fetch('/api/login', { fetch("/api/login", {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json' "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
username, username,
password password,
}) }),
}) })
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
throw Error(response.statusText); throw Error(response.statusText);
} }
return response.text(); return response.text();
}) })
.then((token) => { .then((token) => {
set_session_token(token); set_session_token(token);
goto("/") goto("/");
}); });
}; };
function loggedIn(): boolean { function loggedIn(): boolean {
return get_session_token() != null return get_session_token() != null;
} }
</script> </script>
{#if loggedIn()} {#if loggedIn()}
you are logged in you are logged in
{/if} {/if}
<form on:submit|preventDefault={onSubmit}> <form on:submit|preventDefault={onSubmit}>
<label for="username">Username</label> <label for="username">Username</label>
<input name="username" bind:value={username} /> <input name="username" bind:value={username} />
<label for="password">Password</label> <label for="password">Password</label>
<input type="password" name="password" bind:value={password} /> <input type="password" name="password" bind:value={password} />
<button type="submit">Log in</button> <button type="submit">Log in</button>
</form> </form>

View file

@ -1,38 +1,38 @@
<script lang="ts"> <script lang="ts">
let username: string | undefined; let username: string | undefined;
let password: string | undefined; let password: string | undefined;
const onSubmit = () => { const onSubmit = () => {
if (username === undefined || username.trim() === '') { if (username === undefined || username.trim() === "") {
return;
}
if (password === undefined || password.trim() === '') {
return; return;
} }
fetch('/api/register', { if (password === undefined || password.trim() === "") {
method: 'POST', return;
headers: { }
'Content-Type': 'application/json'
}, fetch("/api/register", {
body: JSON.stringify({ method: "POST",
username, headers: {
password "Content-Type": "application/json",
}) },
}) body: JSON.stringify({
.then((resp) => resp.json()) username,
.then((data) => { password,
console.log(data); }),
}); })
}; .then((resp) => resp.json())
.then((data) => {
console.log(data);
});
};
</script> </script>
<h1>Register</h1> <h1>Register</h1>
<form on:submit|preventDefault={onSubmit}> <form on:submit|preventDefault={onSubmit}>
<label for="username">Username</label> <label for="username">Username</label>
<input name="username" bind:value={username} /> <input name="username" bind:value={username} />
<label for="password">Password</label> <label for="password">Password</label>
<input type="password" name="password" bind:value={password} /> <input type="password" name="password" bind:value={password} />
<button type="submit">Register</button> <button type="submit">Register</button>
</form> </form>

View file

@ -1,49 +1,46 @@
import adapter from '@sveltejs/adapter-auto'; import adapter from "@sveltejs/adapter-auto";
import preprocess from 'svelte-preprocess'; import preprocess from "svelte-preprocess";
// import { svelte } from '@sveltejs/vite-plugin-svelte' // import { svelte } from '@sveltejs/vite-plugin-svelte'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs' import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
import wasmPack from 'vite-plugin-wasm-pack'; import wasmPack from "vite-plugin-wasm-pack";
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
// Consult https://github.com/sveltejs/svelte-preprocess // Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors // for more information about preprocessors
preprocess: preprocess(), preprocess: preprocess(),
kit: { kit: {
adapter: adapter(), adapter: adapter(),
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
ssr: false,
vite: {
plugins: [
// svelte(),
// wasmPack([], ["planetwars-rs"]),
viteCommonjs({
transformMixedEsModules: true,
}),
],
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
server: {
proxy: {
"/api/": "http://localhost:9000",
"/ws": "ws://localhost:9000/ws",
},
fs: {
// Allow serving files from one level up to the project root
allow: ['..']
}
},
}
},
// hydrate the <div id="svelte"> element in src/app.html
target: "#svelte",
ssr: false,
vite: {
plugins: [
// svelte(),
// wasmPack([], ["planetwars-rs"]),
viteCommonjs({
transformMixedEsModules: true,
}),
],
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
server: {
proxy: {
"/api/": "http://localhost:9000",
"/ws": "ws://localhost:9000/ws",
},
fs: {
// Allow serving files from one level up to the project root
allow: [".."],
},
},
},
},
}; };
export default config; export default config;

View file

@ -1,31 +1,31 @@
{ {
"compilerOptions": { "compilerOptions": {
"moduleResolution": "node", "moduleResolution": "node",
"module": "es2020", "module": "es2020",
"lib": ["es2020", "DOM"], "lib": ["es2020", "DOM"],
"target": "es2020", "target": "es2020",
/** /**
svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
to enforce using \`import type\` instead of \`import\` for Types. to enforce using \`import type\` instead of \`import\` for Types.
*/ */
"importsNotUsedAsValues": "error", "importsNotUsedAsValues": "error",
"isolatedModules": true, "isolatedModules": true,
"resolveJsonModule": true, "resolveJsonModule": true,
/** /**
To have warnings/errors of the Svelte compiler at the correct position, To have warnings/errors of the Svelte compiler at the correct position,
enable source maps by default. enable source maps by default.
*/ */
"sourceMap": true, "sourceMap": true,
"esModuleInterop": true, "esModuleInterop": true,
"skipLibCheck": true, "skipLibCheck": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"baseUrl": ".", "baseUrl": ".",
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"paths": { "paths": {
"$lib": ["src/lib"], "$lib": ["src/lib"],
"$lib/*": ["src/lib/*"] "$lib/*": ["src/lib/*"]
} }
}, },
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"] "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"]
} }