Skip to content

Commit 83b3b83

Browse files
committed
chore: refine file watching
1 parent 6fcdd76 commit 83b3b83

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

dist/cli.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25011,6 +25011,8 @@ send.bind(null, 'PATCH');
2501125011
send.bind(null, 'DELETE');
2501225012
send.bind(null, 'PUT');
2501325013

25014+
console.log(`Starting docs preview server.\n`);
25015+
2501425016
const cache = {};
2501525017

2501625018
async function cli() {
@@ -25033,30 +25035,35 @@ async function cli() {
2503325035
);
2503425036

2503525037
const pkg_watch = new CheapWatch({
25036-
dir: path.join(process.cwd(), pkg),
25037-
debounce: 40,
25038-
});
25039-
const doc_watch = new CheapWatch({
25040-
dir: path.join(process.cwd(), docs),
25038+
dir: path.join(process.cwd()),
2504125039
debounce: 40,
25040+
filter: ({ path }) => {
25041+
return path.startsWith(pkg) || path.startsWith(docs);
25042+
},
2504225043
});
25044+
// const doc_watch = new CheapWatch({
25045+
// dir: path.join(process.cwd(), docs),
25046+
// debounce: 40,
25047+
// });
2504325048

2504425049
await pkg_watch.init();
25045-
await doc_watch.init();
25046-
let cons = 0;
25050+
// await doc_watch.init();
25051+
// let cons = 0;
2504725052
pkg_watch.on("+", ({ path, stats, isNew }) => {
25053+
console.log("change detected", path);
2504825054
if (!/.*\.\w+/.test(path)) return;
25055+
console.log("passed regex");
2504925056

2505025057
process_docs(project, pkg, docs, (data) => (ready_for_cf = data));
2505125058
});
2505225059

25053-
doc_watch.on("+", ({ path, stats, isNew }) => {
25054-
if (!/.*\.\w+/.test(path)) return;
25055-
console.log("docs", path);
25056-
console.time(`docs${cons}`);
25057-
process_docs(project, pkg, docs, (data) => (ready_for_cf = data));
25058-
console.timeEnd(`docs${cons++}`);
25059-
});
25060+
// doc_watch.on("+", ({ path, stats, isNew }) => {
25061+
// if (!/.*\.\w+/.test(path)) return;
25062+
// console.log("docs", path);
25063+
// console.time(`docs${cons}`);
25064+
// process_docs(project, pkg, docs, (data: CF_Key[]) => (ready_for_cf = data));
25065+
// console.timeEnd(`docs${cons++}`);
25066+
// });
2506025067

2506125068

2506225069

@@ -25073,8 +25080,6 @@ async function cli() {
2507325080

2507425081

2507525082

25076-
console.log(ready_for_cf);
25077-
2507825083
polka()
2507925084
.get("/docs/:project/:type", async (req, res) => {
2508025085
setCors(res);
@@ -25157,7 +25162,7 @@ async function process_docs(
2515725162
try {
2515825163
_docs = await get_docs(project, pkg, docs);
2515925164
} catch (e) {
25160-
console.log(e);
25165+
console.error(e);
2516125166
throw new Error("no docs");
2516225167
}
2516325168

src/cli.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { get_docs, DocFiles } from "./fs";
1010
import { transform_cloudflare, transform_docs } from "./transform";
1111
import { get } from "httpie";
1212

13+
console.log(`Starting docs preview server.\n`);
14+
1315
const cache: Record<string, CF_Key> = {};
1416

1517
export default async function cli() {
@@ -32,30 +34,35 @@ export default async function cli() {
3234
);
3335

3436
const pkg_watch = new CheapWatch({
35-
dir: path.join(process.cwd(), pkg),
36-
debounce: 40,
37-
});
38-
const doc_watch = new CheapWatch({
39-
dir: path.join(process.cwd(), docs),
37+
dir: path.join(process.cwd()),
4038
debounce: 40,
39+
filter: ({ path }: { path: string }) => {
40+
return path.startsWith(pkg) || path.startsWith(docs);
41+
},
4142
});
43+
// const doc_watch = new CheapWatch({
44+
// dir: path.join(process.cwd(), docs),
45+
// debounce: 40,
46+
// });
4247

4348
await pkg_watch.init();
44-
await doc_watch.init();
45-
let cons = 0;
49+
// await doc_watch.init();
50+
// let cons = 0;
4651
pkg_watch.on("+", ({ path, stats, isNew }) => {
52+
console.log("change detected", path);
4753
if (!/.*\.\w+/.test(path)) return;
54+
console.log("passed regex");
4855

4956
process_docs(project, pkg, docs, (data: CF_Key[]) => (ready_for_cf = data));
5057
});
5158

52-
doc_watch.on("+", ({ path, stats, isNew }) => {
53-
if (!/.*\.\w+/.test(path)) return;
54-
console.log("docs", path);
55-
console.time(`docs${cons}`);
56-
process_docs(project, pkg, docs, (data: CF_Key[]) => (ready_for_cf = data));
57-
console.timeEnd(`docs${cons++}`);
58-
});
59+
// doc_watch.on("+", ({ path, stats, isNew }) => {
60+
// if (!/.*\.\w+/.test(path)) return;
61+
// console.log("docs", path);
62+
// console.time(`docs${cons}`);
63+
// process_docs(project, pkg, docs, (data: CF_Key[]) => (ready_for_cf = data));
64+
// console.timeEnd(`docs${cons++}`);
65+
// });
5966

6067
type RequestDocs = Request & {
6168
params: { project: string; type: string };
@@ -72,8 +79,6 @@ export default async function cli() {
7279
};
7380
};
7481

75-
console.log(ready_for_cf);
76-
7782
polka()
7883
.get("/docs/:project/:type", async (req: RequestDocs, res: Response) => {
7984
setCors(res);
@@ -156,7 +161,7 @@ async function process_docs(
156161
try {
157162
_docs = await get_docs(project, pkg, docs);
158163
} catch (e) {
159-
console.log(e);
164+
console.error(e);
160165
throw new Error("no docs");
161166
}
162167

0 commit comments

Comments
 (0)