@xyd-js/cli 0.1.0-xyd.22 → 0.1.0-xyd.24

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/.cli/package.json DELETED
@@ -1,37 +0,0 @@
1
- {
2
- "private": true,
3
- "name": "@xyd-js/documan-host",
4
- "version": "0.0.0",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "bin": {
8
- "xyd": "bin.js"
9
- },
10
- "scripts": {},
11
- "dependencies": {
12
- "@xyd-js/theme-poetry": "0.1.0-xyd.17",
13
- "@xyd-js/react-router-dev": "7.1.1-xyd.3",
14
- "@readme/oas-to-snippet": "^26.0.1",
15
- "@react-router/node": "7.1.1",
16
- "@react-router/serve": "7.1.1",
17
- "@react-router/dev": "7.1.1",
18
- "react-router": "7.1.1",
19
- "isbot": "^5",
20
- "remark-frontmatter": "^5.0.0",
21
- "remark-mdx-frontmatter": "^5.0.0",
22
- "json-to-graphql-query": "^2.3.0",
23
- "remark": "^15.0.1",
24
- "unist-builder": "^4.0.0",
25
- "oas": "^25.0.3",
26
- "openapi-sampler": "^1.5.1",
27
- "json-schema-ref-parser": "^9.0.9"
28
- },
29
- "devDependencies": {
30
- "@mdx-js/rollup": "^3.1.0",
31
- "vite": "^5.4.9",
32
- "semver": "^7.6.3",
33
- "vite-tsconfig-paths": "^5.1.4",
34
- "autoprefixer": "^10.4.20",
35
- "postcss": "^8.4.47"
36
- }
37
- }
@@ -1,283 +0,0 @@
1
- import path from "path";
2
- import {promises as fs} from "fs";
3
-
4
- import React, {} from "react";
5
- import {redirect} from "react-router";
6
- import remarkFrontmatter from "remark-frontmatter";
7
- import remarkMdxFrontmatter from "remark-mdx-frontmatter";
8
- import remarkGfm from "remark-gfm";
9
- import {parse} from "codehike";
10
- import {visit} from "unist-util-visit";
11
- import {recmaCodeHike, remarkCodeHike} from "codehike/mdx";
12
- import {compile as mdxCompile} from "@mdx-js/mdx";
13
-
14
- import {PageFrontMatter} from "@xyd-js/core";
15
- import getContentComponents from "@xyd-js/components/content";
16
- import {mapSettingsToProps} from "@xyd-js/framework/hydration";
17
- import {Framework, type FwSidebarGroupProps} from "@xyd-js/framework/react";
18
- import {AtlasLazy} from "@xyd-js/atlas";
19
- import type {IBreadcrumb, INavLinks} from "@xyd-js/ui";
20
-
21
- import Theme from "virtual:xyd-theme" // TODO: for some reasons this cannot be hydrated by react-router
22
- import settings from 'virtual:xyd-settings';
23
-
24
- import "virtual:xyd-theme/index.css"
25
- import "virtual:xyd-theme-override/index.css"
26
-
27
- interface loaderData {
28
- sidebarGroups: FwSidebarGroupProps[]
29
- breadcrumbs: IBreadcrumb[],
30
- navlinks?: INavLinks,
31
- toc: PageFrontMatter
32
- slug: string
33
- code: string
34
- }
35
-
36
- const contentComponents = getContentComponents()
37
- const ComponentContent = contentComponents.Content
38
-
39
- // since unist does not support heading level > 6, we need to normalize them
40
- function normalizeCustomHeadings() {
41
- return (tree: any) => {
42
- visit(tree, 'paragraph', (node, index, parent) => {
43
- if (!node.children[0].value) {
44
- return
45
- }
46
- const match = node.children[0] && node.children[0].value.match(/^(#+)\s+(.*)/);
47
- if (match) {
48
- const level = match[1].length;
49
- const text = match[2];
50
- if (level > 6) {
51
- // Create a new heading node with depth 6
52
- const headingNode = {
53
- type: 'heading',
54
- depth: level,
55
- children: [{type: 'text', value: text}]
56
- };
57
- // Replace the paragraph node with the new heading node
58
- //@ts-ignore
59
- parent.children[index] = headingNode;
60
- }
61
- }
62
- });
63
- };
64
- }
65
-
66
- const codeHikeOptions = {
67
- lineNumbers: true,
68
- showCopyButton: true,
69
- autoImport: true,
70
- components: {},
71
- // syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??
72
- // theme: "github-dark",
73
- // },
74
- };
75
-
76
- const compiledBySlug = {}
77
-
78
- // TODO: map every file and merge them or load via client-side ?
79
- async function compileBySlug(slug: string) {
80
- if (compiledBySlug[slug]) {
81
- return compiledBySlug[slug]
82
- }
83
- console.time("api-reference compileBySlug")
84
- // TODO: cwd ?
85
- let filePath = path.join(process.cwd(), `${slug}.md`)
86
-
87
- try {
88
- await fs.access(filePath)
89
- } catch (_) {
90
- filePath = path.join(process.cwd(), `${slug}.mdx`)
91
-
92
- await fs.access(filePath)
93
- }
94
-
95
- console.time("api-reference readFile")
96
- const content = await fs.readFile(filePath, "utf-8");
97
- console.timeEnd("api-reference readFile")
98
-
99
- console.time("api-reference compile")
100
- const resp = await compile(content)
101
- console.timeEnd("api-reference compile")
102
-
103
- console.timeEnd("api-reference compileBySlug")
104
- compiledBySlug[slug] = resp
105
- return resp
106
- }
107
-
108
- async function compile(content: string): Promise<string> {
109
- const compiled = await mdxCompile(content, {
110
- remarkPlugins: [
111
- normalizeCustomHeadings,
112
- [
113
- remarkCodeHike,
114
- codeHikeOptions
115
- ],
116
- remarkFrontmatter,
117
- remarkMdxFrontmatter,
118
- remarkGfm
119
- ],
120
- rehypePlugins: [],
121
- recmaPlugins: [
122
- [
123
- recmaCodeHike,
124
- codeHikeOptions
125
- ]
126
- ],
127
- outputFormat: 'function-body',
128
- development: false,
129
- });
130
-
131
- return String(compiled)
132
- }
133
-
134
- interface loaderData {
135
- sidebarGroups: FwSidebarGroupProps[]
136
- toc: PageFrontMatter
137
- slug: string
138
- code: string
139
- }
140
-
141
- function getPathname(url: string) {
142
- const parsedUrl = new URL(url);
143
- return parsedUrl.pathname.replace(/^\//, '');
144
- }
145
-
146
- // TODO: fix any
147
- function findFirstUrl(items: any): string {
148
- const queue = [...items];
149
-
150
- while (queue.length > 0) {
151
- const item = queue.shift();
152
-
153
- if (item.href) {
154
- return item.href;
155
- }
156
-
157
- if (item.items) {
158
- queue.push(...item.items);
159
- }
160
- }
161
-
162
- return "";
163
- }
164
-
165
- interface data {
166
- groups: FwSidebarGroupProps[],
167
- breadcrumbs: IBreadcrumb[]
168
- navlinks?: INavLinks
169
- }
170
-
171
- const mapSettingsToPropsMap: { [key: string]: data } = {}
172
-
173
- // TODO: fix any
174
- export async function loader({request}: { request: any }) {
175
- console.time("api-reference loader")
176
- const slug = getPathname(request.url);
177
-
178
- let code = "";
179
- let error: any;
180
-
181
- try {
182
- code = await compileBySlug(slug);
183
- } catch (e) {
184
- error = e;
185
- }
186
- let data: data
187
-
188
- if (!mapSettingsToPropsMap[slug]) {
189
- data = await mapSettingsToProps(
190
- settings,
191
- slug
192
- );
193
- mapSettingsToPropsMap[slug] = data
194
- } else {
195
- data = mapSettingsToPropsMap[slug]
196
- }
197
-
198
- const {groups: sidebarGroups, breadcrumbs, navlinks} = data;
199
-
200
- if (error) {
201
- if (sidebarGroups && error.code === "ENOENT") {
202
- const firstItem = findFirstUrl(sidebarGroups?.[0]?.items);
203
-
204
- if (firstItem) {
205
- return redirect(firstItem);
206
- }
207
- }
208
-
209
- console.error(error);
210
- }
211
-
212
- console.timeEnd("api-reference loader")
213
- return {
214
- sidebarGroups,
215
- breadcrumbs,
216
- navlinks,
217
- slug,
218
- code,
219
- } as loaderData;
220
- }
221
-
222
- function mdxExport(code: string) {
223
- const scope = {
224
- Fragment: React.Fragment,
225
- jsxs: React.createElement,
226
- jsx: React.createElement,
227
- jsxDEV: React.createElement,
228
- }
229
- const fn = new Function(...Object.keys(scope), code)
230
- return fn(scope)
231
- }
232
-
233
- function MemoMDXComponent(codeComponent: any) {
234
- return React.useMemo(
235
- () => codeComponent ? codeComponent : null,
236
- [codeComponent]
237
- )
238
- }
239
-
240
- // // TODO: move to content?
241
- function mdxContent(code: string) {
242
- const content = mdxExport(code) // TODO: fix any
243
- if (!mdxExport) {
244
- return {}
245
- }
246
-
247
- return {
248
- component: content?.default,
249
- }
250
- }
251
-
252
- // TODO: in the future more smoother loader - first fast server render then move to ideal position of client and then replace and 3 items at start
253
- export default function APIReference({loaderData}: { loaderData: loaderData }) {
254
- const content = mdxContent(loaderData.code)
255
- const serverComponent = content ? parse(content.component, {
256
- components: contentComponents
257
- }) : null
258
-
259
- const memoizedServerComponent = MemoMDXComponent(serverComponent)
260
-
261
- return <Framework
262
- settings={settings}
263
- sidebarGroups={loaderData.sidebarGroups || []}
264
- breadcrumbs={loaderData.breadcrumbs || []}
265
- navlinks={loaderData.navlinks}
266
- >
267
- <Theme
268
- themeSettings={{
269
- hideToc: true,
270
- bigArticle: true,
271
- sidebar: {
272
- clientSideRouting: true
273
- }
274
- }}
275
- >
276
- <AtlasLazy
277
- references={memoizedServerComponent?.references || []}
278
- slug={loaderData.slug.startsWith("/") ? loaderData.slug : `/${loaderData.slug}`}
279
- urlPrefix="/"
280
- />
281
- </Theme>
282
- </Framework>
283
- }
@@ -1,175 +0,0 @@
1
- import path from "node:path";
2
-
3
- import React from "react";
4
- import {redirect} from "react-router";
5
-
6
- import {PageFrontMatter} from "@xyd-js/core"
7
- import {compileBySlug} from "@xyd-js/content"
8
- import {mapSettingsToProps} from "@xyd-js/framework/hydration";
9
- import {Framework, FwNav, type FwSidebarGroupProps} from "@xyd-js/framework/react";
10
- import getContentComponents from "@xyd-js/components/content";
11
- import {HomePage} from "@xyd-js/components/pages";
12
- import type {IBreadcrumb, INavLinks} from "@xyd-js/ui";
13
-
14
- import settings from 'virtual:xyd-settings';
15
- import Theme from "virtual:xyd-theme";
16
-
17
- import "virtual:xyd-theme/index.css"
18
- import "virtual:xyd-theme-override/index.css"
19
-
20
- interface loaderData {
21
- sidebarGroups: FwSidebarGroupProps[]
22
- breadcrumbs: IBreadcrumb[],
23
- navlinks?: INavLinks,
24
- toc: PageFrontMatter
25
- slug: string
26
- code: string
27
- }
28
-
29
- const contentComponents = getContentComponents()
30
-
31
- const supportedExtensions = {
32
- ".mdx": true,
33
- ".md": true,
34
- "": true,
35
- }
36
-
37
- function getPathname(url: string) {
38
- const parsedUrl = new URL(url);
39
- return parsedUrl.pathname.replace(/^\//, '');
40
- }
41
-
42
- export async function loader({request}: { request: any }) {
43
- const slug = getPathname(request.url || "index") || "index"
44
- const ext = path.extname(slug)
45
-
46
- if (!supportedExtensions[ext]) {
47
- return {}
48
- }
49
-
50
- // TODO: in the future map instead of arr
51
- if (settings.redirects && settings.redirects.length) {
52
- for (const item of settings.redirects) {
53
- if (item.source === getPathname(request.url)) {
54
- return redirect(item.destination)
55
- }
56
- }
57
- }
58
-
59
- let code = ""
60
- let error: any
61
-
62
- try {
63
- code = await compileBySlug(slug, true)
64
- } catch (e) {
65
- error = e
66
- }
67
-
68
- if (error?.code === "ENOENT") {
69
- try {
70
- // TODO: better index algorithm
71
- code = await compileBySlug(slug + "/index", true)
72
- } catch (e) {
73
- error = e
74
- }
75
- }
76
-
77
- const {
78
- groups: sidebarGroups,
79
- breadcrumbs,
80
- navlinks,
81
- } = await mapSettingsToProps(
82
- settings,
83
- slug
84
- )
85
-
86
- if (error) {
87
- if (sidebarGroups && error.code === "ENOENT") {
88
- const firstItem = sidebarGroups?.[0]?.items?.[0]
89
-
90
- if (firstItem) {
91
- return redirect(firstItem.href)
92
- }
93
- }
94
-
95
- console.error(error)
96
- }
97
-
98
- console.timeEnd("docs loader")
99
- return {
100
- sidebarGroups,
101
- breadcrumbs,
102
- navlinks,
103
- slug,
104
- code,
105
- } as loaderData
106
- }
107
-
108
- // TODO: move to content?
109
- function mdxExport(code: string) {
110
- const scope = {
111
- Fragment: React.Fragment,
112
- jsxs: React.createElement,
113
- jsx: React.createElement,
114
- jsxDEV: React.createElement,
115
- }
116
- const fn = new Function(...Object.keys(scope), code)
117
- return fn(scope)
118
- }
119
-
120
- // // TODO: move to content?
121
- function mdxContent(code: string) {
122
- const content = mdxExport(code) // TODO: fix any
123
- if (!mdxExport) {
124
- return {}
125
- }
126
-
127
- return {
128
- component: content?.default,
129
- toc: content?.toc,
130
- frontmatter: content?.frontmatter,
131
- themeSettings: content?.themeSettings || {},
132
- page: content?.page || false,
133
- }
134
- }
135
-
136
- export function MemoMDXComponent(codeComponent: any) {
137
- return React.useMemo(
138
- () => codeComponent ? codeComponent : null,
139
- [codeComponent]
140
- )
141
- }
142
-
143
- export default function CustomPage({loaderData, ...rest}: { loaderData: loaderData }) {
144
- const content = mdxContent(loaderData.code)
145
- const Component = MemoMDXComponent(content.component)
146
-
147
- return <Framework
148
- settings={settings}
149
- sidebarGroups={loaderData.sidebarGroups || []}
150
- toc={content.toc || []}
151
- breadcrumbs={loaderData.breadcrumbs || []}
152
- navlinks={loaderData.navlinks}
153
- >
154
- {content?.page ? <Component components={{
155
- ...contentComponents,
156
- // TODO: another page components
157
- HomePage: (props) => <HomePage
158
- {...props}
159
- // TODO: get props from theme about nav (middle etc)
160
- // TODO: footer
161
- // TODO: style
162
- header={<div style={{marginLeft: "var(--xyd-global-page-gutter)"}}>
163
- <FwNav kind="middle"/>
164
- </div>}
165
-
166
- >
167
- {props.children}
168
- </HomePage>,
169
- }}/> : <Theme
170
- themeSettings={content.themeSettings}
171
- >
172
- {Component ? <Component components={contentComponents}/> : <></>}
173
- </Theme>}
174
- </Framework>
175
- }
@@ -1,37 +0,0 @@
1
- import {
2
- Links,
3
- Meta,
4
- Outlet,
5
- Scripts,
6
- } from "react-router";
7
-
8
- // TODO: config from core settings
9
- export const meta = () => {
10
- return [
11
- {
12
- title: "xyd"
13
- }
14
- ]
15
- }
16
-
17
- export const Layout = ({children}: { children: React.ReactNode }) => {
18
- return (
19
- <html>
20
- <head>
21
- <meta charSet="utf-8"/>
22
- <meta name="viewport" content="width=device-width, initial-scale=1"/>
23
- <Meta/>
24
- <Links/>
25
- </head>
26
- <body>
27
- {children}
28
- <Scripts/>
29
- </body>
30
- </html>
31
- )
32
- }
33
-
34
- export default function App() {
35
- return <Outlet/>
36
- }
37
-