@vendure-io/docs-provider 0.1.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.
@@ -0,0 +1,394 @@
1
+ # Creating a Docs Package
2
+
3
+ This guide walks you through creating a complete documentation package for the Vendure documentation website.
4
+
5
+ ## Project Structure
6
+
7
+ A docs package follows this recommended structure:
8
+
9
+ ```
10
+ @vendure/docs-my-plugin/
11
+ ├── src/
12
+ │ ├── index.ts # Main entry point, exports manifest
13
+ │ └── manifest.ts # Manifest definition
14
+ ├── docs/
15
+ │ ├── getting-started/
16
+ │ │ ├── introduction.mdx
17
+ │ │ ├── installation.mdx
18
+ │ │ └── configuration.mdx
19
+ │ ├── guides/
20
+ │ │ ├── basic-usage.mdx
21
+ │ │ └── advanced-features.mdx
22
+ │ └── reference/
23
+ │ └── api-overview.mdx
24
+ ├── package.json
25
+ └── tsconfig.json
26
+ ```
27
+
28
+ ## Step 1: Initialize the Package
29
+
30
+ Create a new directory and initialize it:
31
+
32
+ ```bash
33
+ mkdir @vendure/docs-my-plugin
34
+ cd @vendure/docs-my-plugin
35
+ npm init -y
36
+ ```
37
+
38
+ Install the required dependency:
39
+
40
+ ```bash
41
+ npm install @vendure-io/docs-provider
42
+ ```
43
+
44
+ ## Step 2: Configure TypeScript
45
+
46
+ Create a `tsconfig.json`:
47
+
48
+ ```json
49
+ {
50
+ "compilerOptions": {
51
+ "target": "ES2022",
52
+ "module": "ESNext",
53
+ "moduleResolution": "bundler",
54
+ "esModuleInterop": true,
55
+ "strict": true,
56
+ "skipLibCheck": true,
57
+ "declaration": true,
58
+ "outDir": "./dist",
59
+ "rootDir": "./src"
60
+ },
61
+ "include": ["src/**/*"],
62
+ "exclude": ["node_modules", "dist"]
63
+ }
64
+ ```
65
+
66
+ ## Step 3: Configure package.json
67
+
68
+ Update your `package.json` with the correct exports:
69
+
70
+ ```json
71
+ {
72
+ "name": "@vendure/docs-my-plugin",
73
+ "version": "1.0.0",
74
+ "type": "module",
75
+ "main": "./src/index.ts",
76
+ "types": "./src/index.ts",
77
+ "exports": {
78
+ ".": {
79
+ "import": "./src/index.ts",
80
+ "require": "./src/index.ts"
81
+ },
82
+ "./manifest": {
83
+ "import": "./src/manifest.ts",
84
+ "require": "./src/manifest.ts"
85
+ }
86
+ },
87
+ "files": ["src", "docs"],
88
+ "dependencies": {
89
+ "@vendure-io/docs-provider": "^0.0.1"
90
+ },
91
+ "devDependencies": {
92
+ "typescript": "^5"
93
+ },
94
+ "keywords": ["vendure", "documentation", "docs"],
95
+ "license": "MIT"
96
+ }
97
+ ```
98
+
99
+ Key points:
100
+
101
+ - The `files` array must include both `src` and `docs` directories
102
+ - Export both the main entry point and the manifest separately
103
+ - Use `"type": "module"` for ES module support
104
+
105
+ ## Step 4: Create the Manifest
106
+
107
+ The manifest defines your documentation structure. Create `src/manifest.ts`:
108
+
109
+ ```typescript
110
+ import type { DocsPackageManifest } from '@vendure-io/docs-provider'
111
+ import { dirname, join } from 'path'
112
+ import { fileURLToPath } from 'url'
113
+
114
+ // Resolve the package root directory
115
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)))
116
+
117
+ // Helper to create absolute file paths
118
+ const file = (relativePath: string) => join(packageRoot, relativePath)
119
+
120
+ export const manifest: DocsPackageManifest = {
121
+ // Unique identifier for your package (used in URLs)
122
+ id: 'my-plugin',
123
+
124
+ // Human-readable name shown in the UI
125
+ name: 'My Plugin Documentation',
126
+
127
+ // Semantic version of your documentation
128
+ version: '1.0.0',
129
+
130
+ // Target Vendure version
131
+ vendureVersion: 'v3',
132
+
133
+ // Navigation tree structure
134
+ navigation: [
135
+ {
136
+ title: 'Getting Started',
137
+ slug: 'getting-started',
138
+ children: [
139
+ {
140
+ title: 'Introduction',
141
+ slug: 'introduction',
142
+ file: file('docs/getting-started/introduction.mdx'),
143
+ },
144
+ {
145
+ title: 'Installation',
146
+ slug: 'installation',
147
+ file: file('docs/getting-started/installation.mdx'),
148
+ },
149
+ {
150
+ title: 'Configuration',
151
+ slug: 'configuration',
152
+ file: file('docs/getting-started/configuration.mdx'),
153
+ },
154
+ ],
155
+ },
156
+ {
157
+ title: 'Guides',
158
+ slug: 'guides',
159
+ children: [
160
+ {
161
+ title: 'Basic Usage',
162
+ slug: 'basic-usage',
163
+ file: file('docs/guides/basic-usage.mdx'),
164
+ },
165
+ {
166
+ title: 'Advanced Features',
167
+ slug: 'advanced-features',
168
+ file: file('docs/guides/advanced-features.mdx'),
169
+ badge: 'New', // Optional badge label
170
+ },
171
+ ],
172
+ },
173
+ {
174
+ title: 'API Reference',
175
+ slug: 'reference',
176
+ file: file('docs/reference/api-overview.mdx'),
177
+ },
178
+ ],
179
+
180
+ // Optional: Search configuration
181
+ search: {
182
+ indexFields: ['title', 'description', 'content', 'keywords'],
183
+ boosts: {
184
+ title: 3,
185
+ keywords: 2,
186
+ description: 1.5,
187
+ content: 1,
188
+ },
189
+ },
190
+
191
+ // Optional: GitHub configuration for edit links
192
+ github: {
193
+ repository: 'your-org/your-repo',
194
+ branch: 'main',
195
+ docsPath: 'packages/docs-my-plugin',
196
+ },
197
+ }
198
+ ```
199
+
200
+ ### Understanding File Paths
201
+
202
+ **Important**: File paths in the manifest must be **absolute paths** resolved at module load time. This is because the docs application reads files directly from the file system.
203
+
204
+ The pattern used above ensures paths are resolved correctly:
205
+
206
+ ```typescript
207
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)))
208
+ const file = (relativePath: string) => join(packageRoot, relativePath)
209
+ ```
210
+
211
+ This resolves paths like:
212
+
213
+ - `file('docs/getting-started/introduction.mdx')` becomes `/path/to/node_modules/@vendure/docs-my-plugin/docs/getting-started/introduction.mdx`
214
+
215
+ ## Step 5: Export the Manifest
216
+
217
+ Create `src/index.ts`:
218
+
219
+ ```typescript
220
+ export { manifest } from './manifest'
221
+ ```
222
+
223
+ ## Step 6: Write MDX Content
224
+
225
+ Create your documentation files in the `docs/` directory. Each file must include frontmatter with at least a `title`.
226
+
227
+ **`docs/getting-started/introduction.mdx`**:
228
+
229
+ ```mdx
230
+ ---
231
+ title: Introduction to My Plugin
232
+ description: Learn what My Plugin does and why you should use it
233
+ keywords:
234
+ - introduction
235
+ - overview
236
+ - getting-started
237
+ ---
238
+
239
+ # Introduction to My Plugin
240
+
241
+ My Plugin extends Vendure with powerful features for managing your e-commerce store.
242
+
243
+ ## Features
244
+
245
+ - Feature one
246
+ - Feature two
247
+ - Feature three
248
+
249
+ ## Why Use My Plugin?
250
+
251
+ Explain the value proposition here...
252
+
253
+ ## Next Steps
254
+
255
+ Ready to get started? Head to the [Installation](/v3/my-plugin/getting-started/installation) guide.
256
+ ```
257
+
258
+ ### MDX Features
259
+
260
+ Your MDX content can use:
261
+
262
+ **Code blocks with syntax highlighting**:
263
+
264
+ ````mdx
265
+ ```typescript
266
+ const config = {
267
+ plugins: [MyPlugin],
268
+ }
269
+ ```
270
+ ````
271
+
272
+ **Admonitions** (if supported by the docs theme):
273
+
274
+ ```mdx
275
+ :::tip
276
+ This is a helpful tip!
277
+ :::
278
+
279
+ :::caution
280
+ Be careful with this setting.
281
+ :::
282
+
283
+ :::warning
284
+ This action cannot be undone.
285
+ :::
286
+ ```
287
+
288
+ **Internal links** using absolute paths:
289
+
290
+ ```mdx
291
+ See the [Configuration Guide](/v3/my-plugin/getting-started/configuration) for more details.
292
+ ```
293
+
294
+ ## Step 7: Navigation Structure Patterns
295
+
296
+ ### Nested Navigation
297
+
298
+ Group related pages under a parent node:
299
+
300
+ ```typescript
301
+ {
302
+ title: 'Guides',
303
+ slug: 'guides',
304
+ children: [
305
+ { title: 'Quick Start', slug: 'quick-start', file: file('docs/guides/quick-start.mdx') },
306
+ { title: 'Best Practices', slug: 'best-practices', file: file('docs/guides/best-practices.mdx') },
307
+ ],
308
+ }
309
+ ```
310
+
311
+ This creates URLs like:
312
+
313
+ - `/v3/my-plugin/guides/quick-start`
314
+ - `/v3/my-plugin/guides/best-practices`
315
+
316
+ ### Deeply Nested Navigation
317
+
318
+ You can nest up to 3 levels deep:
319
+
320
+ ```typescript
321
+ {
322
+ title: 'Reference',
323
+ slug: 'reference',
324
+ children: [
325
+ {
326
+ title: 'Services',
327
+ slug: 'services',
328
+ children: [
329
+ { title: 'MyService', slug: 'my-service', file: file('docs/reference/services/my-service.mdx') },
330
+ ],
331
+ },
332
+ ],
333
+ }
334
+ ```
335
+
336
+ URL: `/v3/my-plugin/reference/services/my-service`
337
+
338
+ ### Top-Level Pages
339
+
340
+ Pages can also exist at the top level:
341
+
342
+ ```typescript
343
+ {
344
+ title: 'FAQ',
345
+ slug: 'faq',
346
+ file: file('docs/faq.mdx'),
347
+ }
348
+ ```
349
+
350
+ URL: `/v3/my-plugin/faq`
351
+
352
+ ### Using Badges
353
+
354
+ Highlight new or important pages with badges:
355
+
356
+ ```typescript
357
+ {
358
+ title: 'New Feature',
359
+ slug: 'new-feature',
360
+ file: file('docs/new-feature.mdx'),
361
+ badge: 'New',
362
+ }
363
+ ```
364
+
365
+ Common badge values: `'New'`, `'Beta'`, `'Deprecated'`, `'Updated'`
366
+
367
+ ## Step 8: Validate Your Manifest
368
+
369
+ Use the `validateManifest` function to catch errors early:
370
+
371
+ ```typescript
372
+ import { validateManifest, ManifestValidationError } from '@vendure-io/docs-provider'
373
+ import { manifest } from './manifest'
374
+
375
+ try {
376
+ validateManifest(manifest)
377
+ console.log('Manifest is valid!')
378
+ } catch (error) {
379
+ if (error instanceof ManifestValidationError) {
380
+ console.error('Validation failed:')
381
+ error.issues.forEach((issue) => console.error(` - ${issue}`))
382
+ }
383
+ }
384
+ ```
385
+
386
+ ## Complete Example
387
+
388
+ For a complete working example, see the [`@vendure-io/docs-demo`](https://github.com/vendure-ecommerce/vendure-io/tree/staging/libs/docs-demo) package in the vendure-io repository.
389
+
390
+ ## Next Steps
391
+
392
+ - [Manifest Reference](./manifest-reference.md) - Detailed API documentation
393
+ - [Frontmatter Reference](./frontmatter-reference.md) - All frontmatter options
394
+ - [Publishing](./publishing.md) - How to publish your docs package