@openpkg-ts/adapters 0.2.2 → 0.3.1

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/README.md CHANGED
@@ -2,6 +2,44 @@
2
2
 
3
3
  Framework adapters for OpenPkg API documentation.
4
4
 
5
+ ## Adapter Registry
6
+
7
+ Self-registering adapter pattern for extensibility.
8
+
9
+ ```typescript
10
+ import { registerAdapter, getAdapter, listAdapters } from '@openpkg-ts/adapters';
11
+
12
+ // List available adapters
13
+ const adapters = listAdapters();
14
+
15
+ // Get adapter by id
16
+ const fumadocs = getAdapter('fumadocs');
17
+ await fumadocs.generate(spec, './docs/api');
18
+ ```
19
+
20
+ ### Creating Custom Adapters
21
+
22
+ ```typescript
23
+ import { registerAdapter, type DocAdapter } from '@openpkg-ts/adapters';
24
+
25
+ const myAdapter: DocAdapter = {
26
+ id: 'my-adapter',
27
+ name: 'My Adapter',
28
+ generate: async (spec, outDir) => {
29
+ // Generate docs to outDir
30
+ },
31
+ };
32
+
33
+ registerAdapter(myAdapter);
34
+ ```
35
+
36
+ ### CLI Integration
37
+
38
+ ```bash
39
+ # Use adapter via CLI
40
+ openpkg docs openpkg.json --adapter fumadocs -o docs/api/
41
+ ```
42
+
5
43
  ## Fumadocs
6
44
 
7
45
  ```bash
@@ -20,6 +58,8 @@ export const apiSource = loader({
20
58
  });
21
59
  ```
22
60
 
61
+ Self-registers on import - no manual registration needed.
62
+
23
63
  ### CSS
24
64
 
25
65
  ```css
@@ -41,6 +81,12 @@ import { SidebarKindBadge } from '@openpkg-ts/adapters/fumadocs/components';
41
81
  | `mode` | `'pages' \| 'single'` | `'pages'` | Navigation mode |
42
82
  | `indexPage` | `boolean` | `true` | Generate index page |
43
83
 
84
+ ## Types
85
+
86
+ ```typescript
87
+ import type { DocAdapter } from '@openpkg-ts/adapters';
88
+ ```
89
+
44
90
  ## Future Adapters
45
91
 
46
92
  - `@openpkg-ts/adapters/docusaurus` (planned)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SidebarKindBadge
3
- } from "../shared/chunk-t3t704xs.js";
3
+ } from "../../shared/chunk-t3t704xs.js";
4
4
  export {
5
5
  SidebarKindBadge
6
6
  };
@@ -1,11 +1,17 @@
1
+ import {
2
+ registerAdapter
3
+ } from "../registry.js";
1
4
  import {
2
5
  SidebarKindBadge
3
- } from "./shared/chunk-t3t704xs.js";
6
+ } from "../shared/chunk-t3t704xs.js";
4
7
 
5
8
  // src/fumadocs/index.ts
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+ import { createDocs as createDocs2 } from "@openpkg-ts/sdk";
6
12
  import {
7
13
  buildSignatureString,
8
- createDocs as createDocs2,
14
+ createDocs as createDocs3,
9
15
  exportToMarkdown,
10
16
  formatParameters,
11
17
  formatReturnType,
@@ -198,6 +204,25 @@ function openpkgSource(options) {
198
204
  }
199
205
  return { files };
200
206
  }
207
+
208
+ // src/fumadocs/index.ts
209
+ var fumadocsAdapter = {
210
+ id: "fumadocs",
211
+ name: "Fumadocs",
212
+ generate: async (spec, outDir) => {
213
+ const docs = createDocs2(spec);
214
+ const exports = docs.getAllExports();
215
+ if (!fs.existsSync(outDir)) {
216
+ fs.mkdirSync(outDir, { recursive: true });
217
+ }
218
+ for (const exp of exports) {
219
+ const content = docs.toMarkdown({ export: exp.id, frontmatter: true, codeSignatures: true });
220
+ const filename = `${exp.name}.md`;
221
+ fs.writeFileSync(path.join(outDir, filename), content);
222
+ }
223
+ }
224
+ };
225
+ registerAdapter(fumadocsAdapter);
201
226
  export {
202
227
  toSearchIndexJSON,
203
228
  toSearchIndex,
@@ -225,7 +250,7 @@ export {
225
250
  formatReturnType,
226
251
  formatParameters,
227
252
  exportToMarkdown,
228
- createDocs2 as createDocs,
253
+ createDocs3 as createDocs,
229
254
  buildSignatureString,
230
255
  SidebarKindBadge,
231
256
  SidebarKindBadge as KindBadge
@@ -0,0 +1,26 @@
1
+ import { OpenPkg } from "@openpkg-ts/spec";
2
+ /**
3
+ * Doc adapter interface for extensible documentation generation.
4
+ */
5
+ interface DocAdapter {
6
+ /** Unique adapter identifier */
7
+ id: string;
8
+ /** Human-readable name */
9
+ name: string;
10
+ /** Generate documentation to output directory */
11
+ generate: (spec: OpenPkg, outDir: string) => Promise<void>;
12
+ }
13
+ /**
14
+ * Register a documentation adapter.
15
+ */
16
+ declare function registerAdapter(adapter: DocAdapter): void;
17
+ /**
18
+ * Get an adapter by ID.
19
+ * @returns The adapter or undefined if not found
20
+ */
21
+ declare function getAdapter(id: string): DocAdapter | undefined;
22
+ /**
23
+ * List all registered adapters.
24
+ */
25
+ declare function listAdapters(): DocAdapter[];
26
+ export { registerAdapter, listAdapters, getAdapter, DocAdapter };
@@ -0,0 +1,18 @@
1
+ // src/registry.ts
2
+ var registry = new Map;
3
+ function registerAdapter(adapter) {
4
+ registry.set(adapter.id, adapter);
5
+ }
6
+ function getAdapter(id) {
7
+ return registry.get(id);
8
+ }
9
+ function listAdapters() {
10
+ return Array.from(registry.values());
11
+ }
12
+ export {
13
+ registerAdapter,
14
+ listAdapters,
15
+ getAdapter
16
+ };
17
+
18
+ export { registerAdapter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/adapters",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Framework adapters for OpenPkg - Fumadocs, Docusaurus, Mintlify, etc.",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -20,9 +20,13 @@
20
20
  "author": "Ryan Waits",
21
21
  "type": "module",
22
22
  "exports": {
23
+ ".": {
24
+ "import": "./src/registry.ts",
25
+ "types": "./src/registry.ts"
26
+ },
23
27
  "./fumadocs": {
24
- "import": "./dist/index.js",
25
- "types": "./dist/index.d.ts"
28
+ "import": "./src/fumadocs/index.ts",
29
+ "types": "./src/fumadocs/index.ts"
26
30
  },
27
31
  "./fumadocs/components": {
28
32
  "import": "./dist/components/index.js",
@@ -41,8 +45,8 @@
41
45
  "typecheck": "tsc --noEmit"
42
46
  },
43
47
  "dependencies": {
44
- "@openpkg-ts/sdk": "^0.30.2",
45
- "@openpkg-ts/spec": "^0.27.1",
48
+ "@openpkg-ts/sdk": "^0.32.0",
49
+ "@openpkg-ts/spec": "^0.32.0",
46
50
  "@openpkg-ts/ui": "^0.1.2"
47
51
  },
48
52
  "peerDependencies": {
File without changes