@stritti/vitepress-plugin-openspec 0.6.0 → 0.7.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,217 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * Options for the `withOpenSpec()` config helper.
5
+ * Extends `OpenSpecPluginOptions` with optional nav/sidebar merge controls.
6
+ */
7
+ interface WithOpenSpecOptions extends OpenSpecPluginOptions {
8
+ /**
9
+ * Whether to prepend an openspec nav entry to `themeConfig.nav`.
10
+ * @default true
11
+ */
12
+ nav?: boolean;
13
+ /**
14
+ * Whether to inject the openspec sidebar section into `themeConfig.sidebar`.
15
+ * @default true
16
+ */
17
+ sidebar?: boolean;
18
+ }
19
+ /**
20
+ * Configuration options for the vitepress-plugin-openspec plugin.
21
+ */
22
+ interface OpenSpecPluginOptions {
23
+ /**
24
+ * Path to the openspec/ directory of the project.
25
+ *
26
+ * Use an explicit path when your `openspec/` folder is not at the project root
27
+ * (e.g. when `config.ts` lives inside `docs/.vitepress/`).
28
+ *
29
+ * If the directory does not exist a warning is printed and the build continues
30
+ * without generating any pages or nav/sidebar entries — no error is thrown.
31
+ *
32
+ * @default './openspec'
33
+ * @example
34
+ * // Resolving from docs/.vitepress/config.ts
35
+ * import path from 'node:path'
36
+ * import { fileURLToPath } from 'node:url'
37
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url))
38
+ * const specDir = path.resolve(__dirname, '../../openspec')
39
+ */
40
+ specDir?: string;
41
+ /**
42
+ * Output directory (relative to VitePress `srcDir`) where the generated
43
+ * Markdown pages will be written.
44
+ * @default 'openspec'
45
+ */
46
+ outDir?: string;
47
+ /**
48
+ * VitePress source directory — the directory containing your `.md` files
49
+ * (i.e. the `docs/` folder). Required when calling `generateOpenSpecPages()`
50
+ * at config evaluation time so it knows where to write the generated files.
51
+ *
52
+ * @default process.cwd()
53
+ * @example path.resolve(__dirname, '..') // from docs/.vitepress/config.ts
54
+ */
55
+ srcDir?: string;
56
+ }
57
+ /**
58
+ * A canonical capability specification from openspec/specs/<name>/spec.md
59
+ */
60
+ interface CapabilitySpec {
61
+ /** Folder name (kebab-case capability identifier) */
62
+ name: string;
63
+ /** Optional display title from spec.md frontmatter. Overrides humanized name. */
64
+ title?: string;
65
+ /** Absolute path to the spec.md file */
66
+ specPath: string;
67
+ /** Raw Markdown content of the spec */
68
+ content: string;
69
+ }
70
+ /**
71
+ * A single artifact (file) belonging to a Change.
72
+ */
73
+ type ChangeArtifact = 'proposal' | 'design' | 'tasks';
74
+ /**
75
+ * An OpenSpec change (active or archived).
76
+ */
77
+ interface Change {
78
+ /** Change directory name (e.g. "my-feature" or for archived: "my-feature" extracted from "2026-03-10-my-feature") */
79
+ name: string;
80
+ /** Optional display title from .openspec.yaml. Overrides humanized name. */
81
+ title?: string;
82
+ /** Absolute path to the change directory */
83
+ dir: string;
84
+ /** Which artifact files are present */
85
+ artifacts: ChangeArtifact[];
86
+ /** Creation date from .openspec.yaml, if available */
87
+ createdDate?: string;
88
+ /** For archived changes: the archive date (YYYY-MM-DD) parsed from directory name */
89
+ archivedDate?: string;
90
+ /**
91
+ * For archived changes: the original archive folder name (e.g. "2026-01-15-my-feature" or
92
+ * "legacy-feature" for non-standard names). Used to build correct archive URLs.
93
+ */
94
+ archiveFolderName?: string;
95
+ }
96
+ /**
97
+ * The full parsed structure of an openspec/ directory.
98
+ */
99
+ interface OpenSpecFolder {
100
+ /** Absolute path to the openspec/ root */
101
+ dir: string;
102
+ /** Canonical capability specs from openspec/specs/ */
103
+ specs: CapabilitySpec[];
104
+ /** Active changes from openspec/changes/ (excluding archive/) */
105
+ changes: Change[];
106
+ /** Archived changes from openspec/changes/archive/ */
107
+ archivedChanges: Change[];
108
+ }
109
+ /**
110
+ * A nav item compatible with VitePress `DefaultTheme.NavItem`.
111
+ */
112
+ interface NavItem {
113
+ text: string;
114
+ link: string;
115
+ }
116
+ /**
117
+ * A sidebar item compatible with VitePress `DefaultTheme.SidebarItem`.
118
+ */
119
+ interface SidebarItem {
120
+ text: string;
121
+ link?: string;
122
+ collapsed?: boolean;
123
+ items?: SidebarItem[];
124
+ }
125
+
126
+ /**
127
+ * Synchronously generates all VitePress Markdown pages from the openspec/
128
+ * directory and writes them to disk.
129
+ *
130
+ * Call this at the top of your `docs/.vitepress/config.ts` **before**
131
+ * `defineConfig()` so the files exist when VitePress scans the source
132
+ * directory for routes.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * // docs/.vitepress/config.ts
137
+ * import { defineConfig } from 'vitepress'
138
+ * import path from 'node:path'
139
+ * import { fileURLToPath } from 'node:url'
140
+ * import openspec, { generateOpenSpecPages } from 'vitepress-plugin-openspec'
141
+ *
142
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url))
143
+ * const specDir = path.resolve(__dirname, '../../openspec')
144
+ *
145
+ * // Generate pages before VitePress scans srcDir for routes
146
+ * generateOpenSpecPages({ specDir, outDir: 'openspec', srcDir: path.resolve(__dirname, '..') })
147
+ *
148
+ * export default defineConfig({ ... })
149
+ * ```
150
+ */
151
+ declare function generateOpenSpecPages(userOptions?: OpenSpecPluginOptions): void;
152
+ /**
153
+ * VitePress plugin that reads an openspec/ directory and generates structured
154
+ * Markdown documentation pages inside the VitePress source directory.
155
+ *
156
+ * For the pages to be available on the first build (including CI), also call
157
+ * `generateOpenSpecPages()` at the top of your `config.ts` before `defineConfig`.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // .vitepress/config.ts
162
+ * import { defineConfig } from 'vitepress'
163
+ * import openspec, { generateOpenSpecPages } from 'vitepress-plugin-openspec'
164
+ *
165
+ * generateOpenSpecPages({ specDir, outDir: 'openspec', srcDir: path.resolve(__dirname, '..') })
166
+ *
167
+ * export default defineConfig({
168
+ * vite: { plugins: [openspec({ specDir: './openspec', outDir: 'project-docs' })] },
169
+ * })
170
+ * ```
171
+ */
172
+ declare function openspec(userOptions?: OpenSpecPluginOptions): Plugin;
173
+ /**
174
+ * One-call VitePress config helper that wires up the full openspec integration.
175
+ *
176
+ * Calls `generateOpenSpecPages()` synchronously (required before VitePress scans
177
+ * for routes), then merges the openspec Vite plugin, nav entry, and sidebar section
178
+ * into the provided config object.
179
+ *
180
+ * Other Vite plugins go into `vite.plugins` as usual — `withOpenSpec` appends to
181
+ * the array without replacing it:
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * // docs/.vitepress/config.ts
186
+ * import { defineConfig } from 'vitepress'
187
+ * import { withOpenSpec } from 'vitepress-plugin-openspec'
188
+ *
189
+ * export default defineConfig(
190
+ * withOpenSpec({
191
+ * vite: { plugins: [myOtherPlugin()] }, // other plugins are preserved
192
+ * themeConfig: { nav: [], sidebar: {} },
193
+ * })
194
+ * )
195
+ * ```
196
+ *
197
+ * @param config - Your VitePress `UserConfig` object (same as what `defineConfig` accepts).
198
+ * @param options - OpenSpec options. All fields are optional; defaults match `generateOpenSpecPages`.
199
+ */
200
+ declare function withOpenSpec<T extends Record<string, unknown>>(config: T, options?: WithOpenSpecOptions): T;
201
+
202
+ /**
203
+ * Returns a VitePress sidebar configuration for the OpenSpec documentation.
204
+ * Includes groups for Specifications, active Changes, and archived Changes.
205
+ */
206
+ declare function generateOpenSpecSidebar(specDir: string, options?: {
207
+ outDir?: string;
208
+ }): SidebarItem[];
209
+ /**
210
+ * Returns a VitePress nav entry for the OpenSpec documentation section.
211
+ */
212
+ declare function openspecNav(specDir: string, options?: {
213
+ outDir?: string;
214
+ text?: string;
215
+ }): NavItem | null;
216
+
217
+ export { type CapabilitySpec, type Change, type ChangeArtifact, type NavItem, type OpenSpecFolder, type OpenSpecPluginOptions, type SidebarItem, type WithOpenSpecOptions, openspec as default, generateOpenSpecPages, generateOpenSpecSidebar, openspec, openspecNav, withOpenSpec };
@@ -0,0 +1,217 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * Options for the `withOpenSpec()` config helper.
5
+ * Extends `OpenSpecPluginOptions` with optional nav/sidebar merge controls.
6
+ */
7
+ interface WithOpenSpecOptions extends OpenSpecPluginOptions {
8
+ /**
9
+ * Whether to prepend an openspec nav entry to `themeConfig.nav`.
10
+ * @default true
11
+ */
12
+ nav?: boolean;
13
+ /**
14
+ * Whether to inject the openspec sidebar section into `themeConfig.sidebar`.
15
+ * @default true
16
+ */
17
+ sidebar?: boolean;
18
+ }
19
+ /**
20
+ * Configuration options for the vitepress-plugin-openspec plugin.
21
+ */
22
+ interface OpenSpecPluginOptions {
23
+ /**
24
+ * Path to the openspec/ directory of the project.
25
+ *
26
+ * Use an explicit path when your `openspec/` folder is not at the project root
27
+ * (e.g. when `config.ts` lives inside `docs/.vitepress/`).
28
+ *
29
+ * If the directory does not exist a warning is printed and the build continues
30
+ * without generating any pages or nav/sidebar entries — no error is thrown.
31
+ *
32
+ * @default './openspec'
33
+ * @example
34
+ * // Resolving from docs/.vitepress/config.ts
35
+ * import path from 'node:path'
36
+ * import { fileURLToPath } from 'node:url'
37
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url))
38
+ * const specDir = path.resolve(__dirname, '../../openspec')
39
+ */
40
+ specDir?: string;
41
+ /**
42
+ * Output directory (relative to VitePress `srcDir`) where the generated
43
+ * Markdown pages will be written.
44
+ * @default 'openspec'
45
+ */
46
+ outDir?: string;
47
+ /**
48
+ * VitePress source directory — the directory containing your `.md` files
49
+ * (i.e. the `docs/` folder). Required when calling `generateOpenSpecPages()`
50
+ * at config evaluation time so it knows where to write the generated files.
51
+ *
52
+ * @default process.cwd()
53
+ * @example path.resolve(__dirname, '..') // from docs/.vitepress/config.ts
54
+ */
55
+ srcDir?: string;
56
+ }
57
+ /**
58
+ * A canonical capability specification from openspec/specs/<name>/spec.md
59
+ */
60
+ interface CapabilitySpec {
61
+ /** Folder name (kebab-case capability identifier) */
62
+ name: string;
63
+ /** Optional display title from spec.md frontmatter. Overrides humanized name. */
64
+ title?: string;
65
+ /** Absolute path to the spec.md file */
66
+ specPath: string;
67
+ /** Raw Markdown content of the spec */
68
+ content: string;
69
+ }
70
+ /**
71
+ * A single artifact (file) belonging to a Change.
72
+ */
73
+ type ChangeArtifact = 'proposal' | 'design' | 'tasks';
74
+ /**
75
+ * An OpenSpec change (active or archived).
76
+ */
77
+ interface Change {
78
+ /** Change directory name (e.g. "my-feature" or for archived: "my-feature" extracted from "2026-03-10-my-feature") */
79
+ name: string;
80
+ /** Optional display title from .openspec.yaml. Overrides humanized name. */
81
+ title?: string;
82
+ /** Absolute path to the change directory */
83
+ dir: string;
84
+ /** Which artifact files are present */
85
+ artifacts: ChangeArtifact[];
86
+ /** Creation date from .openspec.yaml, if available */
87
+ createdDate?: string;
88
+ /** For archived changes: the archive date (YYYY-MM-DD) parsed from directory name */
89
+ archivedDate?: string;
90
+ /**
91
+ * For archived changes: the original archive folder name (e.g. "2026-01-15-my-feature" or
92
+ * "legacy-feature" for non-standard names). Used to build correct archive URLs.
93
+ */
94
+ archiveFolderName?: string;
95
+ }
96
+ /**
97
+ * The full parsed structure of an openspec/ directory.
98
+ */
99
+ interface OpenSpecFolder {
100
+ /** Absolute path to the openspec/ root */
101
+ dir: string;
102
+ /** Canonical capability specs from openspec/specs/ */
103
+ specs: CapabilitySpec[];
104
+ /** Active changes from openspec/changes/ (excluding archive/) */
105
+ changes: Change[];
106
+ /** Archived changes from openspec/changes/archive/ */
107
+ archivedChanges: Change[];
108
+ }
109
+ /**
110
+ * A nav item compatible with VitePress `DefaultTheme.NavItem`.
111
+ */
112
+ interface NavItem {
113
+ text: string;
114
+ link: string;
115
+ }
116
+ /**
117
+ * A sidebar item compatible with VitePress `DefaultTheme.SidebarItem`.
118
+ */
119
+ interface SidebarItem {
120
+ text: string;
121
+ link?: string;
122
+ collapsed?: boolean;
123
+ items?: SidebarItem[];
124
+ }
125
+
126
+ /**
127
+ * Synchronously generates all VitePress Markdown pages from the openspec/
128
+ * directory and writes them to disk.
129
+ *
130
+ * Call this at the top of your `docs/.vitepress/config.ts` **before**
131
+ * `defineConfig()` so the files exist when VitePress scans the source
132
+ * directory for routes.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * // docs/.vitepress/config.ts
137
+ * import { defineConfig } from 'vitepress'
138
+ * import path from 'node:path'
139
+ * import { fileURLToPath } from 'node:url'
140
+ * import openspec, { generateOpenSpecPages } from 'vitepress-plugin-openspec'
141
+ *
142
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url))
143
+ * const specDir = path.resolve(__dirname, '../../openspec')
144
+ *
145
+ * // Generate pages before VitePress scans srcDir for routes
146
+ * generateOpenSpecPages({ specDir, outDir: 'openspec', srcDir: path.resolve(__dirname, '..') })
147
+ *
148
+ * export default defineConfig({ ... })
149
+ * ```
150
+ */
151
+ declare function generateOpenSpecPages(userOptions?: OpenSpecPluginOptions): void;
152
+ /**
153
+ * VitePress plugin that reads an openspec/ directory and generates structured
154
+ * Markdown documentation pages inside the VitePress source directory.
155
+ *
156
+ * For the pages to be available on the first build (including CI), also call
157
+ * `generateOpenSpecPages()` at the top of your `config.ts` before `defineConfig`.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // .vitepress/config.ts
162
+ * import { defineConfig } from 'vitepress'
163
+ * import openspec, { generateOpenSpecPages } from 'vitepress-plugin-openspec'
164
+ *
165
+ * generateOpenSpecPages({ specDir, outDir: 'openspec', srcDir: path.resolve(__dirname, '..') })
166
+ *
167
+ * export default defineConfig({
168
+ * vite: { plugins: [openspec({ specDir: './openspec', outDir: 'project-docs' })] },
169
+ * })
170
+ * ```
171
+ */
172
+ declare function openspec(userOptions?: OpenSpecPluginOptions): Plugin;
173
+ /**
174
+ * One-call VitePress config helper that wires up the full openspec integration.
175
+ *
176
+ * Calls `generateOpenSpecPages()` synchronously (required before VitePress scans
177
+ * for routes), then merges the openspec Vite plugin, nav entry, and sidebar section
178
+ * into the provided config object.
179
+ *
180
+ * Other Vite plugins go into `vite.plugins` as usual — `withOpenSpec` appends to
181
+ * the array without replacing it:
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * // docs/.vitepress/config.ts
186
+ * import { defineConfig } from 'vitepress'
187
+ * import { withOpenSpec } from 'vitepress-plugin-openspec'
188
+ *
189
+ * export default defineConfig(
190
+ * withOpenSpec({
191
+ * vite: { plugins: [myOtherPlugin()] }, // other plugins are preserved
192
+ * themeConfig: { nav: [], sidebar: {} },
193
+ * })
194
+ * )
195
+ * ```
196
+ *
197
+ * @param config - Your VitePress `UserConfig` object (same as what `defineConfig` accepts).
198
+ * @param options - OpenSpec options. All fields are optional; defaults match `generateOpenSpecPages`.
199
+ */
200
+ declare function withOpenSpec<T extends Record<string, unknown>>(config: T, options?: WithOpenSpecOptions): T;
201
+
202
+ /**
203
+ * Returns a VitePress sidebar configuration for the OpenSpec documentation.
204
+ * Includes groups for Specifications, active Changes, and archived Changes.
205
+ */
206
+ declare function generateOpenSpecSidebar(specDir: string, options?: {
207
+ outDir?: string;
208
+ }): SidebarItem[];
209
+ /**
210
+ * Returns a VitePress nav entry for the OpenSpec documentation section.
211
+ */
212
+ declare function openspecNav(specDir: string, options?: {
213
+ outDir?: string;
214
+ text?: string;
215
+ }): NavItem | null;
216
+
217
+ export { type CapabilitySpec, type Change, type ChangeArtifact, type NavItem, type OpenSpecFolder, type OpenSpecPluginOptions, type SidebarItem, type WithOpenSpecOptions, openspec as default, generateOpenSpecPages, generateOpenSpecSidebar, openspec, openspecNav, withOpenSpec };