@tobisk/codesafari 1.0.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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +215 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.js +78 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/export.d.ts +16 -0
  7. package/dist/commands/export.js +68 -0
  8. package/dist/commands/export.js.map +1 -0
  9. package/dist/commands/paths.d.ts +7 -0
  10. package/dist/commands/paths.js +25 -0
  11. package/dist/commands/paths.js.map +1 -0
  12. package/dist/commands/validate.d.ts +8 -0
  13. package/dist/commands/validate.js +51 -0
  14. package/dist/commands/validate.js.map +1 -0
  15. package/dist/content/frontmatter.d.ts +15 -0
  16. package/dist/content/frontmatter.js +35 -0
  17. package/dist/content/frontmatter.js.map +1 -0
  18. package/dist/content/loadContent.d.ts +20 -0
  19. package/dist/content/loadContent.js +188 -0
  20. package/dist/content/loadContent.js.map +1 -0
  21. package/dist/content/walk.d.ts +12 -0
  22. package/dist/content/walk.js +34 -0
  23. package/dist/content/walk.js.map +1 -0
  24. package/dist/ignore/ignore.d.ts +21 -0
  25. package/dist/ignore/ignore.js +60 -0
  26. package/dist/ignore/ignore.js.map +1 -0
  27. package/dist/index.d.ts +9 -0
  28. package/dist/index.js +9 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/manifest/build.d.ts +21 -0
  31. package/dist/manifest/build.js +316 -0
  32. package/dist/manifest/build.js.map +1 -0
  33. package/dist/model/types.d.ts +178 -0
  34. package/dist/model/types.js +11 -0
  35. package/dist/model/types.js.map +1 -0
  36. package/dist/parser/comments.d.ts +43 -0
  37. package/dist/parser/comments.js +215 -0
  38. package/dist/parser/comments.js.map +1 -0
  39. package/dist/parser/ordering.d.ts +19 -0
  40. package/dist/parser/ordering.js +52 -0
  41. package/dist/parser/ordering.js.map +1 -0
  42. package/dist/parser/resolveTarget.d.ts +34 -0
  43. package/dist/parser/resolveTarget.js +155 -0
  44. package/dist/parser/resolveTarget.js.map +1 -0
  45. package/dist/server/devServer.d.ts +10 -0
  46. package/dist/server/devServer.js +170 -0
  47. package/dist/server/devServer.js.map +1 -0
  48. package/package.json +95 -0
  49. package/viewer-dist/assets/abnfDiagram-VRR7QNED-D3fx4JHm.js +1 -0
  50. package/viewer-dist/assets/arc-CDTQlIOl.js +1 -0
  51. package/viewer-dist/assets/architectureDiagram-ZJ3FMSHR-Bc-C9AOz.js +36 -0
  52. package/viewer-dist/assets/blockDiagram-677ZJIJ3-ZChUq7oC.js +132 -0
  53. package/viewer-dist/assets/c4Diagram-LMCZKHZV-Bh84Wvzw.js +10 -0
  54. package/viewer-dist/assets/channel-c5yLhzg_.js +1 -0
  55. package/viewer-dist/assets/chunk-2Q5K7J3B-BL2GPise.js +1 -0
  56. package/viewer-dist/assets/chunk-32BRIVSS-C8J4_0PY.js +1 -0
  57. package/viewer-dist/assets/chunk-5VM5RSS4-BEPuob2j.js +15 -0
  58. package/viewer-dist/assets/chunk-EX3LRPZG-C8dshNGY.js +231 -0
  59. package/viewer-dist/assets/chunk-JWPE2WC7-DB3UPcb9.js +1 -0
  60. package/viewer-dist/assets/chunk-MOJQB5TN-CoW82BtI.js +88 -0
  61. package/viewer-dist/assets/chunk-RYQCIY6F-BSkOviuC.js +1 -0
  62. package/viewer-dist/assets/chunk-V7JOEXUC-C3uhoOMH.js +206 -0
  63. package/viewer-dist/assets/chunk-VR4S4FIN-IAlLBWOE.js +1 -0
  64. package/viewer-dist/assets/chunk-XXDRQBXY-BZ2dkDjb.js +1 -0
  65. package/viewer-dist/assets/classDiagram-OUVF2IWQ-t57CRPeZ.js +1 -0
  66. package/viewer-dist/assets/classDiagram-v2-EOCWNBFH-t57CRPeZ.js +1 -0
  67. package/viewer-dist/assets/cose-bilkent-JH36ORCC-qThT2S0A.js +1 -0
  68. package/viewer-dist/assets/cynefin-VYW2F7L2-DMuuSzID.js +178 -0
  69. package/viewer-dist/assets/cynefinDiagram-TSTJHNR4-58B-tzsV.js +62 -0
  70. package/viewer-dist/assets/cytoscape.esm-CUqq0XTU.js +331 -0
  71. package/viewer-dist/assets/dagre-VKFMJZFB-DD2dvjEA.js +4 -0
  72. package/viewer-dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  73. package/viewer-dist/assets/diagram-FQU43EPY-BwhXWJOe.js +3 -0
  74. package/viewer-dist/assets/diagram-G47NLZAW-Bvw3coaF.js +24 -0
  75. package/viewer-dist/assets/diagram-NH7WQ7WH-Cug3_TDj.js +24 -0
  76. package/viewer-dist/assets/diagram-OA4YK3LP-COuB13FS.js +30 -0
  77. package/viewer-dist/assets/diagram-WEI45ONY-Cs9bIVJ-.js +41 -0
  78. package/viewer-dist/assets/ebnfDiagram-CCIWWBDH-DNxW5fFn.js +1 -0
  79. package/viewer-dist/assets/erDiagram-Q63AITRT-CoxCZQYq.js +85 -0
  80. package/viewer-dist/assets/flowDiagram-23GEKE2U-DDOkOM11.js +156 -0
  81. package/viewer-dist/assets/ganttDiagram-NO4QXBWP-BMIv-Vup.js +292 -0
  82. package/viewer-dist/assets/gitGraphDiagram-IHSO6WYX-CaYRI7Ti.js +106 -0
  83. package/viewer-dist/assets/graph-C2PyVmSI.js +1 -0
  84. package/viewer-dist/assets/index-DPa56qLF.js +430 -0
  85. package/viewer-dist/assets/index-sJB3TFqL.css +1 -0
  86. package/viewer-dist/assets/infoDiagram-FWYZ7A6U-CG1-XeBO.js +2 -0
  87. package/viewer-dist/assets/init-Gi6I4Gst.js +1 -0
  88. package/viewer-dist/assets/ishikawaDiagram-FXEZZL3T-BAaIgDfG.js +70 -0
  89. package/viewer-dist/assets/journeyDiagram-5HDEW3XC-oPpLTcMj.js +139 -0
  90. package/viewer-dist/assets/kanban-definition-HUTT4EX6-wplcQi9I.js +89 -0
  91. package/viewer-dist/assets/katex-C5jXJg4s.js +257 -0
  92. package/viewer-dist/assets/layout-HEHzrzvT.js +1 -0
  93. package/viewer-dist/assets/linear-3o0ZqjSV.js +1 -0
  94. package/viewer-dist/assets/map-BQHxRNoK.js +1 -0
  95. package/viewer-dist/assets/mindmap-definition-LN4V7U3C-FkdX9xoS.js +96 -0
  96. package/viewer-dist/assets/ordinal-Cboi1Yqb.js +1 -0
  97. package/viewer-dist/assets/pegDiagram-2B236MQR-UcxUgXaX.js +1 -0
  98. package/viewer-dist/assets/pieDiagram-ENE6RG2P-BEujiO1u.js +39 -0
  99. package/viewer-dist/assets/quadrantDiagram-ABIIQ3AL-BsWx4RNa.js +7 -0
  100. package/viewer-dist/assets/railroadDiagram-RFXS5EU6-CaiR8155.js +1 -0
  101. package/viewer-dist/assets/requirementDiagram-TGXJPOKE-B7WepZjB.js +84 -0
  102. package/viewer-dist/assets/sankeyDiagram-HTMAVEWB-D2ys-GcR.js +40 -0
  103. package/viewer-dist/assets/sequenceDiagram-DBY2YBRQ-BCx5Lqm4.js +162 -0
  104. package/viewer-dist/assets/sizeCapture-X5ZJPWSS-CdyWDUKU.js +1 -0
  105. package/viewer-dist/assets/stateDiagram-2N3HPSRC-CKjHd02p.js +1 -0
  106. package/viewer-dist/assets/stateDiagram-v2-6OUMAXLB-oQDdTlVJ.js +1 -0
  107. package/viewer-dist/assets/swimlanes-5IMT3BWC-wE7K0Eo8.js +2 -0
  108. package/viewer-dist/assets/swimlanesDiagram-G3AALYLV-Axc7yQiy.js +8 -0
  109. package/viewer-dist/assets/timeline-definition-FHXFAJF6-B9iZKy9Y.js +120 -0
  110. package/viewer-dist/assets/vennDiagram-L72KCM5P-CIMukQYN.js +34 -0
  111. package/viewer-dist/assets/wardleyDiagram-EHGQE667-JZnnBRHP.js +78 -0
  112. package/viewer-dist/assets/xychartDiagram-FW5EYKEG-BphHZiLL.js +7 -0
  113. package/viewer-dist/index.html +15 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodeSafari contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # @tobisk/codesafari
