make-pdf.ts
49 lines · scripts/resolvers/make-pdf.ts at 3f79d81
1import { type TemplateContext } from './types';
2import { binaryAssignment } from './runtime-root';
4/**
5 * {{MAKE_PDF_SETUP}} — emits the readiness check that resolves $P to the
6 * make-pdf binary (make-pdf/dist/pdf). Mirrors generateDesignSetup: the
7 * assignment comes from binaryAssignment(ctx, 'make-pdf'), the same resolver
8 * the runtime prelude puts into every later block that uses $P on env-var
9 * hosts, so readiness and use always name the same binary.
10 *
11 * Resolution order: MAKE_PDF_BIN (contributor dev builds), then the
12 * repo-local install, then the global install (env-var hosts: $GSTACK_ROOT,
13 * which the prelude resolves repo-local first).
14 */
15export function generateMakePdfSetup(ctx: TemplateContext): string {
16 return `## MAKE-PDF SETUP (run this check BEFORE any make-pdf command)
18\`\`\`bash
19${binaryAssignment(ctx, 'make-pdf')}
20if [ -x "$P" ]; then
21 echo "MAKE_PDF_READY: $P"
22 alias _p_="$P" # shellcheck alias helper (not exported)
23 export P # env-var hosts re-derive $P in every later block (runtime prelude)
24else
25 echo "MAKE_PDF_NOT_AVAILABLE (run './setup' in the gstack repo to build it)"
26fi
27\`\`\`
29If \`MAKE_PDF_NOT_AVAILABLE\` is printed: tell the user the binary is not
30built. Have them run \`./setup\` from the gstack repo, then retry.
32If \`MAKE_PDF_READY\` is printed: \`$P\` is the binary path for the rest of
33the skill. Use \`$P\` (not an explicit path) so the skill body stays portable.
35Core commands:
36- \`"$P" generate <input.md> [output.pdf]\` — render markdown to PDF (80% use case)
37- \`"$P" generate --cover --toc essay.md out.pdf\` — full publication layout
38- \`"$P" generate --watermark DRAFT memo.md draft.pdf\` — diagonal DRAFT watermark
39- \`"$P" preview <input.md>\` — render HTML and open in browser (fast iteration)
40- \`"$P" setup\` — verify the browser (Aside, or gstack's own headless fallback) + pdftotext and run a smoke test
41- \`"$P" --help\` — full flag reference
43Output contract:
44- \`stdout\`: ONLY the output path on success. One line.
45- \`stderr\`: progress (\`Rendering HTML... Generating PDF...\`) unless \`--quiet\`.
46- Exit 0 success / 1 bad args / 2 render error / 3 TOC page numbers failed / 4 no browser available (open the Aside app, or run \`./setup\` to build gstack's own browser).
48PDFs print through Aside when it is running and through gstack's own headless browser otherwise; the stderr progress line says which (\`Rendering PDF through Aside\` / \`through gstack's browser\`).`;
49}