mirror of
https://github.com/theoludwig/theoludwig.git
synced 2025-05-29 22:37:44 +02:00
chore: cleaner setup
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import "@repo/config-tailwind/styles.css"
|
||||
import "./storybook-css-overrides.css"
|
||||
import i18nMessages from "@repo/i18n/translations/en-US.json"
|
||||
import { LOCALE_DEFAULT, TIMEZONE } from "@repo/utils/constants"
|
||||
import type { Preview } from "@storybook/react"
|
||||
@ -7,6 +8,11 @@ import { ThemeProvider as NextThemeProvider } from "next-themes"
|
||||
import React from "react"
|
||||
|
||||
const preview: Preview = {
|
||||
globals: {
|
||||
a11y: {
|
||||
manual: true,
|
||||
},
|
||||
},
|
||||
parameters: {
|
||||
nextjs: {
|
||||
appDirectory: true,
|
||||
|
3
apps/storybook/.storybook/storybook-css-overrides.css
Normal file
3
apps/storybook/.storybook/storybook-css-overrides.css
Normal file
@ -0,0 +1,3 @@
|
||||
body {
|
||||
overflow: auto !important;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import typescriptESLint from "typescript-eslint"
|
||||
import config from "@repo/eslint-config"
|
||||
import config from "@repo/config-eslint"
|
||||
|
||||
export default typescriptESLint.config(...config, {
|
||||
files: ["**/*.ts", "**/*.tsx"],
|
||||
|
84
apps/storybook/http-server.ts
Normal file
84
apps/storybook/http-server.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import http from "node:http"
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import util from "node:util"
|
||||
import mime from "mime"
|
||||
|
||||
const MIMETYPE_DEFAULT = "application/octet-stream"
|
||||
|
||||
const args = util.parseArgs({
|
||||
options: {
|
||||
path: { type: "string", default: "public", required: true },
|
||||
port: { type: "string", default: "3000", required: true },
|
||||
host: { type: "string", default: "0.0.0.0" },
|
||||
},
|
||||
})
|
||||
|
||||
const host = args.values.host
|
||||
const basePath = args.values.path
|
||||
|
||||
const port = Number.parseInt(args.values.port, 10)
|
||||
if (Number.isNaN(port)) {
|
||||
console.error("Error: Invalid port number.")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const serverURL = `http://${host}:${port}`
|
||||
|
||||
const server = http.createServer(async (request, response) => {
|
||||
if (request.url == null) {
|
||||
response.writeHead(400, { "Content-Type": "text/plain" })
|
||||
response.end("Bad Request")
|
||||
return
|
||||
}
|
||||
const url = new URL(request.url, serverURL)
|
||||
const urlPath = url.pathname
|
||||
const filePath = path.join(process.cwd(), basePath, urlPath)
|
||||
try {
|
||||
const stat = await fs.promises.stat(filePath)
|
||||
if (stat.isDirectory()) {
|
||||
const indexFile = path.join(filePath, "index.html")
|
||||
try {
|
||||
const fileContent = await fs.promises.readFile(indexFile)
|
||||
response.writeHead(200, { "Content-Type": "text/html" })
|
||||
response.end(fileContent)
|
||||
} catch {
|
||||
response.writeHead(403, { "Content-Type": "text/plain" })
|
||||
response.end("Error: Directory listing not allowed.")
|
||||
}
|
||||
} else {
|
||||
const mimeType = mime.getType(filePath) ?? MIMETYPE_DEFAULT
|
||||
const fileContent = await fs.promises.readFile(filePath)
|
||||
response.writeHead(200, { "Content-Type": mimeType })
|
||||
response.end(fileContent)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
||||
response.writeHead(404, { "Content-Type": "text/plain" })
|
||||
response.end("Error: File not found.")
|
||||
} else {
|
||||
response.writeHead(500, { "Content-Type": "text/plain" })
|
||||
response.end("Error: Internal Server Error.")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const gracefulShutdown = (): void => {
|
||||
server.close()
|
||||
process.exit(0)
|
||||
}
|
||||
process.on("SIGTERM", gracefulShutdown)
|
||||
process.on("SIGINT", gracefulShutdown)
|
||||
|
||||
server.listen(
|
||||
{
|
||||
host,
|
||||
port,
|
||||
},
|
||||
() => {
|
||||
console.log(
|
||||
`HTTP Server is listening at ${util.styleText("cyan", serverURL)}`,
|
||||
)
|
||||
console.log(`Serving files from: \`${basePath}\``)
|
||||
},
|
||||
)
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "@repo/storybook",
|
||||
"version": "4.1.3",
|
||||
"version": "0.0.0-develop",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "storybook build",
|
||||
"dev": "storybook dev --port 6006 --no-open",
|
||||
"start": "http-server \"storybook-static\" --port 6006 --silent",
|
||||
"test": "start-server-and-test \"start\" http://127.0.0.1:6006 \"test:storybook\"",
|
||||
"test:dev": "start-server-and-test \"dev\" http://127.0.0.1:6006 \"test:storybook\"",
|
||||
"start": "node --experimental-strip-types http-server.ts --path=storybook-static --port=6006",
|
||||
"test": "start-server-and-test \"start\" http://localhost:6006 \"test:storybook\"",
|
||||
"test:dev": "start-server-and-test \"dev\" http://localhost:6006 \"test:storybook\"",
|
||||
"test:storybook": "test-storybook --testTimeout=60000 --maxWorkers=2",
|
||||
"chromatic": "chromatic"
|
||||
},
|
||||
@ -22,10 +22,11 @@
|
||||
"next-intl": "catalog:",
|
||||
"next-themes": "catalog:",
|
||||
"react": "catalog:",
|
||||
"react-dom": "catalog:"
|
||||
"react-dom": "catalog:",
|
||||
"mime": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@repo/eslint-config": "workspace:*",
|
||||
"@repo/config-eslint": "workspace:*",
|
||||
"@repo/config-typescript": "workspace:*",
|
||||
"@chromatic-com/storybook": "catalog:",
|
||||
"@playwright/test": "catalog:",
|
||||
@ -45,7 +46,6 @@
|
||||
"axe-playwright": "catalog:",
|
||||
"chromatic": "catalog:",
|
||||
"eslint": "catalog:",
|
||||
"http-server": "catalog:",
|
||||
"start-server-and-test": "catalog:",
|
||||
"storybook": "catalog:",
|
||||
"storybook-dark-mode": "catalog:",
|
||||
|
Reference in New Issue
Block a user