@writedocs/generator 0.10.19 → 0.10.20

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.
package/package.json CHANGED
@@ -1,94 +1,97 @@
1
- {
2
- "name": "@writedocs/generator",
3
- "version": "0.10.19",
4
- "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
- "type": "module",
6
- "bin": {
7
- "writedocs": "./bin/writedocs.js"
8
- },
9
- "exports": {
10
- "./components": "./src/components/index.ts",
11
- "./config-schema": "./src/lib/config-schema.js",
12
- "./writedocs.schema.json": "./writedocs.schema.json",
13
- "./mcp": "./src/mcp/server.js"
14
- },
15
- "files": [
16
- "bin",
17
- "src",
18
- "astro.config.mjs",
19
- "writedocs.schema.json"
20
- ],
21
- "scripts": {
22
- "dev": "node bin/writedocs.js dev",
23
- "build": "node bin/writedocs.js build",
24
- "init": "node bin/writedocs.js init",
25
- "build:schema": "esbuild src/lib/config-schema.ts --format=esm --target=node22 --outfile=src/lib/config-schema.js",
26
- "prepare": "npm run build:schema && npm run build:json-schema",
27
- "test": "node --test \"scripts/*.test.js\"",
28
- "build:json-schema": "node scripts/build-json-schema.mjs"
29
- },
30
- "keywords": [
31
- "docs",
32
- "documentation",
33
- "static-site-generator",
34
- "mdx",
35
- "astro"
36
- ],
37
- "homepage": "https://github.com/writedocs/writedocs#readme",
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/writedocs/writedocs.git"
41
- },
42
- "bugs": {
43
- "url": "https://github.com/writedocs/writedocs/issues"
44
- },
45
- "author": "Gabriel Raeder Gonçalves",
46
- "license": "ISC",
47
- "publishConfig": {
48
- "access": "public"
49
- },
50
- "dependencies": {
51
- "@apidevtools/swagger-parser": "12.1.0",
52
- "@astrojs/markdown-remark": "7.2.4",
53
- "@astrojs/mdx": "7.0.8",
54
- "@astrojs/react": "6.0.2",
55
- "@astrojs/sitemap": "3.7.3",
56
- "@iconify-json/bi": "1.2.7",
57
- "@iconify-json/fa6-brands": "1.2.6",
58
- "@iconify-json/fa6-solid": "1.2.4",
59
- "@iconify-json/heroicons": "1.2.3",
60
- "@iconify-json/ion": "1.2.7",
61
- "@iconify-json/lucide": "1.2.123",
62
- "@iconify-json/mdi": "1.2.3",
63
- "@iconify-json/ri": "1.2.10",
64
- "@iconify-json/simple-icons": "1.2.93",
65
- "@iconify-json/tabler": "1.2.38",
66
- "@mdx-js/mdx": "3.1.1",
67
- "@resvg/resvg-wasm": "2.6.2",
68
- "@shikijs/transformers": "4.4.3",
69
- "@tailwindcss/vite": "4.3.3",
70
- "astro": "7.2.9",
71
- "astro-icon": "1.1.5",
72
- "commander": "15.0.0",
73
- "dotenv": "17.4.2",
74
- "gray-matter": "4.0.3",
75
- "jsonc-parser": "3.3.1",
76
- "katex": "0.16.47",
77
- "mermaid": "11.16.1",
78
- "pagefind": "1.5.2",
79
- "react": "19.2.8",
80
- "react-dom": "19.2.8",
81
- "rehype-katex": "7.0.1",
82
- "remark-math": "6.0.0",
83
- "satori": "0.44.0",
84
- "shiki": "4.4.3",
85
- "tailwindcss": "4.3.3",
86
- "zod": "4.4.3"
87
- },
88
- "engines": {
89
- "node": ">=22.12.0"
90
- },
91
- "devDependencies": {
92
- "esbuild": "0.28.2"
93
- }
1
+ {
2
+ "name": "@writedocs/generator",
3
+ "version": "0.10.20",
4
+ "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
+ "type": "module",
6
+ "bin": {
7
+ "writedocs": "./bin/writedocs.js"
8
+ },
9
+ "exports": {
10
+ "./components": "./src/components/index.ts",
11
+ "./config-schema": "./src/lib/config-schema.js",
12
+ "./writedocs.schema.json": "./writedocs.schema.json",
13
+ "./mcp": "./src/mcp/server.js",
14
+ "./wdignore": "./src/lib/wdignore.js",
15
+ "./wdignore-cases.json": "./src/lib/wdignore-cases.json"
16
+ },
17
+ "files": [
18
+ "bin",
19
+ "src",
20
+ "astro.config.mjs",
21
+ "writedocs.schema.json"
22
+ ],
23
+ "scripts": {
24
+ "dev": "node bin/writedocs.js dev",
25
+ "build": "node bin/writedocs.js build",
26
+ "init": "node bin/writedocs.js init",
27
+ "build:schema": "esbuild src/lib/config-schema.ts --format=esm --target=node22 --outfile=src/lib/config-schema.js",
28
+ "prepare": "npm run build:schema && npm run build:json-schema",
29
+ "test": "node --test \"scripts/*.test.js\"",
30
+ "build:json-schema": "node scripts/build-json-schema.mjs"
31
+ },
32
+ "keywords": [
33
+ "docs",
34
+ "documentation",
35
+ "static-site-generator",
36
+ "mdx",
37
+ "astro"
38
+ ],
39
+ "homepage": "https://github.com/writedocs/writedocs#readme",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/writedocs/writedocs.git"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/writedocs/writedocs/issues"
46
+ },
47
+ "author": "Gabriel Raeder Gonçalves",
48
+ "license": "ISC",
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "dependencies": {
53
+ "@apidevtools/swagger-parser": "12.1.0",
54
+ "@astrojs/markdown-remark": "7.2.4",
55
+ "@astrojs/mdx": "7.0.8",
56
+ "@astrojs/react": "6.0.2",
57
+ "@astrojs/sitemap": "3.7.3",
58
+ "@iconify-json/bi": "1.2.7",
59
+ "@iconify-json/fa6-brands": "1.2.6",
60
+ "@iconify-json/fa6-solid": "1.2.4",
61
+ "@iconify-json/heroicons": "1.2.3",
62
+ "@iconify-json/ion": "1.2.7",
63
+ "@iconify-json/lucide": "1.2.123",
64
+ "@iconify-json/mdi": "1.2.3",
65
+ "@iconify-json/ri": "1.2.10",
66
+ "@iconify-json/simple-icons": "1.2.93",
67
+ "@iconify-json/tabler": "1.2.38",
68
+ "@mdx-js/mdx": "3.1.1",
69
+ "@resvg/resvg-wasm": "2.6.2",
70
+ "@shikijs/transformers": "4.4.3",
71
+ "@tailwindcss/vite": "4.3.3",
72
+ "astro": "7.2.9",
73
+ "astro-icon": "1.1.5",
74
+ "commander": "15.0.0",
75
+ "dotenv": "17.4.2",
76
+ "gray-matter": "4.0.3",
77
+ "ignore": "7.0.5",
78
+ "jsonc-parser": "3.3.1",
79
+ "katex": "0.16.47",
80
+ "mermaid": "11.16.1",
81
+ "pagefind": "1.5.2",
82
+ "react": "19.2.8",
83
+ "react-dom": "19.2.8",
84
+ "rehype-katex": "7.0.1",
85
+ "remark-math": "6.0.0",
86
+ "satori": "0.44.0",
87
+ "shiki": "4.4.3",
88
+ "tailwindcss": "4.3.3",
89
+ "zod": "4.4.3"
90
+ },
91
+ "engines": {
92
+ "node": ">=22.12.0"
93
+ },
94
+ "devDependencies": {
95
+ "esbuild": "0.28.2"
96
+ }
94
97
  }
