@takazudo/zudo-doc-history-server 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,6 +49,7 @@ function parseCommonArgs(args, extra) {
49
49
  let contentDir = "";
50
50
  const locales = [];
51
51
  let maxEntries = 50;
52
+ const exclude = [];
52
53
  for (let i = 0; i < args.length; i++) {
53
54
  const flag = args[i];
54
55
  if (flag === void 0) continue;
@@ -60,6 +61,9 @@ function parseCommonArgs(args, extra) {
60
61
  case "--locale":
61
62
  locales.push(parseLocaleArg(next()));
62
63
  break;
64
+ case "--exclude":
65
+ exclude.push(next());
66
+ break;
63
67
  case "--max-entries": {
64
68
  const raw = next();
65
69
  const n = Number(raw);
@@ -84,7 +88,7 @@ function parseCommonArgs(args, extra) {
84
88
  console.error("Missing required --content-dir option");
85
89
  process.exit(1);
86
90
  }
87
- return { contentDir, locales, maxEntries };
91
+ return { contentDir, locales, maxEntries, exclude };
88
92
  }
89
93
  function isLoopback(host) {
90
94
  return host === "127.0.0.1" || host === "::1" || host === "localhost";
@@ -0,0 +1,38 @@
1
+ // src/exclude.ts
2
+ function compileExclude(patterns) {
3
+ const matchers = patterns.map((pattern) => {
4
+ let source = "";
5
+ for (let i = 0; i < pattern.length; i++) {
6
+ const char = pattern[i];
7
+ if (char === "/" && pattern.slice(i + 1) === "**") {
8
+ source += "(?:/.*)?";
9
+ break;
10
+ }
11
+ if (pattern.slice(i, i + 3) === "**/") {
12
+ source += "(?:[^/]+/)*";
13
+ i += 2;
14
+ continue;
15
+ }
16
+ if (pattern.slice(i, i + 2) === "**") {
17
+ source += ".*";
18
+ i++;
19
+ continue;
20
+ }
21
+ if (char === "*") {
22
+ source += "[^/]*";
23
+ continue;
24
+ }
25
+ if (char === "?") {
26
+ source += "[^/]";
27
+ continue;
28
+ }
29
+ source += char?.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
30
+ }
31
+ return new RegExp(`^${source}$`);
32
+ });
33
+ return (slug) => matchers.some((matcher) => matcher.test(slug));
34
+ }
35
+
36
+ export {
37
+ compileExclude
38
+ };
package/dist/cli.js CHANGED
@@ -6,7 +6,10 @@ import {
6
6
  import {
7
7
  getContentDirEntries,
8
8
  parseCliArgs
9
- } from "./chunk-Y26SYCW7.js";
9
+ } from "./chunk-J3U2PADO.js";
10
+ import {
11
+ compileExclude
12
+ } from "./chunk-OLBD4MJQ.js";
10
13
  import {
11
14
  collectContentFiles,
12
15
  getDocHistoryAsync
@@ -16,8 +19,9 @@ import {
16
19
  import { mkdirSync, writeFileSync } from "fs";
17
20
  import { dirname, join } from "path";
18
21
  async function generate(options2) {
19
- const { contentDir, locales, outDir, maxEntries } = options2;
22
+ const { contentDir, locales, outDir, maxEntries, exclude } = options2;
20
23
  const startTime = performance.now();
24
+ const isExcluded = compileExclude(exclude);
21
25
  const dirEntries = getContentDirEntries(contentDir, locales);
22
26
  mkdirSync(outDir, { recursive: true });
23
27
  let totalFiles = 0;
@@ -26,7 +30,7 @@ async function generate(options2) {
26
30
  const acquire = makeSemaphore(concurrency);
27
31
  const tasks = [];
28
32
  for (const [localeKey, dir] of dirEntries) {
29
- const files = collectContentFiles(dir);
33
+ const files = collectContentFiles(dir).filter(({ slug }) => !isExcluded(slug));
30
34
  const label = localeKey ?? "default";
31
35
  console.log(`Processing ${label}: ${files.length} files in ${dir}`);
32
36
  for (const { filePath, slug } of files) {
@@ -0,0 +1,4 @@
1
+ /** Compile doc-history exclude globs into a reusable slug predicate. */
2
+ declare function compileExclude(patterns: string[]): (slug: string) => boolean;
3
+
4
+ export { compileExclude };
@@ -0,0 +1,6 @@
1
+ import {
2
+ compileExclude
3
+ } from "./chunk-OLBD4MJQ.js";
4
+ export {
5
+ compileExclude
6
+ };
package/dist/index.js CHANGED
@@ -2,7 +2,10 @@
2
2
  import {
3
3
  getContentDirEntries,
4
4
  parseServerArgs
5
- } from "./chunk-Y26SYCW7.js";
5
+ } from "./chunk-J3U2PADO.js";
6
+ import {
7
+ compileExclude
8
+ } from "./chunk-OLBD4MJQ.js";
6
9
  import {
7
10
  collectContentFiles,
8
11
  getDocHistoryAsync
@@ -38,11 +41,12 @@ function sendJson(res, status, data, origin) {
38
41
  res.writeHead(status, { "Content-Type": "application/json" });
39
42
  res.end(JSON.stringify(data));
40
43
  }
41
- function buildFileIndex(dirEntries) {
44
+ function buildFileIndex(dirEntries, isExcluded) {
42
45
  const index = /* @__PURE__ */ new Map();
43
46
  for (const [localeKey, contentDir] of dirEntries) {
44
47
  const files = collectContentFiles(contentDir);
45
48
  for (const file of files) {
49
+ if (isExcluded(file.slug)) continue;
46
50
  const prefixedSlug = localeKey ? `${localeKey}/${file.slug}` : file.slug;
47
51
  index.set(prefixedSlug, file);
48
52
  }
@@ -59,16 +63,17 @@ async function handleDocHistory(requestedSlug, fileIndex, maxEntries, res, origi
59
63
  sendJson(res, 404, { error: `No doc found for slug: ${requestedSlug}` }, origin);
60
64
  }
61
65
  function startServer(options2) {
62
- const { port, host, contentDir, locales, maxEntries } = options2;
66
+ const { port, host, contentDir, locales, maxEntries, exclude } = options2;
63
67
  const dirEntries = getContentDirEntries(contentDir, locales);
64
- let fileIndex = buildFileIndex(dirEntries);
68
+ const isExcluded = compileExclude(exclude);
69
+ let fileIndex = buildFileIndex(dirEntries, isExcluded);
65
70
  console.log(`Indexed ${fileIndex.size} documents`);
66
71
  let lastMtime = getContentDirsMtime(dirEntries);
67
72
  const refreshTimer = setInterval(() => {
68
73
  try {
69
74
  const currentMtime = getContentDirsMtime(dirEntries);
70
75
  if (currentMtime === lastMtime) return;
71
- fileIndex = buildFileIndex(dirEntries);
76
+ fileIndex = buildFileIndex(dirEntries, isExcluded);
72
77
  lastMtime = currentMtime;
73
78
  } catch {
74
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takazudo/zudo-doc-history-server",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "type": "module",
5
5
  "description": "Standalone doc git-history service for zudo-doc — HTTP server + CLI batch generator. Decouples expensive `git log --follow` calls from the main build pipeline.",
6
6
  "license": "MIT",
@@ -45,6 +45,10 @@
45
45
  "types": "./dist/concurrency.d.ts",
46
46
  "default": "./dist/concurrency.js"
47
47
  },
48
+ "./exclude": {
49
+ "types": "./dist/exclude.d.ts",
50
+ "default": "./dist/exclude.js"
51
+ },
48
52
  "./package.json": "./package.json"
49
53
  },
50
54
  "files": [
@@ -59,7 +63,7 @@
59
63
  "vitest": "^4.1.0"
60
64
  },
61
65
  "scripts": {
62
- "build": "tsup src/index.ts src/cli.ts src/git-history.ts src/types.ts src/concurrency.ts --format esm --dts",
66
+ "build": "tsup src/index.ts src/cli.ts src/git-history.ts src/types.ts src/concurrency.ts src/exclude.ts --format esm --dts",
63
67
  "dev": "tsx src/index.ts",
64
68
  "generate": "tsx src/cli.ts",
65
69
  "test": "vitest run",