@xyd-js/plugin-docs 0.1.0-build.160

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,66 @@
1
+ import {Settings} from "@xyd-js/core";
2
+ import {deferencedOpenAPI, oapSchemaToReferences, getXDocs} from "@xyd-js/openapi";
3
+ import type {Reference} from "@xyd-js/uniform";
4
+
5
+ import {Preset} from "../../types"
6
+ import {UniformPreset} from "../uniform"
7
+
8
+ export interface openapiPresetOptions {
9
+ urlPrefix?: string
10
+ root?: string
11
+ disableFSWrite?: boolean
12
+ }
13
+
14
+ function preset(
15
+ settings: Settings,
16
+ options: openapiPresetOptions
17
+ ) {
18
+ return OpenAPIUniformPreset.new(settings, options)
19
+ }
20
+
21
+ export const openapiPreset = preset satisfies Preset<unknown>
22
+
23
+ class OpenAPIUniformPreset extends UniformPreset {
24
+ private constructor(
25
+ settings: Settings,
26
+ options: {
27
+ disableFSWrite?: boolean
28
+ }
29
+ ) {
30
+ super(
31
+ "openapi",
32
+ settings.api?.openapi || "",
33
+ settings?.navigation?.sidebar || [],
34
+ options.disableFSWrite
35
+ )
36
+ this.uniformRefResolver = this.uniformRefResolver.bind(this)
37
+ }
38
+
39
+ static new(
40
+ settings: Settings,
41
+ options: openapiPresetOptions
42
+ ) {
43
+ return new OpenAPIUniformPreset(settings, {
44
+ disableFSWrite: options.disableFSWrite
45
+ })
46
+ .urlPrefix(options.urlPrefix || "")
47
+ .newUniformPreset()(settings, "openapi")
48
+ }
49
+
50
+ protected override async uniformRefResolver(filePath: string): Promise<Reference[]> {
51
+ if (!filePath) {
52
+ return []
53
+ }
54
+
55
+ const schema = await deferencedOpenAPI(filePath)
56
+ if (schema) {
57
+ const xdocs = getXDocs(schema)
58
+ if (xdocs?.route) {
59
+ this.fileRouting(filePath, xdocs.route)
60
+ }
61
+ }
62
+
63
+ return oapSchemaToReferences(schema)
64
+ }
65
+ }
66
+
@@ -0,0 +1,74 @@
1
+ import path from "path";
2
+ import fs from "fs/promises";
3
+
4
+ import type {Reference} from "@xyd-js/uniform";
5
+ import {Settings} from "@xyd-js/core";
6
+ import {sourcesToUniformV2} from "@xyd-js/sources/ts"
7
+
8
+ import {Preset} from "../../types"
9
+ import {UniformPreset} from "../uniform"
10
+
11
+ export interface sourcesPresetsOptions {
12
+ urlPrefix?: string
13
+ root?: string
14
+ disableFSWrite?: boolean
15
+ }
16
+
17
+ function preset(
18
+ settings: Settings,
19
+ options: sourcesPresetsOptions
20
+ ) {
21
+ return SourceUniformPreset.new(settings, options)
22
+ }
23
+
24
+ export const sourcesPreset = preset satisfies Preset<unknown>
25
+
26
+ class SourceUniformPreset extends UniformPreset {
27
+ private constructor(
28
+ settings: Settings,
29
+ options: {
30
+ disableFSWrite?: boolean
31
+ }
32
+ ) {
33
+ super(
34
+ "sources",
35
+ settings.api?.sources || "",
36
+ settings?.navigation?.sidebar || [],
37
+ options.disableFSWrite
38
+ )
39
+ }
40
+
41
+ static new(
42
+ settings: Settings,
43
+ options: sourcesPresetsOptions
44
+ ) {
45
+ return new SourceUniformPreset(settings, {
46
+ disableFSWrite: options.disableFSWrite
47
+ })
48
+ .urlPrefix(options.urlPrefix || "")
49
+ .sourceTheme(true)
50
+ .newUniformPreset()(settings, "sources")
51
+ }
52
+
53
+ // TODO: options to specify only specific packages?
54
+ protected override async uniformRefResolver(filePath: string): Promise<Reference[]> {
55
+ if (!filePath) {
56
+ return []
57
+ }
58
+
59
+ const packages = await fs.readdir(filePath)
60
+
61
+ const ref = await sourcesToUniformV2(
62
+ filePath,
63
+ packages.map(p => path.join(filePath, p))
64
+ )
65
+
66
+ if (!ref || !ref.references) {
67
+ console.error("Failed to generate documentation.", filePath)
68
+ return []
69
+ }
70
+
71
+ return ref.references
72
+ }
73
+ }
74
+