2
+
3
+ Turn a `.tour/` folder plus inline `@tour` source comments into a **local, offline code-tour website**.
4
+
5
+ `@tobisk/codesafari` is a self-contained TypeScript/React tool you run with `npx`. It reads authored Markdown and inline code comments, builds a manifest of your project's guided tours, and serves them through a VS Code-like read-only viewer with a Monokai theme. It can run live with file watching (`dev`) or emit a fully static, backend-free site (`export`).
6
+
7
+ **[Live demo →](https://kellertobias.github.io/codesafari/)**
8
+
9
+ ![The CodeSafari viewer mid-tour: the file tree open on the left, a source file open in the code pane, and the step panel on the right.](docs/viewer-explorer.safari.png)
10
+
11
+ > Status: **early development.** The content model, parser, and CLI (`validate`) are the first pieces landing. See [Roadmap](#roadmap).
12
+
13
+ ## Why
14
+
15
+ Onboarding docs rot because they live away from the code. CodeSafari keeps the *narrative* next to the *source*:
16
+
17
+ - **Author overviews once** in `.tour/` Markdown (project, components, tours, glossary).
18
+ - **Anchor steps to real code** with `@tour slug:step Title` comments that live in the source and move with it.
19
+ - **Read it like an IDE** — a file tree, a scrollable read-only code viewer, and a step-by-step tour panel — with the freedom to "sneak around" and explore any file.
20
+ - **Ship it anywhere** — `export` produces static HTML/CSS/JS with source bundled in, so the site works offline with no server.
21
+
22
+ ## Install / Run
23
+
24
+ No install required:
25
+
26
+ ```bash
27
+ npx @tobisk/codesafari dev # live server with file watching (default port 4317)
28
+ npx @tobisk/codesafari export # emit a static site to ./codesafari-site
29
+ npx @tobisk/codesafari validate # check content and report problems
30
+ ```
31
+
32
+ Or add it to a project:
33
+
34
+ ```bash
35
+ npm install --save-dev @tobisk/codesafari
36
+ ```
37
+
38
+ ### CLI
39
+
40
+ | Command | Description |
41
+ | --- | --- |
42
+ | `codesafari dev [root] --port 4317` | Build the manifest, serve the viewer, watch files, and live-reload. |
43
+ | `codesafari export [root] --out codesafari-site` | Write a frozen manifest, bundled source content, and static assets. |
44
+ | `codesafari validate [root]` | Parse all content and report errors (bad frontmatter, dangling links, unresolved steps, broken Mermaid). |
45
+
46
+ `root` defaults to the current directory. It must contain a `.tour/` folder.
47
+
48
+ ## Content model
49
+
50
+ All authored content lives under `.tour/`. Markdown files use YAML frontmatter.
51
+
52
+ ```
53
+ .tour/
54
+ index.md # project overview + global defaults
55
+ components/*.md # software components
56
+ tours/**/*.md # tour entry pages
57
+ glossary/**/*.md # glossary concepts (one or many per file)
58
+ examples/**/*.md # (v1.5) small self-contained code walkthroughs
59
+ ```
60
+
61
+ ### `.tour/index.md`
62
+
63
+ ```markdown
64
+ ---
65
+ title: My Project
66
+ description: What this project is.
67
+ defaultSnippetLines: 20
68
+ repositoryUrl: https://github.com/me/my-project # optional
69
+ ---
70
+
71
+ Landing-page introduction in Markdown.
72
+ ```
73
+
74
+ ### Components — `.tour/components/*.md`
75
+
76
+ ```markdown
77
+ ---
78
+ slug: queue-worker
79
+ title: Queue Worker
80
+ summary: Processes background jobs. # optional
81
+ order: 10 # optional
82
+ ---
83
+
84
+ Description of the component in Markdown.
85
+ ```
86
+
87
+ ### Tours — `.tour/tours/**/*.md`
88
+
89
+ ```markdown
90
+ ---
91
+ slug: onboarding
92
+ title: Onboarding Tour
93
+ components: [queue-worker] # optional
94
+ order: 1 # optional
95
+ defaultSnippetLines: 30 # optional; overrides project default
96
+ ---
97
+
98
+ Intro shown before the "Start tour" button.
99
+ ```
100
+
101
+ ### Glossary — `.tour/glossary/**/*.md`
102
+
103
+ One file may define many concepts using headings. Link to a concept from anywhere with an explicit Markdown link:
104
+
105
+ ```markdown
106
+ See the [Queue worker](glossary:queue-worker) for details.
107
+ ```
108
+
109
+ ## Inline tour comments
110
+
111
+ Anchor a tour step to code with a comment whose first line is:
112
+
113
+ ```
114
+ @tour <tour-slug>:<step-order> <Step title>
115
+ ```
116
+
117
+ The rest of the continuous comment block is the step body (full Markdown: inline code, links, images, `glossary:` links, and fenced ```mermaid``` diagrams).
118
+
119
+ ```ts
120
+ // @tour onboarding:12.34 Enqueue a job
121
+ // The producer pushes work onto the queue. Downstream, the
122
+ // [Queue worker](glossary:queue-worker) drains it.
123
+ function enqueue(job: Job) { /* ... */ }
124
+ ```
125
+
126
+ **Step order is dot-aware numeric.** `12.34` sorts before `12.45`; `12.2` sorts before `12.10`.
127
+
128
+ **Non-step callouts** render as styled annotations (not navigation steps):
129
+
130
+ ```
131
+ // @tour comment Watch out
132
+ // This map is not thread-safe.
133
+ ```
134
+
135
+ A callout is scoped to the step section it follows — it appears only while you're
136
+ on the nearest step above it in the file. A callout placed before every step in a
137
+ file applies to the whole file and shows whenever that file is open.
138
+
139
+ ### How a step resolves its highlight
140
+
141
+ Given a step comment, the target range is chosen by what directly follows it:
142
+
143
+ - Directly before a **class** → the whole class.
144
+ - Directly before a **function/method** → that function/method.
145
+ - Directly before another **block** → that block.
146
+ - Otherwise → the comment plus the next `defaultSnippetLines` lines (tour-level value overrides the project default).
147
+
148
+ ## Diagrams
149
+
150
+ Fenced ```` ```mermaid ```` blocks in any `.tour/` Markdown or source-comment body are rendered locally to SVG — on demand during `dev`, and pre-rendered into static assets during `export`. Rendering never touches the network. `validate` reports the file and block for any diagram that fails to render.
151
+
152
+ ## Ignore rules
153
+
154
+ Files are excluded from parsing, serving, and export using `.gitignore` plus an optional `.codesafariignore` (same syntax). `.tour/` content is always included, even if a broad pattern would otherwise match it. Images referenced from source comments must be project-relative paths that are not ignored.
155
+
156
+ ## Export output
157
+
158
+ `export` produces a self-contained directory:
159
+
160
+ - the prebuilt React viewer (HTML/CSS/JS),
161
+ - a frozen `manifest.json`,
162
+ - bundled readable source-file content,
163
+ - pre-rendered diagram SVGs and copied images.
164
+
165
+ It runs entirely offline and exposes every included source file.
166
+
167
+ ## Languages
168
+
169
+ v1 parses **TypeScript/TSX, Rust, and Python** via Tree-sitter. Planned next: C/C++, Vue, Go, PHP.
170
+
171
+ ## Roadmap
172
+
173
+ - **v1** — content model, ignore handling, dot-aware ordering, heuristic parsing, `validate` / `dev` / `export`, React viewer (Monokai), Mermaid diagrams.
174
+ - **v1.5** — small self-contained, state-based code **examples** authored in Markdown, attachable to tours, components, glossary concepts, or standalone.
175
+
176
+ The center code viewer sits behind an internal `CodeViewer` abstraction. **v1 uses [Code Hike](https://codehike.org)** (`codehike/code`): the CLI calls Code Hike's `highlight()` primitive directly, so authored tours stay pure Markdown — no MDX, no React authoring — while the viewer gets Code Hike's tokenizer, Monokai theme, and composable annotation handlers for line numbers and range highlighting. The abstraction keeps the door open to swapping in Monaco later without touching authored content.
177
+
178
+ ### Try it on this repo
179
+
180
+ This repository tours itself. From the repo root:
181
+
182
+ ```bash
183
+ npm run safari # build the core + viewer, then serve the tour at http://localhost:4317
184
+ ```
185
+
186
+ `npm run safari` runs CodeSafari on CodeSafari. The `.tour/` folder and the `@tour` comments throughout `src/` and `viewer/src/` drive a two-tour walkthrough of the codebase.
187
+
188
+ ## Tests
189
+
190
+ Unit and integration tests run under Vitest; end-to-end tests drive the real
191
+ `dev` server with Playwright (headless Chromium), against this self-touring repo.
192
+
193
+ ```bash
194
+ npm test # unit + integration (Vitest)
195
+ npm run test:e2e # end-to-end viewer tests (Playwright)
196
+ ```
197
+
198
+ The e2e suite exercises the landing page, the file-tree toggle, and stepping a
199
+ tour. One spec (`e2e/screenshot.spec.ts`) also captures the viewer with the file
200
+ tree and a file open, which powers the README screenshot:
201
+
202
+ ```bash
203
+ npm run screenshot
204
+ ```
205
+
206
+ `npm run screenshot` runs that one spec to write `docs/viewer-explorer.png`, then
207
+ wraps it in dark-mode Safari chrome with the vendored
208
+ [browsershot](https://github.com/kellertobias/browsershot) tool
209
+ (`scripts/browsershot`, run in an isolated Python venv) to produce
210
+ `docs/viewer-explorer.safari.png` — the image shown at the top of this README.
211
+ The framing step needs macOS; on other platforms the raw capture is still written.
212
+
213
+ ## License
214
+
215
+ MIT © CodeSafari contributors
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ /** Command-line entrypoint for @tobisk/codesafari. */
3
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ /** Command-line entrypoint for @tobisk/codesafari. */
3
+ import { readFile } from 'node:fs/promises';
4
+ import { Command } from 'commander';
5
+ import { runValidate } from './commands/validate.js';
6
+ import { runExport } from './commands/export.js';
7
+ import { runDev } from './server/devServer.js';
8
+ import { packageRoot } from './commands/paths.js';
9
+ async function readVersion() {
10
+ try {
11
+ const pkg = JSON.parse(await readFile(`${packageRoot()}/package.json`, 'utf8'));
12
+ return typeof pkg.version === 'string' ? pkg.version : '0.0.0';
13
+ }
14
+ catch {
15
+ return '0.0.0';
16
+ }
17
+ }
18
+ // @tour pipeline:1 The CLI entry point
19
+ // Every run starts here. A `commander` program declares three subcommands —
20
+ // `dev`, `export`, and `validate` — each taking an optional `root` (defaulting
21
+ // to the current directory). Follow the `validate` branch through this tour.
22
+ async function main() {
23
+ const program = new Command();
24
+ program
25
+ .name('codesafari')
26
+ .description('Local, offline code-tour websites')
27
+ .version(await readVersion(), '-v, --version')
28
+ .showHelpAfterError();
29
+ // @tour:detail The dev command
30
+ // `dev` builds the manifest, serves the viewer, watches files, and — unless
31
+ // `--no-open` is passed — opens your browser. This is what `npm run safari`
32
+ // runs against this very repository.
33
+ program
34
+ .command('dev')
35
+ .argument('[root]', 'project directory', process.cwd())
36
+ .description('Serve the viewer with live reload')
37
+ .option('-p, --port <number>', 'dev server port', '4317')
38
+ .option('--no-open', 'do not open the browser on startup')
39
+ .action(async (root, opts) => {
40
+ const port = Number.parseInt(opts.port, 10);
41
+ if (!Number.isInteger(port) || port <= 0) {
42
+ program.error(`Invalid --port value: ${opts.port}`);
43
+ }
44
+ await runDev(root, { port, open: opts.open });
45
+ });
46
+ program
47
+ .command('export')
48
+ .argument('[root]', 'project directory', process.cwd())
49
+ .description('Write a self-contained static site')
50
+ .option('-o, --out <dir>', 'output directory', 'codesafari-site')
51
+ .action(async (root, opts) => {
52
+ const result = await runExport(root, { out: opts.out });
53
+ if (!result.ok)
54
+ process.exitCode = 1;
55
+ });
56
+ // @tour:detail The validate command
57
+ // `validate` is the pure check: build the manifest, print diagnostics, and
58
+ // exit non-zero if anything is wrong. No server, no output written.
59
+ program
60
+ .command('validate')
61
+ .argument('[root]', 'project directory', process.cwd())
62
+ .description('Parse content and report problems')
63
+ .action(async (root) => {
64
+ const result = await runValidate(root);
65
+ if (!result.ok)
66
+ process.exitCode = 1;
67
+ });
68
+ // With no command, print help rather than doing nothing.
69
+ if (process.argv.length <= 2) {
70
+ program.help();
71
+ }
72
+ await program.parseAsync(process.argv);
73
+ }
74
+ main().catch((err) => {
75
+ console.error(err instanceof Error ? err.message : String(err));
76
+ process.exit(1);
77
+ });
78
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,sDAAsD;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,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MAAM,CAAC,EAAE;YAAE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEL,yDAAyD;IACzD,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** `codesafari export` — write a self-contained static site. */
2
+ export interface ExportOptions {
3
+ out: string;
4
+ }
5
+ export interface ExportResult {
6
+ ok: boolean;
7
+ outDir: string;
8
+ fileCount: number;
9
+ errors: number;
10
+ }
11
+ /**
12
+ * Build a frozen manifest with bundled source content, then copy the prebuilt
13
+ * viewer and write the manifest alongside it. The result runs offline with no
14
+ * backend.
15
+ */
16
+ export declare function runExport(root: string, options: ExportOptions): Promise<ExportResult>;
@@ -0,0 +1,68 @@
1
+ /** `codesafari export` — write a self-contained static site. */
2
+ import { promises as fs } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { buildManifest } from '../manifest/build.js';
5
+ import { viewerBuilt, viewerDistDir } from './paths.js';
6
+ // @tour pipeline:5 Freezing a static site
7
+ // The same manifest, made portable. `export` builds it with source content
8
+ // bundled in, copies the prebuilt viewer, and writes the manifest as both JSON
9
+ // and an inline `window.__CODESAFARI_MANIFEST__` script — so the exported site
10
+ // runs from `file://` with no server and no network.
11
+ /**
12
+ * Build a frozen manifest with bundled source content, then copy the prebuilt
13
+ * viewer and write the manifest alongside it. The result runs offline with no
14
+ * backend.
15
+ */
16
+ export async function runExport(root, options) {
17
+ const resolved = path.resolve(root);
18
+ const outDir = path.resolve(options.out);
19
+ const { manifest, diagnostics } = await buildManifest(resolved, {
20
+ bundleSources: true,
21
+ });
22
+ const errors = diagnostics.filter((d) => d.severity === 'error');
23
+ for (const d of diagnostics) {
24
+ const location = d.file ? `${d.file}${d.line ? `:${d.line}` : ''} ` : '';
25
+ console.log(` ${d.severity === 'error' ? 'error' : 'warn'} ${location}${d.message}`);
26
+ }
27
+ if (errors.length > 0) {
28
+ console.error(`Export aborted: ${errors.length} error(s). Fix them and retry.`);
29
+ return { ok: false, outDir, fileCount: 0, errors: errors.length };
30
+ }
31
+ if (!(await viewerBuilt())) {
32
+ throw new Error('Prebuilt viewer assets are missing (viewer-dist/). Run `npm run build:viewer` before exporting from source.');
33
+ }
34
+ await fs.rm(outDir, { recursive: true, force: true });
35
+ await fs.mkdir(outDir, { recursive: true });
36
+ // Copy the prebuilt viewer.
37
+ await copyDir(viewerDistDir(), outDir);
38
+ // Write the frozen manifest as a JS module and JSON, so the static viewer can
39
+ // load it with a plain <script> (no fetch needed for file:// use).
40
+ await fs.mkdir(path.join(outDir, 'data'), { recursive: true });
41
+ const json = JSON.stringify(manifest);
42
+ await fs.writeFile(path.join(outDir, 'data', 'manifest.json'), json, 'utf8');
43
+ await fs.writeFile(path.join(outDir, 'data', 'manifest.js'), `window.__CODESAFARI_MANIFEST__ = ${json};`, 'utf8');
44
+ console.log(`Exported static site to ${outDir}`);
45
+ console.log(` ${manifest.files.length} source file(s) bundled.`);
46
+ return {
47
+ ok: true,
48
+ outDir,
49
+ fileCount: manifest.files.length,
50
+ errors: 0,
51
+ };
52
+ }
53
+ /** Recursively copy a directory tree. */
54
+ async function copyDir(from, to) {
55
+ await fs.mkdir(to, { recursive: true });
56
+ const entries = await fs.readdir(from, { withFileTypes: true });
57
+ for (const entry of entries) {
58
+ const src = path.join(from, entry.name);
59
+ const dest = path.join(to, entry.name);
60
+ if (entry.isDirectory()) {
61
+ await copyDir(src, dest);
62
+ }
63
+ else {
64
+ await fs.copyFile(src, dest);
65
+ }
66
+ }
67
+ }
68
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAaxD,0CAA0C;AAC1C,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,qDAAqD;AACrD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAY,EACZ,OAAsB;IAEtB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEzC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE;QAC9D,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACjE,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,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ets (the prebuilt viewer). */
2
+ /** Absolute path to the package root (the dir containing package.json). */
3
+ export declare function packageRoot(): string;
4
+ /** Absolute path to the prebuilt viewer directory shipped in the package. */
5
+ export declare function viewerDistDir(): string;
6
+ /** True if the prebuilt viewer assets are present. */
7
+ export declare function viewerBuilt(): Promise<boolean>;
@@ -0,0 +1,25 @@
1
+ /** Locate package-bundled runtime assets (the prebuilt viewer). */
2
+ import { promises as fs } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ /** Absolute path to the package root (the dir containing package.json). */
6
+ export function packageRoot() {
7
+ // This file lives at dist/commands/paths.js after build → up two levels.
8
+ const here = path.dirname(fileURLToPath(import.meta.url));
9
+ return path.resolve(here, '..', '..');
10
+ }
11
+ /** Absolute path to the prebuilt viewer directory shipped in the package. */
12
+ export function viewerDistDir() {
13
+ return path.join(packageRoot(), 'viewer-dist');
14
+ }
15
+ /** True if the prebuilt viewer assets are present. */
16
+ export async function viewerBuilt() {
17
+ try {
18
+ await fs.access(path.join(viewerDistDir(), 'index.html'));
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/commands/paths.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,UAAU,WAAW;IACzB,yEAAyE;IACzE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,aAAa,CAAC,CAAC;AACjD,CAAC;AAED,sDAAsD;AACtD,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** `codesafari validate` — parse all content and report problems. */
2
+ export interface ValidateResult {
3
+ ok: boolean;
4
+ errors: number;
5
+ warnings: number;
6
+ }
7
+ /** Build the manifest and print diagnostics. Returns a pass/fail summary. */
8
+ export declare function runValidate(root: string): Promise<ValidateResult>;
@@ -0,0 +1,51 @@
1
+ /** `codesafari validate` — parse all content and report problems. */
2
+ import { promises as fs } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { buildManifest } from '../manifest/build.js';
5
+ // @tour pipeline:2 Validating a project
6
+ // `validate` is the simplest command and the best lens on the pipeline: it
7
+ // confirms a `.tour/` directory exists, builds the manifest, prints every
8
+ // diagnostic, and returns a non-zero exit code if any errors were found.
9
+ /** Build the manifest and print diagnostics. Returns a pass/fail summary. */
10
+ export async function runValidate(root) {
11
+ const resolved = path.resolve(root);
12
+ await assertTourDir(resolved);
13
+ const { manifest, diagnostics } = await buildManifest(resolved);
14
+ const errors = diagnostics.filter((d) => d.severity === 'error');
15
+ const warnings = diagnostics.filter((d) => d.severity === 'warning');
16
+ printSummary(manifest, diagnostics);
17
+ const ok = errors.length === 0;
18
+ return { ok, errors: errors.length, warnings: warnings.length };
19
+ }
20
+ async function assertTourDir(root) {
21
+ const tourDir = path.join(root, '.tour');
22
+ try {
23
+ const stat = await fs.stat(tourDir);
24
+ if (!stat.isDirectory())
25
+ throw new Error('not a directory');
26
+ }
27
+ catch {
28
+ throw new Error(`No .tour/ directory found in ${root}. Create one with a .tour/index.md to get started.`);
29
+ }
30
+ }
31
+ function printSummary(manifest, diagnostics) {
32
+ const stepCount = manifest.tours.reduce((n, t) => n + t.steps.length, 0);
33
+ console.log(`Project: ${manifest.project.title}`);
34
+ console.log(` ${manifest.components.length} component(s), ${manifest.tours.length} tour(s), ` +
35
+ `${stepCount} step(s), ${manifest.glossary.length} glossary concept(s), ` +
36
+ `${manifest.callouts.length} callout(s).`);
37
+ for (const d of diagnostics) {
38
+ const location = d.file ? `${d.file}${d.line ? `:${d.line}` : ''}` : '';
39
+ const tag = d.severity === 'error' ? 'error' : 'warn';
40
+ console.log(` ${tag} ${location ? `${location} ` : ''}${d.message}`);
41
+ }
42
+ const errors = diagnostics.filter((d) => d.severity === 'error').length;
43
+ const warnings = diagnostics.filter((d) => d.severity === 'warning').length;
44
+ if (errors === 0 && warnings === 0) {
45
+ console.log('No problems found.');
46
+ }
47
+ else {
48
+ console.log(`${errors} error(s), ${warnings} warning(s).`);
49
+ }
50
+ }
51
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/commands/validate.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAQrD,wCAAwC;AACxC,2EAA2E;AAC3E,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE9B,MAAM,EA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QACN,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,cAAc,QAAQ,cAAc,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ /** Thin, typed wrapper over gray-matter for parsing frontmatter + body. */
2
+ export interface ParsedDocument {
3
+ data: Record<string, unknown>;
4
+ body: string;
5
+ }
6
+ /** Parse a Markdown string into frontmatter data and trimmed body. */
7
+ export declare function parseFrontmatter(source: string): ParsedDocument;
8
+ /** Read a required string field, throwing a descriptive error if missing. */
9
+ export declare function requireString(data: Record<string, unknown>, key: string, context: string): string;
10
+ export declare function optionalString(data: Record<string, unknown>, key: string): string | undefined;
11
+ export declare function optionalNumber(data: Record<string, unknown>, key: string): number | undefined;
12
+ export declare function optionalStringArray(data: Record<string, unknown>, key: string): string[];
13
+ /** A frontmatter validation error, carrying only a human-readable message. */
14
+ export declare class FieldError extends Error {
15
+ }
@@ -0,0 +1,35 @@
1
+ /** Thin, typed wrapper over gray-matter for parsing frontmatter + body. */
2
+ import matter from 'gray-matter';
3
+ /** Parse a Markdown string into frontmatter data and trimmed body. */
4
+ export function parseFrontmatter(source) {
5
+ const parsed = matter(source);
6
+ return { data: parsed.data, body: parsed.content.trim() };
7
+ }
8
+ /** Read a required string field, throwing a descriptive error if missing. */
9
+ export function requireString(data, key, context) {
10
+ const value = data[key];
11
+ if (typeof value !== 'string' || value.trim() === '') {
12
+ throw new FieldError(`Missing required "${key}" in ${context}`);
13
+ }
14
+ return value;
15
+ }
16
+ export function optionalString(data, key) {
17
+ const value = data[key];
18
+ return typeof value === 'string' ? value : undefined;
19
+ }
20
+ export function optionalNumber(data, key) {
21
+ const value = data[key];
22
+ if (typeof value === 'number' && Number.isFinite(value))
23
+ return value;
24
+ return undefined;
25
+ }
26
+ export function optionalStringArray(data, key) {
27
+ const value = data[key];
28
+ if (!Array.isArray(value))
29
+ return [];
30
+ return value.filter((item) => typeof item === 'string');
31
+ }
32
+ /** A frontmatter validation error, carrying only a human-readable message. */
33
+ export class FieldError extends Error {
34
+ }
35
+ //# sourceMappingURL=frontmatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/content/frontmatter.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,MAAM,MAAM,aAAa,CAAC;AAOjC,sEAAsE;AACtE,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAA+B,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;AACvF,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAC3B,IAA6B,EAC7B,GAAW,EACX,OAAe;IAEf,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,UAAU,CAAC,qBAAqB,GAAG,QAAQ,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,IAA6B,EAC7B,GAAW;IAEX,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,IAA6B,EAC7B,GAAW;IAEX,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtE,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,IAA6B,EAC7B,GAAW;IAEX,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;AAC1E,CAAC;AAED,8EAA8E;AAC9E,MAAM,OAAO,UAAW,SAAQ,KAAK;CAAG"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Load authored `.tour/` content into typed model objects.
3
+ *
4
+ * This layer is responsible only for reading and validating Markdown +
5
+ * frontmatter — it does not scan source comments or resolve highlight ranges.
6
+ * Problems are collected as {@link Diagnostic}s rather than thrown, so a single
7
+ * bad file doesn't abort the whole build; only fatal I/O errors propagate.
8
+ */
9
+ import type { Component, Diagnostic, GlossaryConcept, ProjectMeta, Tour } from '../model/types.js';
10
+ export interface LoadedContent {
11
+ project: ProjectMeta;
12
+ components: Component[];
13
+ tours: Omit<Tour, 'steps'>[];
14
+ glossary: GlossaryConcept[];
15
+ diagnostics: Diagnostic[];
16
+ }
17
+ /** Load and validate all `.tour/` content under `root`. */
18
+ export declare function loadContent(root: string): Promise<LoadedContent>;
19
+ /** Convert a heading title into a URL-safe glossary slug. */
20
+ export declare function slugify(text: string): string;