Skip to content

Commit 6bbff35

Browse files
committed
More updates
1 parent e69e64a commit 6bbff35

File tree

14 files changed

+394
-198
lines changed

14 files changed

+394
-198
lines changed

.github/workflows/site.yaml

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import fs from "node:fs/promises";
2+
import { fileExists, filesMustHaveContent, filesMustHaveShape } from "#common";
3+
import type { Issues } from "#types";
4+
import dedent from "dedent";
5+
6+
export const issues: Issues = async function* issues({ project }) {
7+
const content = `
8+
CompileFlags:
9+
Add: [-xc]\n`;
10+
11+
yield* filesMustHaveContent({ ".clangd": content });
12+
};

config/lint-rules/400-ecosystem/nodejs/eslint.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import detectIndent from 'detect-indent'
1414
export const issues: Issues = async function* issues({ project }) {
1515
// Check that there is only one configuration file.
1616
{
17-
const configContent = `export { default } from '@hyperupcall/scripts-nodejs/config-eslint.ts'\n`
17+
const configContent = `export { default } from '@hyperupcall/scripts-nodejs/config-eslint.js'\n`
1818

1919
// https://eslint.org/docs/latest/use/configure/configuration-files-deprecated
2020
// https://eslint.org/docs/latest/use/configure/configuration-files
@@ -45,6 +45,7 @@ export const issues: Issues = async function* issues({ project }) {
4545
'package.json': {
4646
scripts: {
4747
lint: 'hyperupcall-scripts-nodejs lint',
48+
'lint:fix': { __delete: null },
4849
},
4950
devDependencies: {
5051
'@hyperupcall/scripts-nodejs': `${version}`,

config/lint-rules/400-ecosystem/nodejs/prettier.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const issues: Issues = async function* issues({ project }) {
4444
'package.json': {
4545
scripts: {
4646
format: 'hyperupcall-scripts-nodejs format',
47+
'format:fix': { __delete: null },
4748
},
4849
devDependencies: {
4950
'@hyperupcall/scripts-nodejs': `${version}`,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { html } from "htm/preact";
2+
import path from "node:path";
3+
import { useEffect, useState } from "preact/hooks";
4+
import * as v from "valibot";
5+
import os from "node:os";
6+
import fs from "node:fs/promises";
7+
import type { Express } from "express";
8+
import type { WebSocketServer } from "ws";
9+
10+
export type PageSchemaT = v.InferInput<typeof PageSchema>;
11+
export const PageSchema = v.strictObject({
12+
fileList: v.array(
13+
v.strictObject({ path: v.string(), lastAccessed: v.string() }),
14+
),
15+
});
16+
17+
const cspellFiles = [
18+
path.join(os.homedir(), ".dotfiles/config/custom-words.txt"),
19+
];
20+
21+
export async function PageData(): Promise<PageSchemaT> {
22+
const list: PageSchemaT["fileList"] = [];
23+
for (const file of cspellFiles) {
24+
list.push({
25+
path: file,
26+
lastAccessed: (await fs.stat(file)).mtime.toTimeString(),
27+
});
28+
}
29+
30+
return {
31+
fileList: list,
32+
};
33+
}
34+
35+
export function Api(app: Express, wss: WebSocketServer) {
36+
wss.on("connection", (ws) => {
37+
ws.on("error", console.error);
38+
ws.on("message", function message(data) {
39+
console.log("received: %s", data);
40+
});
41+
42+
for (const dictFile of cspellFiles) {
43+
const signal = new AbortController().signal;
44+
(async () => {
45+
try {
46+
const watcher = fs.watch(dictFile, { persistent: false, signal });
47+
for await (const event of watcher) {
48+
ws.send(
49+
JSON.stringify({
50+
type: "dictionary-watcher-log",
51+
line: `Event "${event.eventType}" from file "${event.filename}"`,
52+
}),
53+
);
54+
}
55+
} catch (err) {
56+
if (err.name === "AbortError") {
57+
return;
58+
}
59+
throw err;
60+
}
61+
})();
62+
}
63+
64+
ws.send("something");
65+
});
66+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { html } from "htm/preact";
2+
import { useEffect, useState } from "preact/hooks";
3+
import type { PageSchemaT } from "./dictionary-watcher.server.ts";
4+
import { Fragment } from "preact";
5+
import { Navigation } from "#components/Navigation.ts";
6+
7+
let ws: WebSocket | null = null;
8+
if ("window" in globalThis) {
9+
ws = new WebSocket("http://localhost:3000/ws");
10+
ws.addEventListener("error", console.error);
11+
ws.addEventListener("open", () => {
12+
console.info(`Opening WebSocket`);
13+
});
14+
}
15+
16+
export function Page(a: PageSchemaT) {
17+
const [log, setLog] = useState("");
18+
19+
useEffect(() => {
20+
if (!ws) {
21+
console.info("no ws");
22+
return;
23+
}
24+
25+
const listener = (str: MessageEvent) => {
26+
console.info("ev", str);
27+
28+
let obj;
29+
try {
30+
obj = JSON.parse(str.data);
31+
} catch {}
32+
33+
if (obj?.type === "dictionary-watcher-log") {
34+
console.log("Appending to dictionary log", obj.line);
35+
setLog(log + obj.line + "\n");
36+
}
37+
};
38+
ws.addEventListener("message", listener);
39+
40+
return () => ws.removeEventListener("message", listener);
41+
}, []);
42+
43+
return html`
44+
<${Fragment}>
45+
<${Navigation} />
46+
<h1 class="mb-0 title">Dictionary Watcher</h1>
47+
<p class="mb-0">This tool watches and sync various dictionary files</p>
48+
<hr class="my-2" />
49+
<div class="content">
50+
<p>The following dictionary files are processed:</p>
51+
<ul>
52+
<li>
53+
<p>
54+
<b>cspell:</b> at
55+
<code>cat ~/.dotfiles/config/custom-words.txt</code>
56+
</p>
57+
</li>
58+
<li>
59+
<p>
60+
<b>LibreOffice:</b> at
61+
<!-- TODO: space -->
62+
<code>~/.config/libreoffice/4/user/wordbook/standard.dic</code>
63+
</p>
64+
</li>
65+
</ul>
66+
</div>
67+
<h2>Watching these files:</h2>
68+
${a.fileList.map((item) => {
69+
return html`<p class="subtitle">${item.path}</p>`;
70+
})}
71+
<h2>Log</h2>
72+
<pre>
73+
${log}
74+
</pre
75+
>
76+
<//>
77+
`;
78+
}

devserver/server.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
import express from 'express'
2-
import { renderPage } from './webframework.ts'
3-
import * as v from 'valibot'
4-
5-
import { Api as repositoriesApi } from './pages/projects.server.ts'
6-
import { Api as servicesApi } from './pages/services.server.ts'
7-
import { Api as repositoriesSettingsApi } from './pages/projects/settings.server.ts'
8-
import { Api as editProjectQueriesApi } from './pages/projects/edit-queries.server.ts'
9-
10-
await import('#utilities/db.ts')
11-
12-
export function createApp() {
13-
const app = express()
14-
app.use(express.json())
15-
app.use((req, _res, next) => {
16-
console.info(req.method + ' ' + req.url)
17-
next()
18-
})
19-
app.get('/', renderPage)
20-
app.get('/lint', renderPage)
21-
22-
app.get('/services', renderPage)
23-
servicesApi(app)
24-
25-
app.get('/projects', renderPage)
26-
repositoriesApi(app)
27-
28-
app.get('/projects/settings', renderPage)
29-
repositoriesSettingsApi(app)
30-
31-
app.get('/projects/edit-queries', renderPage)
32-
editProjectQueriesApi(app)
33-
34-
return app
1+
import express from "express";
2+
import { renderPage } from "./webframework.ts";
3+
import type { Express } from "express";
4+
import { WebSocketServer } from "ws";
5+
6+
import { Api as repositoriesApi } from "./pages/projects.server.ts";
7+
import { Api as servicesApi } from "./pages/services.server.ts";
8+
import { Api as repositoriesSettingsApi } from "./pages/projects/settings.server.ts";
9+
import { Api as editProjectQueriesApi } from "./pages/projects/edit-queries.server.ts";
10+
import { Api as dictionaryWatcherApi } from "./pages/tools/dictionary-watcher.server.ts";
11+
12+
await import("#utilities/db.ts");
13+
14+
export function createApp(app: Express, wss: WebSocketServer) {
15+
app.use(express.json());
16+
app.use((req, _res, next) => {
17+
console.info(req.method + " " + req.url);
18+
next();
19+
});
20+
app.get("/", renderPage);
21+
app.get("/lint", renderPage);
22+
23+
app.get("/services", renderPage);
24+
servicesApi(app);
25+
26+
app.get("/projects", renderPage);
27+
repositoriesApi(app);
28+
29+
app.get("/tools/dictionary-watcher", renderPage);
30+
dictionaryWatcherApi(app, wss);
31+
32+
app.get("/projects/settings", renderPage);
33+
repositoriesSettingsApi(app);
34+
35+
app.get("/projects/edit-queries", renderPage);
36+
editProjectQueriesApi(app);
3537
}

0 commit comments

Comments
 (0)