@writedocs/generator 0.13.3 → 0.13.5
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/README.md +28 -28
- package/astro.config.mjs +645 -645
- package/bin/writedocs.js +43 -12
- package/package.json +99 -99
- package/src/cli/base-path-layout.js +44 -44
- package/src/cli/build-auth.js +135 -135
- package/src/cli/build.js +203 -203
- package/src/cli/check-built-styles.js +41 -41
- package/src/cli/convert.js +1 -1
- package/src/cli/dev.js +268 -268
- package/src/cli/exit-when-flushed.js +4 -0
- package/src/cli/generate-api-pages.js +507 -507
- package/src/cli/og-image-worker.js +20 -20
- package/src/cli/og-images.js +70 -70
- package/src/cli/page-list-watch.js +69 -69
- package/src/cli/run-astro.js +97 -97
- package/src/cli/run-pagefind.js +154 -154
- package/src/cli/write-mcp-files.js +103 -103
- package/src/cli/write-redirects-file.js +158 -158
- package/src/components/ApiReferencePanel.astro +1792 -1792
- package/src/components/AppIcon.astro +51 -51
- package/src/components/Card.astro +193 -193
- package/src/components/CodeGroup.astro +63 -39
- package/src/components/CopyPageMenu.astro +374 -374
- package/src/components/Hint.astro +188 -188
- package/src/components/Icon.astro +72 -72
- package/src/components/Image.astro +165 -165
- package/src/components/Tile.astro +67 -67
- package/src/components/Video.astro +137 -137
- package/src/content.config.ts +203 -203
- package/src/layout/BaseLayout.astro +908 -908
- package/src/layout/components/AnalyticsScripts.astro +49 -49
- package/src/layout/components/Breadcrumbs.astro +98 -98
- package/src/layout/components/ConsentBanner.astro +119 -119
- package/src/layout/components/MobileMenu.astro +225 -225
- package/src/layout/components/NavTree.astro +408 -408
- package/src/layout/components/Sidebar.astro +232 -232
- package/src/layout/components/SiteFooter.astro +87 -87
- package/src/layout/components/TopBar.astro +386 -386
- package/src/layout/styles/base.css +332 -326
- package/src/layout/styles/mobile-menu.css +285 -285
- package/src/lib/agent-markdown.js +164 -164
- package/src/lib/asset-dimensions.js +89 -89
- package/src/lib/base-path.js +90 -90
- package/src/lib/cli-report.js +22 -22
- package/src/lib/code-line-numbers.js +13 -0
- package/src/lib/config-schema.js +414 -75
- package/src/lib/config-schema.ts +2509 -1905
- package/src/lib/config.ts +1316 -1314
- package/src/lib/consent.js +108 -108
- package/src/lib/content-store-reload-integration.js +101 -101
- package/src/lib/icon-data-dev.js +53 -53
- package/src/lib/image-size.js +152 -152
- package/src/lib/json-schema-descriptions.js +228 -228
- package/src/lib/link-check.js +544 -544
- package/src/lib/llms-index.ts +90 -90
- package/src/lib/mcp-dev-integration.js +65 -65
- package/src/lib/mcp-index.ts +102 -102
- package/src/lib/mintlify-convert.js +605 -605
- package/src/lib/moved-api-pages.js +49 -49
- package/src/lib/og-cards.js +33 -33
- package/src/lib/og-image.js +235 -235
- package/src/lib/openapi-dev-status.js +80 -80
- package/src/lib/openapi-reload-integration.js +193 -193
- package/src/lib/pages.js +312 -312
- package/src/lib/project-files-integration.js +116 -116
- package/src/lib/project-files.js +137 -137
- package/src/lib/rehype-base-path.js +62 -62
- package/src/lib/rehype-image-loading.js +71 -71
- package/src/lib/robots-txt.js +21 -21
- package/src/lib/search-scope.js +44 -44
- package/src/lib/selector-placement.js +50 -50
- package/src/lib/seo-tags.js +155 -155
- package/src/lib/shiki-code-block.js +7 -1
- package/src/lib/site-base.ts +27 -27
- package/src/lib/styles-asset-integration.js +291 -291
- package/src/lib/wdignore-cases.json +195 -195
- package/src/lib/wdignore.js +177 -177
- package/src/pages/404.astro +63 -63
- package/src/pages/[...slug].astro +1762 -1608
- package/src/pages/[...slug].md.ts +93 -93
- package/src/pages/llms-full.txt.ts +88 -88
- package/src/pages/og/[...slug].png.ts +63 -63
- package/src/scripts/mobile-menu.ts +80 -80
- package/src/scripts/search.ts +245 -245
- package/src/scripts/sidebar-scroll.ts +61 -61
- package/src/styles/global.css +40 -40
package/bin/writedocs.js
CHANGED
|
@@ -10,6 +10,7 @@ import { runInit } from '../src/cli/init.js';
|
|
|
10
10
|
import { requireBuildKey } from '../src/cli/build-auth.js';
|
|
11
11
|
import { log, step, plural, color, CliExit, errorText, stopActiveStep } from '../src/cli/output.js';
|
|
12
12
|
import { startUpdateCheck, showUpdateNotice } from '../src/cli/update-check.js';
|
|
13
|
+
import { exitWhenFlushed } from '../src/cli/exit-when-flushed.js';
|
|
13
14
|
import { readConfigText } from '../src/lib/config-file.js';
|
|
14
15
|
import { canonicalPath } from '../src/lib/canonical-path.js';
|
|
15
16
|
// O MESMO modulo que o build usa (via loadDocsConfig, que reexporta daqui) e
|
|
@@ -29,7 +30,8 @@ import { canonicalPath } from '../src/lib/canonical-path.js';
|
|
|
29
30
|
import {
|
|
30
31
|
validateDocsConfig,
|
|
31
32
|
formatValidationIssuesDetailed,
|
|
32
|
-
|
|
33
|
+
unknownRootKeyWarnings,
|
|
34
|
+
VALIDATION_ISSUE_LIMIT,
|
|
33
35
|
} from '../src/lib/config-schema.js';
|
|
34
36
|
|
|
35
37
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -108,6 +110,7 @@ program
|
|
|
108
110
|
.description('Validate writedocs.json and every page - frontmatter, MDX, navigation, components, icons')
|
|
109
111
|
.argument('[dir]', 'content directory (contains writedocs.json)', '.')
|
|
110
112
|
.option('--config-only', 'check writedocs.json only, not the pages')
|
|
113
|
+
.option('--all', `list every problem in writedocs.json, not only the first ${VALIDATION_ISSUE_LIMIT}`)
|
|
111
114
|
.action(async (dir, options) => {
|
|
112
115
|
const contentDir = canonicalPath(path.resolve(process.cwd(), dir));
|
|
113
116
|
const configPath = path.join(contentDir, 'writedocs.json');
|
|
@@ -119,11 +122,17 @@ program
|
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
const rawText = readConfigText(contentDir);
|
|
122
|
-
|
|
125
|
+
// Sem `--all`, a validacao para depois de VALIDATION_ISSUE_LIMIT erros
|
|
126
|
+
// (WD-315): a lista traz os primeiros, e `issuesTruncated` diz que ha mais,
|
|
127
|
+
// sem saber quantos. `--all` valida tudo e lista tudo, como antes.
|
|
128
|
+
const all = Boolean(options.all);
|
|
129
|
+
const result = validateDocsConfig(rawText, { all });
|
|
123
130
|
// Chave desconhecida na raiz e AVISO, nunca erro: a raiz nao e `.strict()`
|
|
124
131
|
// de proposito (tornar strict quebraria configs existentes), entao o Zod
|
|
125
132
|
// descarta a chave em silencio. Sem JSON parseavel nao ha chave pra avaliar.
|
|
126
|
-
|
|
133
|
+
// Os avisos chegam com no maximo VALIDATION_ISSUE_LIMIT (todos, com `--all`),
|
|
134
|
+
// e o total deles e sempre exato.
|
|
135
|
+
const warnings = result.kind === 'invalid_json' ? { issues: [], issuesTotal: 0 } : unknownRootKeyWarnings(rawText, { all });
|
|
127
136
|
const nomeArquivo = path.basename(configPath);
|
|
128
137
|
|
|
129
138
|
if (!result.ok) {
|
|
@@ -133,17 +142,25 @@ program
|
|
|
133
142
|
log.error(
|
|
134
143
|
result.kind === 'invalid_json'
|
|
135
144
|
? `${nomeArquivo} is not valid JSON`
|
|
136
|
-
:
|
|
145
|
+
: result.issuesTruncated
|
|
146
|
+
? `More than ${VALIDATION_ISSUE_LIMIT} errors in ${nomeArquivo}`
|
|
147
|
+
: `${plural(result.issuesTotal, 'error')} in ${nomeArquivo}`
|
|
137
148
|
);
|
|
138
149
|
log.line();
|
|
139
|
-
log.line(
|
|
150
|
+
log.line(
|
|
151
|
+
formatValidationIssuesDetailed(result.issues, {
|
|
152
|
+
fileName: nomeArquivo,
|
|
153
|
+
total: result.issuesTotal,
|
|
154
|
+
truncated: result.issuesTruncated,
|
|
155
|
+
})
|
|
156
|
+
);
|
|
140
157
|
log.line();
|
|
141
158
|
}
|
|
142
159
|
|
|
143
|
-
if (warnings.
|
|
144
|
-
log.warn(`${plural(warnings.
|
|
160
|
+
if (warnings.issuesTotal > 0) {
|
|
161
|
+
log.warn(`${plural(warnings.issuesTotal, 'warning')} in ${nomeArquivo}`);
|
|
145
162
|
log.line();
|
|
146
|
-
log.line(formatValidationIssuesDetailed(warnings, { fileName: nomeArquivo }));
|
|
163
|
+
log.line(formatValidationIssuesDetailed(warnings.issues, { fileName: nomeArquivo, total: warnings.issuesTotal }));
|
|
147
164
|
log.line();
|
|
148
165
|
}
|
|
149
166
|
|
|
@@ -173,8 +190,12 @@ program
|
|
|
173
190
|
}
|
|
174
191
|
|
|
175
192
|
if (!result.ok || (content && content.errors.length > 0)) {
|
|
176
|
-
const
|
|
177
|
-
|
|
193
|
+
const nasPaginas = content ? content.errors.length : 0;
|
|
194
|
+
const total =
|
|
195
|
+
!result.ok && result.issuesTruncated
|
|
196
|
+
? `more than ${VALIDATION_ISSUE_LIMIT + nasPaginas} errors`
|
|
197
|
+
: plural((result.ok ? 0 : result.issuesTotal) + nasPaginas, 'error');
|
|
198
|
+
log.error(`Not valid: ${total} to fix - the build would fail on these.`);
|
|
178
199
|
throw new CliExit(1);
|
|
179
200
|
}
|
|
180
201
|
// Aviso nao invalida: um config so com avisos continua valido, e sai 0 -
|
|
@@ -313,13 +334,23 @@ program
|
|
|
313
334
|
(command ?? program).help();
|
|
314
335
|
});
|
|
315
336
|
|
|
337
|
+
// A command that succeeds ends on its own: Node keeps the process alive until
|
|
338
|
+
// what it wrote to a pipe has left. One that fails has to exit with its code,
|
|
339
|
+
// and process.exit() drops whatever a pipe hasn't taken yet - on Linux a pipe
|
|
340
|
+
// is asynchronous, and `writedocs validate` with 1,000 errors reached a CI log
|
|
341
|
+
// or the platform's build log with 1,198 of its 5,003 lines. exitWhenFlushed()
|
|
342
|
+
// waits for stdout and stderr first (10 s at most, for a reader that stopped
|
|
343
|
+
// reading). The exit codes are a contract with the platform: 0, 1, and 75
|
|
344
|
+
// from requireBuildKey() (src/cli/build-auth.js), which exits on its own after
|
|
345
|
+
// a few lines - they always fit in an empty pipe. Tested in
|
|
346
|
+
// scripts/cli-exit-flush.test.js.
|
|
316
347
|
program
|
|
317
348
|
.parseAsync(process.argv)
|
|
318
349
|
.then(showUpdateNotice)
|
|
319
|
-
.catch((err) => {
|
|
350
|
+
.catch(async (err) => {
|
|
320
351
|
stopActiveStep();
|
|
321
352
|
// A command that already printed its own error throws CliExit.
|
|
322
353
|
if (!(err instanceof CliExit)) log.error(errorText(err));
|
|
323
354
|
showUpdateNotice();
|
|
324
|
-
|
|
355
|
+
await exitWhenFlushed(err instanceof CliExit ? err.code : 1);
|
|
325
356
|
});
|
package/package.json
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@writedocs/generator",
|
|
3
|
-
"version": "0.13.
|
|
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
|
-
"rolldown": "1.2.14",
|
|
87
|
-
"satori": "0.44.0",
|
|
88
|
-
"shiki": "4.4.3",
|
|
89
|
-
"tailwindcss": "4.3.3",
|
|
90
|
-
"vite": "8.3.4",
|
|
91
|
-
"zod": "4.6.7"
|
|
92
|
-
},
|
|
93
|
-
"engines": {
|
|
94
|
-
"node": ">=22.12.0"
|
|
95
|
-
},
|
|
96
|
-
"devDependencies": {
|
|
97
|
-
"esbuild": "0.28.2"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@writedocs/generator",
|
|
3
|
+
"version": "0.13.5",
|
|
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
|
+
"rolldown": "1.2.14",
|
|
87
|
+
"satori": "0.44.0",
|
|
88
|
+
"shiki": "4.4.3",
|
|
89
|
+
"tailwindcss": "4.3.3",
|
|
90
|
+
"vite": "8.3.4",
|
|
91
|
+
"zod": "4.6.7"
|
|
92
|
+
},
|
|
93
|
+
"engines": {
|
|
94
|
+
"node": ">=22.12.0"
|
|
95
|
+
},
|
|
96
|
+
"devDependencies": {
|
|
97
|
+
"esbuild": "0.28.2"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
// Where a build puts the site in dist/ (build.js). Without a basePath, at
|
|
2
|
-
// dist/ itself, as always. With one ("/docs", writedocs.json - see
|
|
3
|
-
// lib/base-path.js), every file the site serves goes to dist/docs/: a static
|
|
4
|
-
// server that serves dist/ at its root answers /docs/... with no rule of its
|
|
5
|
-
// own, and a proxy that passes /docs/* on with its path unchanged finds every
|
|
6
|
-
// file where its address says.
|
|
7
|
-
//
|
|
8
|
-
// A few files aren't the site's but its host's, and the host reads them at
|
|
9
|
-
// the root of what it serves, so they stay in dist/:
|
|
10
|
-
// 404.html the page a host shows for an address it doesn't have
|
|
11
|
-
// (Cloudflare Pages, the WriteDocs platform look for it there);
|
|
12
|
-
// _redirects the host's redirects - every path in the generated rules
|
|
13
|
-
// carries the base (write-redirects-file.js);
|
|
14
|
-
// _headers the host's response headers, when the project has one;
|
|
15
|
-
// _worker.js, _routes.json, .assetsignore
|
|
16
|
-
// the Cloudflare MCP server (write-mcp-files.js), which
|
|
17
|
-
// Cloudflare only runs from the root.
|
|
18
|
-
import fs from 'node:fs';
|
|
19
|
-
import path from 'node:path';
|
|
20
|
-
|
|
21
|
-
/** The host's files - kept at the root of dist/, outside the basePath. */
|
|
22
|
-
export const ROOT_FILES = ['404.html', '_redirects', '_headers', '_worker.js', '_routes.json', '.assetsignore'];
|
|
23
|
-
|
|
24
|
-
/** The folder the site itself goes to: dist/ without a basePath,
|
|
25
|
-
* dist/docs/ for "/docs", dist/help/docs/ for "/help/docs". */
|
|
26
|
-
export function siteDirFor(distDir, basePath) {
|
|
27
|
-
const segments = (basePath ?? '').split('/').filter(Boolean);
|
|
28
|
-
return segments.length ? path.join(distDir, ...segments) : distDir;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Moves the host's files (ROOT_FILES) a build left in the site's folder up
|
|
32
|
-
* to the root of dist/. Nothing to do without a basePath. Returns the names
|
|
33
|
-
* moved. */
|
|
34
|
-
export function moveRootFiles(siteDir, distDir) {
|
|
35
|
-
if (path.resolve(siteDir) === path.resolve(distDir)) return [];
|
|
36
|
-
const moved = [];
|
|
37
|
-
for (const name of ROOT_FILES) {
|
|
38
|
-
const from = path.join(siteDir, name);
|
|
39
|
-
if (!fs.existsSync(from)) continue;
|
|
40
|
-
fs.renameSync(from, path.join(distDir, name));
|
|
41
|
-
moved.push(name);
|
|
42
|
-
}
|
|
43
|
-
return moved;
|
|
44
|
-
}
|
|
1
|
+
// Where a build puts the site in dist/ (build.js). Without a basePath, at
|
|
2
|
+
// dist/ itself, as always. With one ("/docs", writedocs.json - see
|
|
3
|
+
// lib/base-path.js), every file the site serves goes to dist/docs/: a static
|
|
4
|
+
// server that serves dist/ at its root answers /docs/... with no rule of its
|
|
5
|
+
// own, and a proxy that passes /docs/* on with its path unchanged finds every
|
|
6
|
+
// file where its address says.
|
|
7
|
+
//
|
|
8
|
+
// A few files aren't the site's but its host's, and the host reads them at
|
|
9
|
+
// the root of what it serves, so they stay in dist/:
|
|
10
|
+
// 404.html the page a host shows for an address it doesn't have
|
|
11
|
+
// (Cloudflare Pages, the WriteDocs platform look for it there);
|
|
12
|
+
// _redirects the host's redirects - every path in the generated rules
|
|
13
|
+
// carries the base (write-redirects-file.js);
|
|
14
|
+
// _headers the host's response headers, when the project has one;
|
|
15
|
+
// _worker.js, _routes.json, .assetsignore
|
|
16
|
+
// the Cloudflare MCP server (write-mcp-files.js), which
|
|
17
|
+
// Cloudflare only runs from the root.
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
|
|
21
|
+
/** The host's files - kept at the root of dist/, outside the basePath. */
|
|
22
|
+
export const ROOT_FILES = ['404.html', '_redirects', '_headers', '_worker.js', '_routes.json', '.assetsignore'];
|
|
23
|
+
|
|
24
|
+
/** The folder the site itself goes to: dist/ without a basePath,
|
|
25
|
+
* dist/docs/ for "/docs", dist/help/docs/ for "/help/docs". */
|
|
26
|
+
export function siteDirFor(distDir, basePath) {
|
|
27
|
+
const segments = (basePath ?? '').split('/').filter(Boolean);
|
|
28
|
+
return segments.length ? path.join(distDir, ...segments) : distDir;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Moves the host's files (ROOT_FILES) a build left in the site's folder up
|
|
32
|
+
* to the root of dist/. Nothing to do without a basePath. Returns the names
|
|
33
|
+
* moved. */
|
|
34
|
+
export function moveRootFiles(siteDir, distDir) {
|
|
35
|
+
if (path.resolve(siteDir) === path.resolve(distDir)) return [];
|
|
36
|
+
const moved = [];
|
|
37
|
+
for (const name of ROOT_FILES) {
|
|
38
|
+
const from = path.join(siteDir, name);
|
|
39
|
+
if (!fs.existsSync(from)) continue;
|
|
40
|
+
fs.renameSync(from, path.join(distDir, name));
|
|
41
|
+
moved.push(name);
|
|
42
|
+
}
|
|
43
|
+
return moved;
|
|
44
|
+
}
|