Add linting with prettier.

This commit is contained in:
wearrrrr 2024-02-06 11:53:55 -06:00
parent c5b054d5ec
commit 39fc988bce
16 changed files with 11073 additions and 11077 deletions

2
.prettierignore Normal file
View file

@ -0,0 +1,2 @@
dist
node_modules

View file

@ -1,4 +1,4 @@
import { defineConfig } from 'astro/config';
import { defineConfig } from "astro/config";
import node from "@astrojs/node";
@ -8,5 +8,5 @@ export default defineConfig({
output: "hybrid",
adapter: node({
mode: "middleware",
})
}),
});

View file

@ -1,12 +1,12 @@
import { createBareServer } from "@tomphttp/bare-server-node"
import { uvPath } from "@nebula-services/ultraviolet"
import http from 'node:http';
import path from 'node:path';
import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';
import dotenv from 'dotenv';
import compression from "compression"
import chalk from "chalk"
import { createBareServer } from "@tomphttp/bare-server-node";
import { uvPath } from "@nebula-services/ultraviolet";
import http from "node:http";
import path from "node:path";
import express from "express";
import { handler as ssrHandler } from "./dist/server/entry.mjs";
import dotenv from "dotenv";
import compression from "compression";
import chalk from "chalk";
dotenv.config();
const PORT = process.env.PORT || 3000;
@ -19,15 +19,16 @@ app.use(express.static(path.join(process.cwd(), "static")));
app.use(express.static(path.join(process.cwd(), "build")));
app.use("/uv/", express.static(uvPath));
app.use(express.json());
app.use(express.urlencoded({
extended: true
app.use(
express.urlencoded({
extended: true,
})
);
app.use("/", express.static('dist/client/'));
app.use("/", express.static("dist/client/"));
app.use(ssrHandler);
app.get('*', function(req, res){
res.status(200).sendFile("404.html", {root: path.resolve("dist/client")});
app.get("*", function (req, res) {
res.status(200).sendFile("404.html", { root: path.resolve("dist/client") });
});
server.on("request", (req, res) => {
@ -46,11 +47,11 @@ server.on("upgrade", (req, socket, head) => {
}
});
console.log(chalk.gray("Starting Alu..."))
console.log(chalk.gray("Starting Alu..."));
server.on("listening", () => {
console.log(chalk.green(`Server running at http://localhost:${PORT}/.`));
});
server.listen({
port: PORT
port: PORT,
});

938
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,14 +4,16 @@
"version": "0.0.1",
"scripts": {
"start": "node .",
"build": "astro build"
"build": "astro build",
"lint": "prettier --write .",
"lint:check": "prettier --check ."
},
"dependencies": {
"@astrojs/check": "^0.4.0",
"@astrojs/node": "^7.0.4",
"@nebula-services/ultraviolet": "^1.0.1-1.patch.5",
"@tomphttp/bare-server-node": "^2.0.1",
"astro": "^4.1.1",
"astro": "^4.3.3",
"astro-i18n": "^2.2.4",
"astro-i18next": "^1.0.0-beta.21",
"chalk": "^5.3.0",
@ -23,5 +25,8 @@
"i18next-browser-languagedetector": "^7.2.0",
"npm": "^10.2.5",
"typescript": "^5.3.3"
},
"devDependencies": {
"prettier": "3.2.5"
}
}

10
prettier.config.js Normal file
View file

@ -0,0 +1,10 @@
const config = {
tabWidth: 2,
semi: true,
trailingComma: "es5",
bracketSpacing: true,
bracketSameLine: true,
arrowParens: "always",
};
export default config;

View file

@ -5,8 +5,8 @@
* Ideally, this will be registered under the scope in uv.config.js so it will not need to be modified.
* However, if a user changes the location of uv.bundle.js/uv.config.js or sw.js is not relative to them, they will need to modify this script locally.
*/
importScripts('/uv/uv.bundle.js');
importScripts('/uv.config.js');
importScripts("/uv/uv.bundle.js");
importScripts("/uv.config.js");
importScripts(__uv$config.sw);
self.addEventListener("install", (event) => {
@ -15,4 +15,4 @@ self.addEventListener("install", (event) => {
const sw = new UVServiceWorker();
self.addEventListener('fetch', (event) => event.respondWith(sw.fetch(event)));
self.addEventListener("fetch", (event) => event.respondWith(sw.fetch(event)));

View file

@ -1,12 +1,12 @@
/*global Ultraviolet*/
self.__uv$config = {
prefix: '/service/',
bare: '/bare/',
prefix: "/service/",
bare: "/bare/",
encodeUrl: Ultraviolet.codec.xor.encode,
decodeUrl: Ultraviolet.codec.xor.decode,
handler: '/uv/uv.handler.js',
client: '/uv/uv.client.js',
bundle: '/uv/uv.bundle.js',
config: '/uv/uv.config.js',
sw: '/uv/uv.sw.js',
handler: "/uv/uv.handler.js",
client: "/uv/uv.client.js",
bundle: "/uv/uv.bundle.js",
config: "/uv/uv.config.js",
sw: "/uv/uv.sw.js",
};

234
src/env.d.ts vendored
View file

@ -1,205 +1,247 @@
/// <reference types="astro/client" />
// ###> astro-i18n/type-generation ###
type PrimaryLocale = "en"
type SecondaryLocale = ""
type Locale = PrimaryLocale | SecondaryLocale
type RouteParameters = {"/games":undefined;"/":undefined;"/settings":undefined;"/404":undefined;}
type Route = keyof RouteParameters
type TranslationVariables = {"nav.brand":object|undefined;"nav.games":object|undefined;"nav.settings":object|undefined;}
type Translation = keyof TranslationVariables
type Environment = "none"|"node"|"browser"
type PrimaryLocale = "en";
type SecondaryLocale = "";
type Locale = PrimaryLocale | SecondaryLocale;
type RouteParameters = {
"/games": undefined;
"/": undefined;
"/settings": undefined;
"/404": undefined;
};
type Route = keyof RouteParameters;
type TranslationVariables = {
"nav.brand": object | undefined;
"nav.games": object | undefined;
"nav.settings": object | undefined;
};
type Translation = keyof TranslationVariables;
type Environment = "none" | "node" | "browser";
declare module "astro-i18n" {
type GetStaticPathsProps = {paginate:Function;rss:Function}
type GetStaticPathsItem = {params:Record<string,number|string|undefined>;props?:Record<string,unknown>}
type DeepStringRecord = {[key: string]:string|DeepStringRecord}
type TranslationDirectory = {i18n?:string;pages?: string}
export type Translations = {[group: string]:{[locale: string]: DeepStringRecord}}
export type TranslationFormatters = {[formatterName: string]:(value:unknown,...args:unknown[])=>unknown}
export type TranslationLoadingRules = {groups:string[];routes: string[]}[]
export type SegmentTranslations = {[secondaryLocale: string]:{[segment: string]:string}}
export interface AstroI18nConfig {primaryLocale:string;secondaryLocales:string[];fallbackLocale:string;showPrimaryLocale:boolean;trailingSlash:"always"|"never";run:"server"|"client+server";translations:Translations;translationLoadingRules:TranslationLoadingRules;translationDirectory:TranslationDirectory;routes:SegmentTranslations;srcDir:string;}
type GetStaticPathsProps = { paginate: Function; rss: Function };
type GetStaticPathsItem = {
params: Record<string, number | string | undefined>;
props?: Record<string, unknown>;
};
type DeepStringRecord = { [key: string]: string | DeepStringRecord };
type TranslationDirectory = { i18n?: string; pages?: string };
export type Translations = {
[group: string]: { [locale: string]: DeepStringRecord };
};
export type TranslationFormatters = {
[formatterName: string]: (value: unknown, ...args: unknown[]) => unknown;
};
export type TranslationLoadingRules = {
groups: string[];
routes: string[];
}[];
export type SegmentTranslations = {
[secondaryLocale: string]: { [segment: string]: string };
};
export interface AstroI18nConfig {
primaryLocale: string;
secondaryLocales: string[];
fallbackLocale: string;
showPrimaryLocale: boolean;
trailingSlash: "always" | "never";
run: "server" | "client+server";
translations: Translations;
translationLoadingRules: TranslationLoadingRules;
translationDirectory: TranslationDirectory;
routes: SegmentTranslations;
srcDir: string;
}
/** Typed astro-i18n config definition. */
export function defineAstroI18nConfig(config: Partial<AstroI18nConfig>): Partial<AstroI18nConfig>
export function defineAstroI18nConfig(
config: Partial<AstroI18nConfig>
): Partial<AstroI18nConfig>;
/** The `astro-i18n` middleware. */
export function useAstroI18n(
config?: Partial<AstroI18nConfig> | string,
formatters?: TranslationFormatters,
): (...args: any[]) => any
formatters?: TranslationFormatters
): (...args: any[]) => any;
/** Workaround function to make astroI18n work inside getStaticPaths. This is because Astro's getStaticPaths runs before everything which doesn't allows astroI18n to update its state automatically. */
function createGetStaticPaths(
callback: (
props: GetStaticPathsProps,
) => GetStaticPathsItem[] | Promise<GetStaticPathsItem[]>,
): (props: GetStaticPathsProps & {
props: GetStaticPathsProps
) => GetStaticPathsItem[] | Promise<GetStaticPathsItem[]>
): (
props: GetStaticPathsProps & {
astroI18n?: {
locale: string;
};
}) => Promise<GetStaticPathsItem[]>
}
) => Promise<GetStaticPathsItem[]>;
/**
* @param key The translation key, for example `"my.nested.translation.key"`.
* @param properties An object containing your interpolation variables and/or your variants, for example `{ variant: 3, interpolation: "text" }`.
* @param options `route`: Overrides the current route, you will be able to access that route's translations. `locale`: Overrides the current locale, this allows you to control which language you want to translate to. `fallbackLocale`: Overrides the fallback locale.
*/
export function t<T extends Translation>(
key: T | string & {},
key: T | (string & {}),
...args: undefined extends TranslationVariables[T]
? [
properties?: keyof TranslationVariables extends T
? Record<string, unknown>
: TranslationVariables[T],
options?: {
route?: Route | string & {}
locale?: Locale | string & {}
fallbackLocale?: Locale | string & {}
}
route?: Route | (string & {});
locale?: Locale | (string & {});
fallbackLocale?: Locale | (string & {});
},
]
: [
properties: TranslationVariables[T],
options?: {
route?: Route | string & {}
locale?: Locale | string & {}
fallbackLocale?: Locale | string & {}
}
route?: Route | (string & {});
locale?: Locale | (string & {});
fallbackLocale?: Locale | (string & {});
},
]
): string
): string;
/**
* @param route A route in any of the configured languages, for example `"/en/my/english/route/[param]"`.
* @param parameters An object containing your route parameters, for example `{ slug: "my-blog-post-slug" }`.
* @param options `targetLocale`: Overrides the target locale. `routeLocale`: Overrides the given route locale, this is useful if astro-i18n cannot figure out the route's locale. `showPrimaryLocale`: Overrides the showPrimaryLocale parameter. `query`: Adds these query parameters at the end of the translated route.
*/
export function l<T extends Route>(
route: T | string & {},
route: T | (string & {}),
...args: T extends keyof RouteParameters
? undefined extends RouteParameters[T]
? [
parameters?: Record<string, string>,
options?: {
targetLocale?: string,
routeLocale?: string,
showPrimaryLocale?: string,
query?: Record<string, unknown>
}
targetLocale?: string;
routeLocale?: string;
showPrimaryLocale?: string;
query?: Record<string, unknown>;
},
]
: [
parameters: RouteParameters[T],
options?: {
targetLocale?: string,
routeLocale?: string,
showPrimaryLocale?: string,
query?: Record<string, unknown>
}
targetLocale?: string;
routeLocale?: string;
showPrimaryLocale?: string;
query?: Record<string, unknown>;
},
]
: [
parameters?: Record<string, string>,
options?: {
targetLocale?: string,
routeLocale?: string,
showPrimaryLocale?: string,
query?: Record<string, unknown>
}
targetLocale?: string;
routeLocale?: string;
showPrimaryLocale?: string;
query?: Record<string, unknown>;
},
]
): string
): string;
class AstroI18n {
/** The detected runtime environment. */
environment: Environment
environment: Environment;
/** The current page route. */
route: string
route: string;
/** All page routes. For example: `["/", "/about", "/posts/[slug]"]` */
pages: string[]
pages: string[];
/** The equivalent page for the current route. For example if route is equal to `"/posts/my-cool-cat"` this could return `"/posts/[slug]"`. */
page: string
page: string;
/** The current page locale. */
locale: Locale
locale: Locale;
/** All configured locales. */
locales: Locale[]
locales: Locale[];
/** The default/primary locale. */
primaryLocale: PrimaryLocale
primaryLocale: PrimaryLocale;
/** Locales other than the default/primary one. */
secondaryLocales: SecondaryLocale[]
secondaryLocales: SecondaryLocale[];
/** The fallback locale, when a translation is missing in a locale the fallback locale will be used to find a replacement. */
fallbackLocale: Locale
fallbackLocale: Locale;
/** True when astro-i18n is initialized. */
isInitialized: boolean
isInitialized: boolean;
/**
* @param key The translation key, for example `"my.nested.translation.key"`.
* @param properties An object containing your interpolation variables and/or your variants, for example `{ variant: 3, interpolation: "text" }`.
* @param options `route`: Overrides the current route, you will be able to access that route's translations. `locale`: Overrides the current locale, this allows you to control which language you want to translate to. `fallbackLocale`: Overrides the fallback locale.
*/
t<T extends Translation>(
key: T | string & {},
key: T | (string & {}),
...args: undefined extends TranslationVariables[T]
? [
properties?: keyof TranslationVariables extends T
? Record<string, unknown>
: TranslationVariables[T],
options?: {
route?: Route | string & {}
locale?: Locale | string & {}
fallbackLocale?: Locale | string & {}
}
route?: Route | (string & {});
locale?: Locale | (string & {});
fallbackLocale?: Locale | (string & {});
},
]
: [
properties: TranslationVariables[T],
options?: {
route?: Route | string & {}
locale?: Locale | string & {}
fallbackLocale?: Locale | string & {}
}
route?: Route | (string & {});
locale?: Locale | (string & {});
fallbackLocale?: Locale | (string & {});
},
]
): string
): string;
/**
* @param route A route in any of the configured languages, for example `"/en/my/english/route/[param]"`.
* @param parameters An object containing your route parameters, for example `{ slug: "my-blog-post-slug" }`.
* @param options `targetLocale`: Overrides the target locale. `routeLocale`: Overrides the given route locale, this is useful if astro-i18n cannot figure out the route's locale. `showPrimaryLocale`: Overrides the showPrimaryLocale parameter. `query`: Adds these query parameters at the end of the translated route.
*/
l<T extends Route>(
route: T | string & {},
route: T | (string & {}),
...args: T extends keyof RouteParameters
? undefined extends RouteParameters[T]
? [
parameters?: Record<string, string>,
options?: {
targetLocale?: string,
routeLocale?: string,
showPrimaryLocale?: string,
query?: Record<string, unknown>
}
targetLocale?: string;
routeLocale?: string;
showPrimaryLocale?: string;
query?: Record<string, unknown>;
},
]
: [
parameters: RouteParameters[T],
options?: {
targetLocale?: string,
routeLocale?: string,
showPrimaryLocale?: string,
query?: Record<string, unknown>
}
targetLocale?: string;
routeLocale?: string;
showPrimaryLocale?: string;
query?: Record<string, unknown>;
},
]
: [
parameters?: Record<string, string>,
options?: {
targetLocale?: string,
routeLocale?: string,
showPrimaryLocale?: string,
query?: Record<string, unknown>
}
targetLocale?: string;
routeLocale?: string;
showPrimaryLocale?: string;
query?: Record<string, unknown>;
},
]
): string
): string;
/** Adds new translations at runtime. */
addTranslations(translations: Translations): this
addTranslations(translations: Translations): this;
/** Adds new translation formatters at runtime. */
addFormatters(translationFormatters: TranslationFormatters): this
addFormatters(translationFormatters: TranslationFormatters): this;
/** Adds new translation loading rules at runtime. */
addTranslationLoadingRules(translationLoadingRules: TranslationLoadingRules): this
addTranslationLoadingRules(
translationLoadingRules: TranslationLoadingRules
): this;
/** Adds new route segment translations at runtime. */
addRoutes(routes: SegmentTranslations): this
addRoutes(routes: SegmentTranslations): this;
/** Tries to parse one of the configured locales out of the given route. If no configured locale is found it will return `null`. */
extractRouteLocale(route: string): string|null
extractRouteLocale(route: string): string | null;
/** Initializes astro-i18n on the server-side. */
initialize(config?: Partial<AstroI18nConfig> | string, formatters?: TranslationFormatters = {}): Promise<void>
initialize(
config?: Partial<AstroI18nConfig> | string,
formatters?: TranslationFormatters = {}
): Promise<void>;
/** Redirects the user to the given destination. */
redirect(destination: string | URL, status = 301)
redirect(destination: string | URL, status = 301);
}
export const astroI18n: AstroI18n
export const astroI18n: AstroI18n;
}
// ###< astro-i18n/type-generation ###

View file

@ -5,7 +5,6 @@
"pages.games": "Games | Alu",
"pages.settings": "Settings | Alu",
"nav.brand": "Alu",
"nav.games": "Games",
"nav.settings": "Settings",

View file

@ -1,9 +1,9 @@
import en from './en.json';
import jp from './jp.json';
import en from "./en.json";
import jp from "./jp.json";
export const defaultLang = 'en';
export const defaultLang = "en";
export const ui = {
en,
jp
jp,
};

View file

@ -1,14 +1,14 @@
import { ui, defaultLang } from './ui';
import { ui, defaultLang } from "./ui";
export function getLangFromUrl(url: URL) {
// comma lol
const [, lang] = url.pathname.split('/');
const [, lang] = url.pathname.split("/");
if (lang in ui) return lang as keyof typeof ui;
return defaultLang;
}
export function useTranslations(lang: keyof typeof ui) {
return function t(key: keyof typeof ui[typeof defaultLang]) {
return function t(key: keyof (typeof ui)[typeof defaultLang]) {
return ui[lang][key] || ui[defaultLang][key];
}
};
}

View file

@ -1,3 +1,6 @@
{
"extends": "astro/tsconfigs/strict"
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"verbatimModuleSyntax": false
}
}