@writedocs/generator 0.10.20 → 0.11.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.
Files changed (52) hide show
  1. package/astro.config.mjs +32 -8
  2. package/package.json +1 -1
  3. package/src/cli/base-path-layout.js +44 -0
  4. package/src/cli/build.js +177 -168
  5. package/src/cli/check-built-styles.js +41 -33
  6. package/src/cli/dev.js +261 -244
  7. package/src/cli/run-pagefind.js +154 -148
  8. package/src/cli/write-mcp-files.js +103 -96
  9. package/src/cli/write-redirects-file.js +25 -8
  10. package/src/components/AppIcon.astro +51 -50
  11. package/src/components/Card.astro +193 -192
  12. package/src/components/CopyPageMenu.astro +374 -370
  13. package/src/components/Hint.astro +188 -187
  14. package/src/components/Icon.astro +72 -71
  15. package/src/components/Image.astro +3 -2
  16. package/src/components/Tile.astro +67 -66
  17. package/src/components/Video.astro +137 -136
  18. package/src/layout/BaseLayout.astro +21 -12
  19. package/src/layout/components/AnalyticsScripts.astro +6 -2
  20. package/src/layout/components/Breadcrumbs.astro +98 -97
  21. package/src/layout/components/ConsentBanner.astro +119 -118
  22. package/src/layout/components/MobileMenu.astro +229 -228
  23. package/src/layout/components/NavTree.astro +393 -392
  24. package/src/layout/components/Sidebar.astro +232 -231
  25. package/src/layout/components/SiteFooter.astro +87 -86
  26. package/src/layout/components/TopBar.astro +386 -385
  27. package/src/lib/agent-markdown.js +164 -162
  28. package/src/lib/asset-dimensions.js +89 -89
  29. package/src/lib/base-path.js +90 -0
  30. package/src/lib/config-schema.js +10 -0
  31. package/src/lib/config-schema.ts +17 -0
  32. package/src/lib/config.ts +1314 -1289
  33. package/src/lib/consent.js +108 -102
  34. package/src/lib/json-schema-descriptions.js +1 -0
  35. package/src/lib/link-check.js +7 -2
  36. package/src/lib/llms-index.ts +90 -88
  37. package/src/lib/mcp-dev-integration.js +65 -60
  38. package/src/lib/mcp-index.ts +102 -101
  39. package/src/lib/project-files-integration.js +2 -2
  40. package/src/lib/rehype-base-path.js +62 -0
  41. package/src/lib/robots-txt.js +21 -16
  42. package/src/lib/seo-tags.js +155 -140
  43. package/src/lib/site-base.ts +27 -0
  44. package/src/lib/styles-asset-integration.js +23 -10
  45. package/src/lib/wdignore-cases.json +195 -195
  46. package/src/lib/wdignore.js +177 -177
  47. package/src/pages/404.astro +63 -62
  48. package/src/pages/[...slug].astro +1604 -1597
  49. package/src/pages/[...slug].md.ts +93 -93
  50. package/src/pages/llms-full.txt.ts +88 -86
  51. package/src/scripts/search.ts +241 -237
  52. package/writedocs.schema.json +6 -0