@@ -5,6 +5,7 @@ import matter from 'gray-matter';
5
5
  import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
6
6
  import { parseOpenApiRef, openApiOperationKey, specDirName } from '../lib/openapi-ref.js';
7
7
  import { findAllPages } from '../lib/pages.js';
8
+ import { projectIgnore } from '../lib/project-ignore.js';
8
9
  import { readConfigText } from '../lib/config-file.js';
9
10
  import { HTTP_METHODS, collectOpenApiGroups } from '../lib/openapi-spec.js';
10
11
  import { operationMetaDescription } from '../lib/meta-description.js';
@@ -93,8 +94,10 @@ const OVERRIDE_SCAN_EXCLUDED_DIRS = new Set(['node_modules', 'dist', '.astro', '
93
94
  * id ("docs/webhooks/index") the rest of the routing pipeline would
94
95
  * never actually resolve, since the page's real id is "docs/webhooks") -
95
96
  * into `overrides`, skipping OVERRIDE_SCAN_EXCLUDED_DIRS at the content
96
- * root's own top level. */
97
- function scanDirForOverrides(dir, relBase, overrides) {
97
+ * root's own top level and whatever `rules` - the project's ignore rules,
98
+ * lib/wdignore.js - leave out: such a file isn't a page (findAllPages()
99
+ * skips it too), so it can't stand in for a generated one. */
100
+ function scanDirForOverrides(dir, relBase, overrides, rules) {
98
101
  let entries;
99
102
  try {
100
103
  entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -106,10 +109,11 @@ function scanDirForOverrides(dir, relBase, overrides) {
106
109
  const rel = relBase ? `${relBase}/${entry.name}` : entry.name;
107
110
  if (entry.isDirectory()) {
108
111
  if (relBase === '' && OVERRIDE_SCAN_EXCLUDED_DIRS.has(entry.name)) continue;
109
- scanDirForOverrides(full, rel, overrides);
112
+ if (rules.ignores(rel, true)) continue;
113
+ scanDirForOverrides(full, rel, overrides, rules);
110
114
  continue;
111
115
  }
112
- if (!/\.mdx?$/i.test(entry.name)) continue;
116
+ if (!/\.mdx?$/i.test(entry.name) || rules.ignores(rel)) continue;
113
117
  const raw = fs.readFileSync(full, 'utf-8');
114
118
  let data;
115
119
  try {
@@ -140,7 +144,7 @@ function scanDirForOverrides(dir, relBase, overrides) {
140
144
  * lives. */
141
145
  function findHandWrittenOverrides(contentDir) {
142
146
  const overrides = new Map(); // operationKey -> file id
143
- scanDirForOverrides(contentDir, '', overrides);
147
+ scanDirForOverrides(contentDir, '', overrides, projectIgnore(contentDir));
144
148
  return overrides;
145
149
  }
146
150
 
@@ -1,66 +1,69 @@
1
- // `writedocs dev`: noticing pages added or removed. The preview's list of page
2
- // files is read once, when it starts (content.config.ts hands findAllPages()'s
3
- // list to Astro) - an edit to a page shows up at once, but a new page stays
4
- // "not found" and a deleted one keeps being served. So this watches the
5
- // content folder, and when the list findAllPages() gives changes, calls
6
- // `onChange` - cli/dev.js restarts the preview then.
7
- //
8
- // It compares the list itself, not file events: a Markdown file that isn't
9
- // a page (no frontmatter, not in the navigation), an edit to a page, or a
10
- // save that writes a file twice doesn't restart anything.
11
- import fs from 'node:fs';
12
- import { findAllPages, EXCLUDED_TOP_LEVEL_DIRS } from '../lib/pages.js';
13
-
14
- /** Wait this long after the last file event before checking - a rename, a
15
- * copy of several files or an editor's save arrive as a burst of events. */
16
- export const SETTLE_MS = 400;
17
-
18
- /** Whether a changed file can change the page list: a .md/.mdx file, or
19
- * writedocs.json (it lists pages that have no frontmatter), outside the
20
- * folders findAllPages() never looks in. */
21
- export function mayChangePages(relative) {
22
- if (!relative) return true;
23
- const parts = String(relative).split(/[\\/]/);
24
- if (EXCLUDED_TOP_LEVEL_DIRS.has(parts[0]) || parts.some((part) => part.startsWith('.'))) return false;
25
- const name = parts[parts.length - 1];
26
- return /\.mdx?$/i.test(name) || name === 'writedocs.json';
27
- }
28
-
29
- /** Starts watching; returns `{ close }`. `onChange({ added, removed })` gets
30
- * the page files (relative paths) that came and went. */
31
- export function watchPageList(contentDir, onChange, { settleMs = SETTLE_MS } = {}) {
32
- let current = new Set(findAllPages(contentDir));
33
- let timer = null;
34
- const check = () => {
35
- let next;
36
- try {
37
- next = new Set(findAllPages(contentDir));
38
- } catch {
39
- return; // mid-save, or a folder being moved - the next event checks again
40
- }
41
- const added = [...next].filter((file) => !current.has(file));
42
- const removed = [...current].filter((file) => !next.has(file));
43
- if (!added.length && !removed.length) return;
44
- current = next;
45
- onChange({ added, removed });
46
- };
47
- let watcher;
48
- try {
49
- watcher = fs.watch(contentDir, { recursive: true }, (_event, filename) => {
50
- if (!mayChangePages(filename)) return;
51
- clearTimeout(timer);
52
- timer = setTimeout(check, settleMs);
53
- });
54
- watcher.on('error', () => {});
55
- } catch {
56
- // A file system without recursive watching: pages added while `dev`
57
- // runs need a restart, as before.
58
- return { close() {} };
59
- }
60
- return {
61
- close() {
62
- clearTimeout(timer);
63
- watcher.close();
64
- },
65
- };
66
- }
1
+ // `writedocs dev`: noticing pages added or removed. The preview's list of page
2
+ // files is read once, when it starts (content.config.ts hands findAllPages()'s
3
+ // list to Astro) - an edit to a page shows up at once, but a new page stays
4
+ // "not found" and a deleted one keeps being served. So this watches the
5
+ // content folder, and when the list findAllPages() gives changes, calls
6
+ // `onChange` - cli/dev.js restarts the preview then.
7
+ //
8
+ // It compares the list itself, not file events: a Markdown file that isn't
9
+ // a page (no frontmatter, not in the navigation), an edit to a page, or a
10
+ // save that writes a file twice doesn't restart anything.
11
+ import fs from 'node:fs';
12
+ import { findAllPages, EXCLUDED_TOP_LEVEL_DIRS } from '../lib/pages.js';
13
+ import { WDIGNORE_FILE } from '../lib/wdignore.js';
14
+
15
+ /** Wait this long after the last file event before checking - a rename, a
16
+ * copy of several files or an editor's save arrive as a burst of events. */
17
+ export const SETTLE_MS = 400;
18
+
19
+ /** Whether a changed file can change the page list: a .md/.mdx file, or
20
+ * writedocs.json (it lists pages that have no frontmatter), outside the
21
+ * folders findAllPages() never looks in - or the project's `.wdignore`,
22
+ * which says which files aren't pages. */
23
+ export function mayChangePages(relative) {
24
+ if (!relative) return true;
25
+ const parts = String(relative).split(/[\\/]/);
26
+ if (parts.length === 1 && parts[0] === WDIGNORE_FILE) return true;
27
+ if (EXCLUDED_TOP_LEVEL_DIRS.has(parts[0]) || parts.some((part) => part.startsWith('.'))) return false;
28
+ const name = parts[parts.length - 1];
29
+ return /\.mdx?$/i.test(name) || name === 'writedocs.json';
30
+ }
31
+
32
+ /** Starts watching; returns `{ close }`. `onChange({ added, removed })` gets
33
+ * the page files (relative paths) that came and went. */
34
+ export function watchPageList(contentDir, onChange, { settleMs = SETTLE_MS } = {}) {
35
+ let current = new Set(findAllPages(contentDir));
36
+ let timer = null;
37
+ const check = () => {
38
+ let next;
39
+ try {
40
+ next = new Set(findAllPages(contentDir));
41
+ } catch {
42
+ return; // mid-save, or a folder being moved - the next event checks again
43
+ }
44
+ const added = [...next].filter((file) => !current.has(file));
45
+ const removed = [...current].filter((file) => !next.has(file));
46
+ if (!added.length && !removed.length) return;
47
+ current = next;
48
+ onChange({ added, removed });
49
+ };
50
+ let watcher;
51
+ try {
52
+ watcher = fs.watch(contentDir, { recursive: true }, (_event, filename) => {
53
+ if (!mayChangePages(filename)) return;
54
+ clearTimeout(timer);
55
+ timer = setTimeout(check, settleMs);
56
+ });
57
+ watcher.on('error', () => {});
58
+ } catch {
59
+ // A file system without recursive watching: pages added while `dev`
60
+ // runs need a restart, as before.
61
+ return { close() {} };
62
+ }
63
+ return {
64
+ close() {
65
+ clearTimeout(timer);
66
+ watcher.close();
67
+ },
68
+ };
69
+ }