@writedocs/generator 0.11.0 → 0.12.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.
- package/package.json +3 -1
- package/src/cli/astro-output.js +44 -11
- package/src/cli/build.js +28 -2
- package/src/cli/dev.js +261 -261
- package/src/cli/og-image-worker.js +20 -0
- package/src/cli/og-images.js +70 -0
- package/src/cli/run-astro.js +97 -93
- package/src/components/ApiReferencePanel.astro +1792 -1792
- package/src/layout/BaseLayout.astro +1 -3
- package/src/layout/components/MobileMenu.astro +9 -13
- package/src/layout/components/NavTree.astro +21 -6
- package/src/layout/components/Sidebar.astro +4 -4
- package/src/layout/styles/base.css +326 -327
- package/src/layout/styles/mobile-menu.css +285 -285
- package/src/lib/og-cards.js +33 -0
- package/src/lib/og-image.js +235 -168
- package/src/pages/og/[...slug].png.ts +63 -64
- package/src/scripts/mobile-menu.ts +80 -55
- package/src/scripts/search.ts +9 -5
- package/src/scripts/sidebar-scroll.ts +61 -65
package/src/cli/run-astro.js
CHANGED
|
@@ -1,93 +1,97 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import { canonicalPath } from '../lib/canonical-path.js';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
const workerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'astro-worker.js');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Runs Astro (`command`: 'dev' or 'build') in a child process -
|
|
10
|
-
* astro-worker.js - and turns everything it reports into events for
|
|
11
|
-
* `onEvent`, so the CLI decides what reaches the terminal:
|
|
12
|
-
*
|
|
13
|
-
* { type: 'astro-log', level, label, message } - an Astro/Vite log line
|
|
14
|
-
* { type: 'report', level, message, where } - writedocs' own code
|
|
15
|
-
* (lib/cli-report.js)
|
|
16
|
-
* { type: 'raw', stream, line } - anything printed directly
|
|
17
|
-
* { type: 'ready', urls } / { type: 'done' } / { type: 'fatal', error }
|
|
18
|
-
*
|
|
19
|
-
* A raw "[writedocs] ..." line is turned into a 'report' too, so a
|
|
20
|
-
* console.warn that doesn't go through cli-report.js still shows up.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
cwd
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { canonicalPath } from '../lib/canonical-path.js';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const workerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'astro-worker.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Runs Astro (`command`: 'dev' or 'build') in a child process -
|
|
10
|
+
* astro-worker.js - and turns everything it reports into events for
|
|
11
|
+
* `onEvent`, so the CLI decides what reaches the terminal:
|
|
12
|
+
*
|
|
13
|
+
* { type: 'astro-log', level, label, message } - an Astro/Vite log line
|
|
14
|
+
* { type: 'report', level, message, where } - writedocs' own code
|
|
15
|
+
* (lib/cli-report.js)
|
|
16
|
+
* { type: 'raw', stream, line } - anything printed directly
|
|
17
|
+
* { type: 'ready', urls } / { type: 'done' } / { type: 'fatal', error }
|
|
18
|
+
*
|
|
19
|
+
* A raw "[writedocs] ..." line is turned into a 'report' too, so a
|
|
20
|
+
* console.warn that doesn't go through cli-report.js still shows up.
|
|
21
|
+
*
|
|
22
|
+
* `env` adds variables for the child only (build.js's
|
|
23
|
+
* WRITEDOCS_OG_CARDS_FILE).
|
|
24
|
+
*
|
|
25
|
+
* Returns { child, exited } - `exited` resolves with the exit code.
|
|
26
|
+
*/
|
|
27
|
+
export function runAstro(command, { packageRoot, contentDir, port, env = {}, onEvent }) {
|
|
28
|
+
// One spelling of each folder for Astro and Vite - see canonical-path.js.
|
|
29
|
+
packageRoot = canonicalPath(packageRoot);
|
|
30
|
+
contentDir = canonicalPath(contentDir);
|
|
31
|
+
const child = spawn(process.execPath, [workerPath, command], {
|
|
32
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
33
|
+
// Explicit, not inherited: astro.config.mjs's own `outDir` lives
|
|
34
|
+
// inside packageRoot (writedocsBuildStagingDir() - see its own
|
|
35
|
+
// comment in writedocs-temp-dir.js for the full EXDEV story this is
|
|
36
|
+
// one half of), and Astro's static builder only stages its
|
|
37
|
+
// prerendered output *inside* that outDir - rather than falling
|
|
38
|
+
// back to `<process.cwd()>/.astro/.prerender/` - when outDir starts
|
|
39
|
+
// with process.cwd() (getOutDirWithinCwd, astro/dist/core/build/
|
|
40
|
+
// common.js). Left unset, this child would just inherit whatever
|
|
41
|
+
// directory the *parent* writedocs CLI process happened to be
|
|
42
|
+
// launched from - unrelated to packageRoot for a real globally-
|
|
43
|
+
// installed CLI invoked from wherever the user's shell happens to
|
|
44
|
+
// be - so the fallback branch would fire regardless, staging
|
|
45
|
+
// outside packageRoot again and reintroducing the exact module-
|
|
46
|
+
// resolution problem this whole design is meant to avoid. Pinning
|
|
47
|
+
// cwd to packageRoot here guarantees the "starts with cwd" check
|
|
48
|
+
// passes deterministically, independent of the parent process's own
|
|
49
|
+
// cwd.
|
|
50
|
+
cwd: packageRoot,
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
WRITEDOCS_CONTENT_DIR: contentDir,
|
|
54
|
+
// Astro is always run with root: packageRoot (astro-worker.js), so
|
|
55
|
+
// every CollectionEntry's `filePath` comes back relative to *this*,
|
|
56
|
+
// not to contentDir or the process's cwd. Exposed so lib/config.ts's
|
|
57
|
+
// fileIdForEntry() can resolve it back into a docs/-relative file id
|
|
58
|
+
// - see that function for why.
|
|
59
|
+
WRITEDOCS_PACKAGE_ROOT: packageRoot,
|
|
60
|
+
// 'dev' or 'build' - lib/build-memo.js keeps per-build results only in a build.
|
|
61
|
+
WRITEDOCS_COMMAND: command,
|
|
62
|
+
...(port ? { WRITEDOCS_PORT: String(port) } : {}),
|
|
63
|
+
...env,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
child.on('message', (message) => {
|
|
68
|
+
if (message && typeof message === 'object' && typeof message.type === 'string') onEvent(message);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for (const streamName of ['stdout', 'stderr']) {
|
|
72
|
+
let pending = '';
|
|
73
|
+
const emit = (line) => {
|
|
74
|
+
if (line.trim() === '') return;
|
|
75
|
+
const own = line.match(/^\[writedocs\]\s+(?:(\S+:\d+(?::\d+)?) - )?(.*)$/);
|
|
76
|
+
if (own) onEvent({ type: 'report', level: streamName === 'stderr' ? 'warn' : 'info', message: own[2], where: own[1] ?? null });
|
|
77
|
+
else onEvent({ type: 'raw', stream: streamName, line });
|
|
78
|
+
};
|
|
79
|
+
child[streamName].setEncoding('utf8');
|
|
80
|
+
child[streamName].on('data', (chunk) => {
|
|
81
|
+
pending += chunk;
|
|
82
|
+
const lines = pending.split(/\r?\n/);
|
|
83
|
+
pending = lines.pop();
|
|
84
|
+
lines.forEach(emit);
|
|
85
|
+
});
|
|
86
|
+
child[streamName].on('end', () => {
|
|
87
|
+
if (pending) emit(pending);
|
|
88
|
+
pending = '';
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const exited = new Promise((resolve, reject) => {
|
|
93
|
+
child.on('error', reject);
|
|
94
|
+
child.on('close', (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
95
|
+
});
|
|
96
|
+
return { child, exited };
|
|
97
|
+
}
|