package/src/cli/dev.js CHANGED
@@ -1,244 +1,261 @@
1
- import { canonicalPath } from '../lib/canonical-path.js';
2
- import { runAstro } from './run-astro.js';
3
- import { preflightCheck, sameDriveCheck, writableInstallCheck } from './preflight.js';
4
- import { generateApiPages } from './generate-api-pages.js';
5
- import { log, step, duration, formatProblems, color, CliExit } from './output.js';
6
- import { describeError, requestLog, authorWarning, verboseLine, stripAnsi } from './astro-output.js';
7
- import { reportApiPages } from './api-pages-output.js';
8
- import { runningPreview, writeLock, removeLock } from './dev-lock.js';
9
- import { showUpdateNotice } from './update-check.js';
10
- import { shouldOpenBrowser, openBrowser } from './open-browser.js';
11
- import { watchPageList } from './page-list-watch.js';
12
-
13
- // The same problem tends to arrive more than once in a row - Vite and
14
- // Astro each log a failed page, and a page compiles for more than one
15
- // environment. Within this window, a repeat is dropped.
16
- const REPEAT_WINDOW_MS = 2000;
17
-
18
- export async function runDev({ contentDir, packageRoot, port, verbose = false, open = true }) {
19
- // One spelling of each folder throughout - see lib/canonical-path.js.
20
- contentDir = canonicalPath(contentDir);
21
- packageRoot = canonicalPath(packageRoot);
22
- const started = Date.now();
23
- preflightCheck(contentDir);
24
- writableInstallCheck(packageRoot);
25
- const other = runningPreview(packageRoot);
26
- if (other) {
27
- log.error(`Another writedocs preview is already running${other.url ? ` at ${other.url}` : ''}.`);
28
- log.detail(
29
- color.dim(
30
- `It's serving ${other.contentDir}. Stop it first (Ctrl+C in its terminal) - two previews at once overwrite each other's pages.`
31
- )
32
- );
33
- throw new CliExit(1);
34
- }
35
- writeLock(packageRoot, { contentDir, url: null });
36
- process.on('exit', () => removeLock(packageRoot));
37
-
38
- const api = await generateApiPages({ contentDir });
39
- sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
40
- reportApiPages(api);
41
- api.warnings.forEach((message) => log.warn(message));
42
-
43
- let starting = step('Starting local preview');
44
- let ready = false;
45
- let browserOpened = false;
46
- // Restarting after pages were added or removed (see the watcher below):
47
- // when that restart began, and the port to come back on.
48
- let restartStarted = null;
49
- let currentPort = port;
50
-
51
- const lastShown = new Map();
52
- const once = (key, print) => {
53
- const now = Date.now();
54
- if (now - (lastShown.get(key) ?? 0) < REPEAT_WINDOW_MS) return;
55
- lastShown.set(key, now);
56
- print();
57
- };
58
- const oneLine = (where, message) => (where ? `${color.bold(where)} ${message}` : message);
59
-
60
- // A failed page is logged twice - Vite's error (message only) and then
61
- // Astro's (message plus the file). Errors wait a moment so the two can
62
- // be merged into one line that names the file.
63
- // When the same page fails again, only the first report of it named the
64
- // file: later ones point at the MDX compiler instead. The file each
65
- // error was last seen in is remembered here, by the error itself.
66
- const pendingErrors = new Map();
67
- const knownWhere = new Map();
68
- const showError = (problem) => {
69
- if (problem.where) knownWhere.set(problem.key, problem.where);
70
- else if (knownWhere.has(problem.key)) problem = { ...problem, where: knownWhere.get(problem.key) };
71
- const existing = pendingErrors.get(problem.message);
72
- if (existing) {
73
- if (!existing.problem.where && problem.where) existing.problem = problem;
74
- return;
75
- }
76
- const entry = { problem };
77
- entry.timer = setTimeout(() => {
78
- pendingErrors.delete(problem.message);
79
- const { where, message, hint } = entry.problem;
80
- once(`error\n${where}\n${message}`, () => {
81
- log.error(oneLine(where, message));
82
- if (hint) log.detail(color.dim(`Hint: ${hint}`));
83
- });
84
- }, 150);
85
- pendingErrors.set(problem.message, entry);
86
- };
87
-
88
- let fatal = null;
89
- const rawTail = [];
90
- const onEvent = (event) => {
91
- if (verbose) {
92
- const line = verboseLine(event);
93
- if (line !== null) log.line(color.dim(line));
94
- }
95
- switch (event.type) {
96
- case 'ready': {
97
- ready = true;
98
- const [local] = event.urls?.local ?? [];
99
- writeLock(packageRoot, { contentDir, url: local ?? null });
100
- const wanted = Number(port ?? 4321);
101
- const actual = local ? Number(new URL(local).port) : wanted;
102
- currentPort = actual;
103
- // Pages changed while it was starting: restart now that it's up.
104
- if (restartPending) {
105
- const change = restartPending;
106
- restartPending = false;
107
- setTimeout(() => restartForPages(change), 0);
108
- }
109
- // Back after a restart: one line - the open tab reloads by itself.
110
- if (restartStarted !== null) {
111
- starting.succeed(`Preview updated ${color.dim(`in ${duration(Date.now() - restartStarted)}`)}`);
112
- restartStarted = null;
113
- return;
114
- }
115
- starting.succeed(`Preview ready ${color.dim(`in ${duration(Date.now() - started)}`)}`);
116
- log.line();
117
- log.line(` ${color.bold('Local:')} ${color.cyan(local ?? `http://localhost:${wanted}/`)}`);
118
- if (actual !== wanted) log.line(color.dim(` Port ${wanted} was in use, so the preview is on ${actual}.`));
119
- log.line();
120
- log.line(color.dim(' Edit any page and the preview updates. Press Ctrl+C to stop.'));
121
- log.line();
122
- // `dev` runs until Ctrl+C - the notice goes under the ready screen,
123
- // not after the command like everywhere else.
124
- showUpdateNotice();
125
- // The preview in the browser, at the address it actually got - once,
126
- // not again if Astro restarts the server.
127
- if (!browserOpened && shouldOpenBrowser({ open })) {
128
- browserOpened = true;
129
- openBrowser(local ?? `http://localhost:${wanted}/`);
130
- }
131
- return;
132
- }
133
- case 'fatal':
134
- fatal = event.error;
135
- return;
136
- case 'report':
137
- // 'info' notes are about the build (sitemap and the like), not
138
- // the preview.
139
- if (event.level === 'warn') once(`warn\n${event.where}\n${event.message}`, () => log.warn(oneLine(event.where, event.message)));
140
- return;
141
- case 'raw':
142
- rawTail.push(event.line);
143
- if (rawTail.length > 40) rawTail.shift();
144
- return;
145
- case 'astro-log': {
146
- // A page file just deleted: Astro's list of page modules
147
- // (.astro/content-modules.mjs) still points at it for a moment -
148
- // "Failed to load url ... Does the file exist?" - until the restart
149
- // the page-list watcher starts brings in a fresh list. Noise, not a
150
- // problem in the site. Every other error still shows, and a
151
- // preview that can't start still reports through 'fatal'.
152
- if (event.level === 'error' && /content-modules\.mjs/.test(event.message) && /Does the file exist/.test(event.message)) return;
153
- if (restartStarted !== null && event.level === 'error') return;
154
- if (event.level === 'error') {
155
- showError(describeError(stripAnsi(event.message), contentDir, { root: packageRoot }));
156
- return;
157
- }
158
- const request = requestLog(event);
159
- // A missing page is worth knowing about (a broken link, a typo in
160
- // the navigation); a missing favicon or source map isn't.
161
- if (request?.status === 404 && !/\.[a-z0-9]+$/i.test(request.url.split('?')[0])) {
162
- once(`404\n${request.url}`, () => log.warn(`${color.bold(request.url)} No page at this address (404).`));
163
- return;
164
- }
165
- const warning = authorWarning(event, contentDir);
166
- if (warning) once(`warn\n${warning}`, () => log.warn(warning));
167
- return;
168
- }
169
- }
170
- };
171
-
172
- // Pages added or removed while the preview runs: its page list is read
173
- // when it starts, so it restarts - on the same port; the open tab
174
- // reconnects and reloads by itself. Edits to pages and to writedocs.json
175
- // don't need this (lib/config-reload-integration.js).
176
- let child = null;
177
- let restarting = false;
178
- let restartPending = false;
179
- const restartForPages = ({ added, removed }) => {
180
- const what = [
181
- ...added.slice(0, 3).map((file) => `${file} added`),
182
- ...removed.slice(0, 3).map((file) => `${file} removed`),
183
- ];
184
- const more = added.length + removed.length - what.length;
185
- log.info(`${what.join(', ')}${more > 0 ? ` and ${more} more` : ''} - restarting the preview so the page list is current.`);
186
- restarting = true;
187
- ready = false;
188
- restartStarted = Date.now();
189
- starting = step('Restarting the preview');
190
- child?.kill();
191
- };
192
- const pageWatch = watchPageList(contentDir, (change) => {
193
- if (stopping || restarting) return;
194
- // Still starting: restart once it's up, not halfway.
195
- if (!ready) {
196
- restartPending = change;
197
- return;
198
- }
199
- restartForPages(change);
200
- });
201
-
202
- // Ctrl+C: stop the server quietly. (The child gets the same signal from
203
- // the terminal; killing it here covers the cases where it doesn't.) A
204
- // second Ctrl+C doesn't wait for it.
205
- let stopping = false;
206
- const stop = () => {
207
- if (stopping) process.exit(130);
208
- stopping = true;
209
- pageWatch.close();
210
- child?.kill();
211
- };
212
- process.on('SIGINT', stop);
213
- process.on('SIGTERM', stop);
214
-
215
- let code;
216
- for (;;) {
217
- fatal = null;
218
- rawTail.length = 0;
219
- const run = runAstro('dev', { packageRoot, contentDir, port: currentPort, onEvent });
220
- child = run.child;
221
- code = await run.exited;
222
- if (stopping || !restarting) break;
223
- restarting = false;
224
- }
225
- pageWatch.close();
226
- if (stopping) {
227
- if (ready) log.line(color.dim('Preview stopped.'));
228
- return;
229
- }
230
- // The server never stops on its own - getting here is a failure.
231
- if (!ready) starting.fail('Could not start the local preview');
232
- else log.error('The local preview stopped unexpectedly.');
233
- if (fatal) {
234
- const problem = describeError(fatal, contentDir, { root: packageRoot });
235
- log.line();
236
- log.line(formatProblems([{ where: problem.where, message: problem.message }]));
237
- if (problem.hint) log.line(`\n${color.dim(` Hint: ${problem.hint}`)}`);
238
- if (verbose && fatal.stack) log.line(`\n${color.dim(fatal.stack)}`);
239
- } else if (rawTail.length) {
240
- log.line();
241
- log.line(color.dim(rawTail.join('\n')));
242
- }
243
- throw new CliExit(code || 1);
244
- }
1
+ import { canonicalPath } from '../lib/canonical-path.js';
2
+ import { runAstro } from './run-astro.js';
3
+ import { preflightCheck, sameDriveCheck, writableInstallCheck } from './preflight.js';
4
+ import { generateApiPages } from './generate-api-pages.js';
5
+ import { log, step, duration, formatProblems, color, CliExit } from './output.js';
6
+ import { describeError, requestLog, authorWarning, verboseLine, stripAnsi } from './astro-output.js';
7
+ import { reportApiPages } from './api-pages-output.js';
8
+ import { runningPreview, writeLock, removeLock } from './dev-lock.js';
9
+ import { showUpdateNotice } from './update-check.js';
10
+ import { shouldOpenBrowser, openBrowser } from './open-browser.js';
11
+ import { watchPageList } from './page-list-watch.js';
12
+ import { readConfigText } from '../lib/config-file.js';
13
+ import { normalizeBasePath } from '../lib/base-path.js';
14
+
15
+ /** The preview's address for the server's own (`http://localhost:4321/`):
16
+ * under writedocs.json's `basePath` when it has one - the site is served
17
+ * at /docs/ then, and / is Astro's "not here" page. Read when the server
18
+ * is ready, so it follows the file. */
19
+ export function previewAddress(serverUrl, configText) {
20
+ let basePath = '';
21
+ try {
22
+ basePath = normalizeBasePath(JSON.parse(configText).basePath);
23
+ } catch {
24
+ // An unreadable writedocs.json stops the preview elsewhere.
25
+ }
26
+ return basePath ? new URL(`${basePath.slice(1)}/`, serverUrl).href : serverUrl;
27
+ }
28
+
29
+ // The same problem tends to arrive more than once in a row - Vite and
30
+ // Astro each log a failed page, and a page compiles for more than one
31
+ // environment. Within this window, a repeat is dropped.
32
+ const REPEAT_WINDOW_MS = 2000;
33
+
34
+ export async function runDev({ contentDir, packageRoot, port, verbose = false, open = true }) {
35
+ // One spelling of each folder throughout - see lib/canonical-path.js.
36
+ contentDir = canonicalPath(contentDir);
37
+ packageRoot = canonicalPath(packageRoot);
38
+ const started = Date.now();
39
+ preflightCheck(contentDir);
40
+ writableInstallCheck(packageRoot);
41
+ const other = runningPreview(packageRoot);
42
+ if (other) {
43
+ log.error(`Another writedocs preview is already running${other.url ? ` at ${other.url}` : ''}.`);
44
+ log.detail(
45
+ color.dim(
46
+ `It's serving ${other.contentDir}. Stop it first (Ctrl+C in its terminal) - two previews at once overwrite each other's pages.`
47
+ )
48
+ );
49
+ throw new CliExit(1);
50
+ }
51
+ writeLock(packageRoot, { contentDir, url: null });
52
+ process.on('exit', () => removeLock(packageRoot));
53
+
54
+ const api = await generateApiPages({ contentDir });
55
+ sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
56
+ reportApiPages(api);
57
+ api.warnings.forEach((message) => log.warn(message));
58
+
59
+ let starting = step('Starting local preview');
60
+ let ready = false;
61
+ let browserOpened = false;
62
+ // Restarting after pages were added or removed (see the watcher below):
63
+ // when that restart began, and the port to come back on.
64
+ let restartStarted = null;
65
+ let currentPort = port;
66
+
67
+ const lastShown = new Map();
68
+ const once = (key, print) => {
69
+ const now = Date.now();
70
+ if (now - (lastShown.get(key) ?? 0) < REPEAT_WINDOW_MS) return;
71
+ lastShown.set(key, now);
72
+ print();
73
+ };
74
+ const oneLine = (where, message) => (where ? `${color.bold(where)} ${message}` : message);
75
+
76
+ // A failed page is logged twice - Vite's error (message only) and then
77
+ // Astro's (message plus the file). Errors wait a moment so the two can
78
+ // be merged into one line that names the file.
79
+ // When the same page fails again, only the first report of it named the
80
+ // file: later ones point at the MDX compiler instead. The file each
81
+ // error was last seen in is remembered here, by the error itself.
82
+ const pendingErrors = new Map();
83
+ const knownWhere = new Map();
84
+ const showError = (problem) => {
85
+ if (problem.where) knownWhere.set(problem.key, problem.where);
86
+ else if (knownWhere.has(problem.key)) problem = { ...problem, where: knownWhere.get(problem.key) };
87
+ const existing = pendingErrors.get(problem.message);
88
+ if (existing) {
89
+ if (!existing.problem.where && problem.where) existing.problem = problem;
90
+ return;
91
+ }
92
+ const entry = { problem };
93
+ entry.timer = setTimeout(() => {
94
+ pendingErrors.delete(problem.message);
95
+ const { where, message, hint } = entry.problem;
96
+ once(`error\n${where}\n${message}`, () => {
97
+ log.error(oneLine(where, message));
98
+ if (hint) log.detail(color.dim(`Hint: ${hint}`));
99
+ });
100
+ }, 150);
101
+ pendingErrors.set(problem.message, entry);
102
+ };
103
+
104
+ let fatal = null;
105
+ const rawTail = [];
106
+ const onEvent = (event) => {
107
+ if (verbose) {
108
+ const line = verboseLine(event);
109
+ if (line !== null) log.line(color.dim(line));
110
+ }
111
+ switch (event.type) {
112
+ case 'ready': {
113
+ ready = true;
114
+ const [local] = event.urls?.local ?? [];
115
+ const wanted = Number(port ?? 4321);
116
+ const actual = local ? Number(new URL(local).port) : wanted;
117
+ const address = previewAddress(local ?? `http://localhost:${wanted}/`, readConfigText(contentDir));
118
+ writeLock(packageRoot, { contentDir, url: address });
119
+ currentPort = actual;
120
+ // Pages changed while it was starting: restart now that it's up.
121
+ if (restartPending) {
122
+ const change = restartPending;
123
+ restartPending = false;
124
+ setTimeout(() => restartForPages(change), 0);
125
+ }
126
+ // Back after a restart: one line - the open tab reloads by itself.
127
+ if (restartStarted !== null) {
128
+ starting.succeed(`Preview updated ${color.dim(`in ${duration(Date.now() - restartStarted)}`)}`);
129
+ restartStarted = null;
130
+ return;
131
+ }
132
+ starting.succeed(`Preview ready ${color.dim(`in ${duration(Date.now() - started)}`)}`);
133
+ log.line();
134
+ log.line(` ${color.bold('Local:')} ${color.cyan(address)}`);
135
+ if (actual !== wanted) log.line(color.dim(` Port ${wanted} was in use, so the preview is on ${actual}.`));
136
+ log.line();
137
+ log.line(color.dim(' Edit any page and the preview updates. Press Ctrl+C to stop.'));
138
+ log.line();
139
+ // `dev` runs until Ctrl+C - the notice goes under the ready screen,
140
+ // not after the command like everywhere else.
141
+ showUpdateNotice();
142
+ // The preview in the browser, at the address it actually got - once,
143
+ // not again if Astro restarts the server.
144
+ if (!browserOpened && shouldOpenBrowser({ open })) {
145
+ browserOpened = true;
146
+ openBrowser(address);
147
+ }
148
+ return;
149
+ }
150
+ case 'fatal':
151
+ fatal = event.error;
152
+ return;
153
+ case 'report':
154
+ // 'info' notes are about the build (sitemap and the like), not
155
+ // the preview.
156
+ if (event.level === 'warn') once(`warn\n${event.where}\n${event.message}`, () => log.warn(oneLine(event.where, event.message)));
157
+ return;
158
+ case 'raw':
159
+ rawTail.push(event.line);
160
+ if (rawTail.length > 40) rawTail.shift();
161
+ return;
162
+ case 'astro-log': {
163
+ // A page file just deleted: Astro's list of page modules
164
+ // (.astro/content-modules.mjs) still points at it for a moment -
165
+ // "Failed to load url ... Does the file exist?" - until the restart
166
+ // the page-list watcher starts brings in a fresh list. Noise, not a
167
+ // problem in the site. Every other error still shows, and a
168
+ // preview that can't start still reports through 'fatal'.
169
+ if (event.level === 'error' && /content-modules\.mjs/.test(event.message) && /Does the file exist/.test(event.message)) return;
170
+ if (restartStarted !== null && event.level === 'error') return;
171
+ if (event.level === 'error') {
172
+ showError(describeError(stripAnsi(event.message), contentDir, { root: packageRoot }));
173
+ return;
174
+ }
175
+ const request = requestLog(event);
176
+ // A missing page is worth knowing about (a broken link, a typo in
177
+ // the navigation); a missing favicon or source map isn't.
178
+ if (request?.status === 404 && !/\.[a-z0-9]+$/i.test(request.url.split('?')[0])) {
179
+ once(`404\n${request.url}`, () => log.warn(`${color.bold(request.url)} No page at this address (404).`));
180
+ return;
181
+ }
182
+ const warning = authorWarning(event, contentDir);
183
+ if (warning) once(`warn\n${warning}`, () => log.warn(warning));
184
+ return;
185
+ }
186
+ }
187
+ };
188
+
189
+ // Pages added or removed while the preview runs: its page list is read
190
+ // when it starts, so it restarts - on the same port; the open tab
191
+ // reconnects and reloads by itself. Edits to pages and to writedocs.json
192
+ // don't need this (lib/config-reload-integration.js).
193
+ let child = null;
194
+ let restarting = false;
195
+ let restartPending = false;
196
+ const restartForPages = ({ added, removed }) => {
197
+ const what = [
198
+ ...added.slice(0, 3).map((file) => `${file} added`),
199
+ ...removed.slice(0, 3).map((file) => `${file} removed`),
200
+ ];
201
+ const more = added.length + removed.length - what.length;
202
+ log.info(`${what.join(', ')}${more > 0 ? ` and ${more} more` : ''} - restarting the preview so the page list is current.`);
203
+ restarting = true;
204
+ ready = false;
205
+ restartStarted = Date.now();
206
+ starting = step('Restarting the preview');
207
+ child?.kill();
208
+ };
209
+ const pageWatch = watchPageList(contentDir, (change) => {
210
+ if (stopping || restarting) return;
211
+ // Still starting: restart once it's up, not halfway.
212
+ if (!ready) {
213
+ restartPending = change;
214
+ return;
215
+ }
216
+ restartForPages(change);
217
+ });
218
+
219
+ // Ctrl+C: stop the server quietly. (The child gets the same signal from
220
+ // the terminal; killing it here covers the cases where it doesn't.) A
221
+ // second Ctrl+C doesn't wait for it.
222
+ let stopping = false;
223
+ const stop = () => {
224
+ if (stopping) process.exit(130);
225
+ stopping = true;
226
+ pageWatch.close();
227
+ child?.kill();
228
+ };
229
+ process.on('SIGINT', stop);
230
+ process.on('SIGTERM', stop);
231
+
232
+ let code;
233
+ for (;;) {
234
+ fatal = null;
235
+ rawTail.length = 0;
236
+ const run = runAstro('dev', { packageRoot, contentDir, port: currentPort, onEvent });
237
+ child = run.child;
238
+ code = await run.exited;
239
+ if (stopping || !restarting) break;
240
+ restarting = false;
241
+ }
242
+ pageWatch.close();
243
+ if (stopping) {
244
+ if (ready) log.line(color.dim('Preview stopped.'));
245
+ return;
246
+ }
247
+ // The server never stops on its own - getting here is a failure.
248
+ if (!ready) starting.fail('Could not start the local preview');
249
+ else log.error('The local preview stopped unexpectedly.');
250
+ if (fatal) {
251
+ const problem = describeError(fatal, contentDir, { root: packageRoot });
252
+ log.line();
253
+ log.line(formatProblems([{ where: problem.where, message: problem.message }]));
254
+ if (problem.hint) log.line(`\n${color.dim(` Hint: ${problem.hint}`)}`);
255
+ if (verbose && fatal.stack) log.line(`\n${color.dim(fatal.stack)}`);
256
+ } else if (rawTail.length) {
257
+ log.line();
258
+ log.line(color.dim(rawTail.join('\n')));
259
+ }
260
+ throw new CliExit(code || 1);
261
+ }