@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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +4605 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
- package/src/const.ts +7 -0
- package/src/declarations.d.ts +29 -0
- package/src/index.ts +386 -0
- package/src/pages/context.tsx +9 -0
- package/src/pages/layout.tsx +340 -0
- package/src/pages/metatags.ts +96 -0
- package/src/pages/page.tsx +463 -0
- package/src/presets/docs/index.ts +317 -0
- package/src/presets/docs/settings.ts +262 -0
- package/src/presets/graphql/index.ts +69 -0
- package/src/presets/openapi/index.ts +66 -0
- package/src/presets/sources/index.ts +74 -0
- package/src/presets/uniform/index.ts +832 -0
- package/src/types.ts +40 -0
- package/src/utils.ts +19 -0
|
@@ -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
|
+
|