Page MenuHomeSealhub

No OneTemporary

Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
diff --git a/README.md b/README.md
index a25a895..c3c6dc6 100644
--- a/README.md
+++ b/README.md
@@ -1,44 +1,43 @@
# Sealious app
## Requirements
- docker
- docker-compose (version 2.6 or up)
+- tmux
## Installation
```
npm install
```
-Always use ./npm.sh when installing dependencies.
-
## Running the app in development mode
```
npx sealgen make-env
docker-compose up -d db mailcatcher
npm run watch
```
## Adding a component
```
npx sealgen add-component
```
And then go to `localhost:8080/components` to preview your custom component
## Testing
First time after installing the project run this command to download firefox
```
npx playwright install firefox
```
And then
```
-./npm.sh run test
+npm run test
```
diff --git a/nodemon.json b/nodemon.json
index 7748fd3..5c989ad 100644
--- a/nodemon.json
+++ b/nodemon.json
@@ -1,3 +1,3 @@
{
- "delay": "100"
+ "delay": "500"
}
diff --git a/src/back/html.ts b/src/back/html.ts
index 7aa383c..e931161 100644
--- a/src/back/html.ts
+++ b/src/back/html.ts
@@ -1,148 +1,192 @@
import { FlatTemplatable, Templatable, tempstream } from "tempstream";
import { Readable } from "stream";
import { BaseContext } from "koa";
import { default as default_navbar } from "./routes/common/navbar.js";
import { toKebabCase } from "js-convert-case";
export const defaultHead = (
ctx: BaseContext,
title: string,
options: HTMLOptions
) => /* HTML */ `<title>${title} · ${ctx.$app.manifest.name}</title>
<meta name="viewport" content="width=device-width" />
<script async src="/dist/bundle.js"></script>
<link
href="/dist/main.css${options.autoRefreshCSS
? `?${Math.random()}${Math.random()}`
: ""}"
rel="stylesheet"
type="text/css"
/>
${options.morphing ? `<meta name="turbo-refresh-method" content="morph" />` : ""}
${options.preserveScroll
? `<meta name="turbo-refresh-scroll" content="preserve">`
: ""}`;
export type HTMLOptions = {
preserveScroll?: boolean;
morphing?: boolean;
navbar?: (ctx: BaseContext) => FlatTemplatable;
autoRefreshCSS?: boolean;
};
export default function html(
ctx: BaseContext,
title: string,
body: Templatable,
htmlOptions: HTMLOptions = {},
makeHead: (
ctx: BaseContext,
title: string,
options: HTMLOptions
) => Templatable = defaultHead
): Readable {
ctx.set("content-type", "text/html;charset=utf-8");
return tempstream/* HTML */ ` <!DOCTYPE html>
<html lang="pl" class="title--${toKebabCase(title)}">
<head>
${makeHead(ctx, title, htmlOptions)}
</head>
<body>
${(htmlOptions.navbar || default_navbar)(ctx)} ${body}
${htmlOptions.autoRefreshCSS
? /* HTML */ `<script>
function make_new_link() {
const new_link = document.createElement("link");
new_link.rel = "stylesheet";
new_link.href = \`/dist/main.css?\${Math.random()}+\${Math.random()}\`;
new_link.type = "text/css";
return new_link;
}
function getStyles() {
return Array.from(
document.querySelectorAll("head link")
).filter(
(e) => new URL(e.href).pathname == "/dist/main.css"
);
}
function cleanup_css() {
console.log("clearing styles");
getStyles()
.slice(0, -1)
.forEach((style) => {
style.parentElement.removeChild(style);
});
}
document.documentElement.addEventListener(
"turbo:morph",
cleanup_css
);
const sleep = (time) =>
new Promise((resolve) => {
setTimeout(resolve, time);
});
- let last_known_start_timestamp = 0;
+ const APP_DOWN_ERROR_MESSAGE = "App is currently down";
+
+ function get_status() {
+ return fetch("/status.json").then((r) => r.json());
+ }
+
+ async function wait_for_run_id_to_change() {
+ let first_timestamp;
+ try {
+ const { started_at, status } = await get_status();
+ first_timestamp = started_at;
+ } catch (e) {
+ await wait_for_app_to_be_stable();
+ return;
+ }
+
+ if (!first_timestamp) {
+ throw new Error(APP_DOWN_ERROR_MESSAGE);
+ }
- async function wait_for_app_restart() {
while (true) {
- const { started_at, status } = await fetch(
- "/status.json"
- )
- .then((r) => r.json())
- .catch(() => ({
- started_at: last_known_start_timestamp,
+ const { started_at, status } =
+ await get_status().catch(() => ({
+ started_at: first_timestamp,
}));
- if (started_at !== last_known_start_timestamp) {
- last_known_start_timestamp = started_at;
+ if (started_at !== first_timestamp) {
return;
}
await sleep(100);
}
}
+ async function wait_for_app_to_be_stable(n = 3) {
+ console.log("Waiting for app to be stable....");
+ let counter = 0;
+ while (true) {
+ const { status } = await get_status().catch((e) => ({
+ status: "down",
+ }));
+ if (status == "running") {
+ console.log(counter);
+ counter++;
+ } else {
+ counter = 0;
+ }
+ if (counter == n) {
+ return;
+ }
+ await sleep(100);
+ }
+ }
+
+ async function wait_for_app_restart() {
+ try {
+ await wait_for_run_id_to_change();
+ } catch (e) {
+ if (e.message !== APP_DOWN_ERROR_MESSAGE) {
+ throw e;
+ }
+ }
+ await wait_for_app_to_be_stable();
+ }
+
(async function () {
const { started_at, status } = await fetch(
"/status.json"
).then((r) => r.json());
last_known_start_timestamp = started_at;
const { port, watch } = await fetch(
"/dist/notifier.json"
).then((r) => r.json());
if (!watch) {
console.warning(
"Not running auto refresh on watch because the build process is not running in watch mode"
);
return;
}
const socket = new WebSocket(\`ws://localhost:\${port}\`);
socket.onmessage = async (message) => {
if (message.data === "css") {
const new_link = make_new_link();
new_link.onload = cleanup_css;
document
.querySelector("head")
.appendChild(new_link);
}
if (message.data === "ts") {
document.documentElement.classList.add(
"restarting"
);
await wait_for_app_restart();
document.documentElement.dispatchEvent(
new Event("ts-rebuilt")
);
document.documentElement.classList.remove(
"restarting"
);
}
};
})();
</script>`
: ""}
</body>
</html>`;
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 28, 03:15 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1225841
Default Alt Text
(6 KB)

Event Timeline