@xyd-js/documan 0.1.0-xyd.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.
- package/README.md +3 -0
- package/dist/build.d.ts +2 -0
- package/dist/build.js +106 -0
- package/dist/build.js.map +1 -0
- package/dist/dev.d.ts +2 -0
- package/dist/dev.js +96 -0
- package/dist/dev.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +238 -0
- package/dist/index.js.map +1 -0
- package/dist/serve.d.ts +2 -0
- package/dist/serve.js +110 -0
- package/dist/serve.js.map +1 -0
- package/host/.react-router/types/app/+types/root.ts +40 -0
- package/host/app/root.tsx +23 -0
- package/host/app/routes.ts +5 -0
- package/host/node_modules/.vite/deps/@mdx-js_mdx.js +81 -0
- package/host/node_modules/.vite/deps/@mdx-js_mdx.js.map +7 -0
- package/host/node_modules/.vite/deps/@mdx-js_rollup.js +4003 -0
- package/host/node_modules/.vite/deps/@mdx-js_rollup.js.map +7 -0
- package/host/node_modules/.vite/deps/@radix-ui_react-icons.js +7531 -0
- package/host/node_modules/.vite/deps/@radix-ui_react-icons.js.map +7 -0
- package/host/node_modules/.vite/deps/@radix-ui_react-tabs.js +917 -0
- package/host/node_modules/.vite/deps/@radix-ui_react-tabs.js.map +7 -0
- package/host/node_modules/.vite/deps/_metadata.json +157 -0
- package/host/node_modules/.vite/deps/chunk-2TUXWMP5.js +46 -0
- package/host/node_modules/.vite/deps/chunk-2TUXWMP5.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-A76PLWFF.js +23875 -0
- package/host/node_modules/.vite/deps/chunk-A76PLWFF.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-B2TCFXA3.js +27 -0
- package/host/node_modules/.vite/deps/chunk-B2TCFXA3.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-CZACBYAQ.js +3461 -0
- package/host/node_modules/.vite/deps/chunk-CZACBYAQ.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-IVP26VTC.js +21 -0
- package/host/node_modules/.vite/deps/chunk-IVP26VTC.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-NSHFRFAV.js +894 -0
- package/host/node_modules/.vite/deps/chunk-NSHFRFAV.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-O6QCC74R.js +205 -0
- package/host/node_modules/.vite/deps/chunk-O6QCC74R.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-SBIFJFEH.js +894 -0
- package/host/node_modules/.vite/deps/chunk-SBIFJFEH.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-SURLKOJ2.js +12 -0
- package/host/node_modules/.vite/deps/chunk-SURLKOJ2.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-VENRSTQF.js +21628 -0
- package/host/node_modules/.vite/deps/chunk-VENRSTQF.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-XCGROZNW.js +10609 -0
- package/host/node_modules/.vite/deps/chunk-XCGROZNW.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-ZFDQJWTH.js +928 -0
- package/host/node_modules/.vite/deps/chunk-ZFDQJWTH.js.map +7 -0
- package/host/node_modules/.vite/deps/chunk-ZFOARUJI.js +1906 -0
- package/host/node_modules/.vite/deps/chunk-ZFOARUJI.js.map +7 -0
- package/host/node_modules/.vite/deps/gray-matter.js +3492 -0
- package/host/node_modules/.vite/deps/gray-matter.js.map +7 -0
- package/host/node_modules/.vite/deps/lucide-react.js +34742 -0
- package/host/node_modules/.vite/deps/lucide-react.js.map +7 -0
- package/host/node_modules/.vite/deps/package.json +3 -0
- package/host/node_modules/.vite/deps/react-dom.js +7 -0
- package/host/node_modules/.vite/deps/react-dom.js.map +7 -0
- package/host/node_modules/.vite/deps/react-dom_client.js +39 -0
- package/host/node_modules/.vite/deps/react-dom_client.js.map +7 -0
- package/host/node_modules/.vite/deps/react-router.js +243 -0
- package/host/node_modules/.vite/deps/react-router.js.map +7 -0
- package/host/node_modules/.vite/deps/react-router_dom.js +212 -0
- package/host/node_modules/.vite/deps/react-router_dom.js.map +7 -0
- package/host/node_modules/.vite/deps/react.js +6 -0
- package/host/node_modules/.vite/deps/react.js.map +7 -0
- package/host/node_modules/.vite/deps/react_jsx-dev-runtime.js +913 -0
- package/host/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
- package/host/node_modules/.vite/deps/react_jsx-runtime.js +7 -0
- package/host/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
- package/host/node_modules/.vite/deps/remark-frontmatter.js +428 -0
- package/host/node_modules/.vite/deps/remark-frontmatter.js.map +7 -0
- package/host/node_modules/.vite/deps/remark-gfm.js +3122 -0
- package/host/node_modules/.vite/deps/remark-gfm.js.map +7 -0
- package/host/node_modules/.vite/deps/remark-mdx-frontmatter.js +10482 -0
- package/host/node_modules/.vite/deps/remark-mdx-frontmatter.js.map +7 -0
- package/host/node_modules/.vite/deps/unist-util-visit.js +14 -0
- package/host/node_modules/.vite/deps/unist-util-visit.js.map +7 -0
- package/host/node_modules/.vite/deps/vfile.js +8 -0
- package/host/node_modules/.vite/deps/vfile.js.map +7 -0
- package/host/package.json +43 -0
- package/host/postcss.config.cjs +5 -0
- package/host/react-router.config.ts +8 -0
- package/host/tsconfig.json +22 -0
- package/host/vite.config.ts +9 -0
- package/package.json +63 -0
- package/src/commands/build.ts +4 -0
- package/src/commands/dev.ts +5 -0
- package/src/commands/serve.ts +5 -0
- package/src/index.ts +7 -0
- package/src/run/build.ts +98 -0
- package/src/run/dev.ts +76 -0
- package/src/run/index.ts +6 -0
- package/src/run/serve.ts +106 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +81 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"name": "@xyd-js/documan-host",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@xyd-js/atlas": "workspace:*",
|
|
9
|
+
"@xyd-js/core": "workspace:*",
|
|
10
|
+
"@xyd-js/content": "workspace:*",
|
|
11
|
+
"@xyd-js/framework": "workspace:*",
|
|
12
|
+
"@xyd-js/gql": "workspace:*",
|
|
13
|
+
"@xyd-js/openapi": "workspace:*",
|
|
14
|
+
"@xyd-js/uniform": "workspace:*",
|
|
15
|
+
"@xyd-js/theme-gusto": "workspace:*",
|
|
16
|
+
"@react-router/node": "^7.1.1",
|
|
17
|
+
"@react-router/serve": "^7.1.1",
|
|
18
|
+
"codehike": "^1.0.3",
|
|
19
|
+
"express": "^4.21.1",
|
|
20
|
+
"isbot": "^5.1.17",
|
|
21
|
+
"react": "^18.3.1",
|
|
22
|
+
"react-dom": "^18.3.1",
|
|
23
|
+
"react-router": "^7.1.1",
|
|
24
|
+
"remark-frontmatter": "^5.0.0",
|
|
25
|
+
"remark-gfm": "^4.0.0",
|
|
26
|
+
"remark-mdx-frontmatter": "^5.0.0",
|
|
27
|
+
"typescript": "^5.6.3",
|
|
28
|
+
"vfile": "^6.0.3",
|
|
29
|
+
"yaml": "^2.6.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^22.7.5",
|
|
33
|
+
"@types/react-dom": "^18.3.1",
|
|
34
|
+
"@mdx-js/rollup": "^3.1.0",
|
|
35
|
+
"@types/react": "^18.3.9",
|
|
36
|
+
"@vitejs/plugin-react": "^4.3.2",
|
|
37
|
+
"autoprefixer": "^10.4.20",
|
|
38
|
+
"postcss": "^8.4.47",
|
|
39
|
+
"typescript": "^5.6.2",
|
|
40
|
+
"vite": "^5.4.9",
|
|
41
|
+
"vite-tsconfig-paths": "^5.0.1"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ES2020",
|
|
8
|
+
"DOM",
|
|
9
|
+
"DOM.Iterable"
|
|
10
|
+
],
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"noEmit": false,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noUnusedParameters": true,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
"jsx": "react-jsx"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyd-js/documan",
|
|
3
|
+
"version": "0.1.0-xyd.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./package.json": "./package.json",
|
|
7
|
+
".": "./dist/index.js",
|
|
8
|
+
"./dev": "./dist/dev.js",
|
|
9
|
+
"./build": "./dist/build.js",
|
|
10
|
+
"./serve": "./dist/serve.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xyd-js/react-router-dev": "7.1.1-xyd.3",
|
|
14
|
+
"@react-router/node": "^7.1.1",
|
|
15
|
+
"@react-router/serve": "^7.1.1",
|
|
16
|
+
"@react-router/dev": "^7.1.1",
|
|
17
|
+
"codehike": "^1.0.3",
|
|
18
|
+
"compression": "^1.7.5",
|
|
19
|
+
"express": "^4.21.2",
|
|
20
|
+
"get-port": "^7.1.0",
|
|
21
|
+
"gray-matter": "^4.0.3",
|
|
22
|
+
"isbot": "^5.1.17",
|
|
23
|
+
"lightningcss": "^1.27.0",
|
|
24
|
+
"morgan": "^1.10.0",
|
|
25
|
+
"react": "^18.3.1",
|
|
26
|
+
"react-dom": "^18.3.1",
|
|
27
|
+
"react-router": "^7.1.1",
|
|
28
|
+
"remark-frontmatter": "^5.0.0",
|
|
29
|
+
"remark-gfm": "^4.0.0",
|
|
30
|
+
"remark-mdx-frontmatter": "^5.0.0",
|
|
31
|
+
"source-map-support": "^0.5.21",
|
|
32
|
+
"typescript": "^5.6.3",
|
|
33
|
+
"vfile": "^6.0.3",
|
|
34
|
+
"yaml": "^2.6.0",
|
|
35
|
+
"@xyd-js/core": "0.1.0-xyd.0",
|
|
36
|
+
"@xyd-js/content": "0.1.0-xyd.2",
|
|
37
|
+
"@xyd-js/openapi": "0.1.0-xyd.0",
|
|
38
|
+
"@xyd-js/plugin-zero": "0.1.0-xyd.0",
|
|
39
|
+
"@xyd-js/gql": "0.1.0-xyd.0",
|
|
40
|
+
"@xyd-js/atlas": "0.1.0-xyd.1",
|
|
41
|
+
"@xyd-js/framework": "0.1.0-xyd.1",
|
|
42
|
+
"@xyd-js/theme-poetry": "0.1.0-xyd.1",
|
|
43
|
+
"@xyd-js/uniform": "0.1.0-xyd.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@mdx-js/rollup": "^3.1.0",
|
|
47
|
+
"@types/node": "^22.7.5",
|
|
48
|
+
"@types/react": "^18.3.9",
|
|
49
|
+
"@types/react-dom": "^18.3.1",
|
|
50
|
+
"@vitejs/plugin-react": "^4.3.2",
|
|
51
|
+
"autoprefixer": "^10.4.20",
|
|
52
|
+
"postcss": "^8.4.47",
|
|
53
|
+
"tsup": "^8.3.0",
|
|
54
|
+
"typescript": "^5.6.2",
|
|
55
|
+
"vite": "^5.4.9",
|
|
56
|
+
"vite-tsconfig-paths": "^5.0.1"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"build:tsc": "tsc --project ./tsconfig.build.json",
|
|
61
|
+
"watch": "tsup --watch"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/index.ts
ADDED
package/src/run/build.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import {fileURLToPath} from "node:url";
|
|
4
|
+
|
|
5
|
+
import {build as viteBuild} from 'vite';
|
|
6
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
7
|
+
|
|
8
|
+
import {reactRouter} from "@xyd-js/react-router-dev/vite";
|
|
9
|
+
// import { reactRouter } from "@react-router/dev/vite";
|
|
10
|
+
|
|
11
|
+
import {vitePlugins as xydContentVitePlugins} from "@xyd-js/content"
|
|
12
|
+
import {pluginZero} from "@xyd-js/plugin-zero";
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
|
|
17
|
+
// Define the main function to run the builds
|
|
18
|
+
export async function build() {
|
|
19
|
+
const resp = await pluginZero()
|
|
20
|
+
if (!resp) {
|
|
21
|
+
throw new Error("PluginZero not found")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const buildDir = path.join(process.cwd(), ".xyd/build");
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
const packageJsonPath = path.join(buildDir, 'package.json');
|
|
28
|
+
|
|
29
|
+
const packageJsonContent = {
|
|
30
|
+
type: "module",
|
|
31
|
+
scripts: {},
|
|
32
|
+
dependencies: {},
|
|
33
|
+
devDependencies: {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Ensure the build directory exists
|
|
37
|
+
if (!fs.existsSync(buildDir)) {
|
|
38
|
+
fs.mkdirSync(buildDir, {recursive: true});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Write the package.json file
|
|
42
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContent, null, 2), 'utf8');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// Build the client-side bundle
|
|
47
|
+
await viteBuild({
|
|
48
|
+
root: path.join(__dirname, "../host"),
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
plugins: [
|
|
51
|
+
...(xydContentVitePlugins({
|
|
52
|
+
toc: {
|
|
53
|
+
minDepth: 2,
|
|
54
|
+
}
|
|
55
|
+
}) as Plugin[]),
|
|
56
|
+
reactRouter({
|
|
57
|
+
outDir: buildDir,
|
|
58
|
+
routes: resp.routes
|
|
59
|
+
}),
|
|
60
|
+
tsconfigPaths(),
|
|
61
|
+
...resp.vitePlugins
|
|
62
|
+
],
|
|
63
|
+
optimizeDeps: {
|
|
64
|
+
include: ["react/jsx-runtime"],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Build the SSR bundle
|
|
69
|
+
await viteBuild({
|
|
70
|
+
root: path.join(__dirname, "../host"),
|
|
71
|
+
build: {
|
|
72
|
+
ssr: true,
|
|
73
|
+
},
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
plugins: [
|
|
76
|
+
...(xydContentVitePlugins({
|
|
77
|
+
toc: {
|
|
78
|
+
minDepth: 2,
|
|
79
|
+
}
|
|
80
|
+
}) as Plugin[]),
|
|
81
|
+
reactRouter({
|
|
82
|
+
outDir: buildDir,
|
|
83
|
+
routes: resp.routes
|
|
84
|
+
}),
|
|
85
|
+
tsconfigPaths(),
|
|
86
|
+
...resp.vitePlugins
|
|
87
|
+
],
|
|
88
|
+
optimizeDeps: {
|
|
89
|
+
include: ["react/jsx-runtime"],
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
console.log('Build completed successfully.'); // TODO: better message
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error('Build failed:', error); // TODO: better message
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
package/src/run/dev.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import {fileURLToPath} from "node:url";
|
|
3
|
+
import {createServer, searchForWorkspaceRoot} from "vite";
|
|
4
|
+
|
|
5
|
+
import {reactRouter} from "@xyd-js/react-router-dev/vite";
|
|
6
|
+
// import { reactRouter } from "@react-router/dev/vite";
|
|
7
|
+
|
|
8
|
+
import {vitePlugins as xydContentVitePlugins} from "@xyd-js/content";
|
|
9
|
+
import {pluginZero} from "@xyd-js/plugin-zero";
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
|
|
14
|
+
const port = process.env.XYD_PORT ? parseInt(process.env.XYD_PORT) : 5175;
|
|
15
|
+
|
|
16
|
+
export async function dev() {
|
|
17
|
+
const resp = await pluginZero()
|
|
18
|
+
if (!resp) {
|
|
19
|
+
throw new Error("PluginZero not found")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const allowCwd = searchForWorkspaceRoot(process.cwd())
|
|
23
|
+
|
|
24
|
+
const preview = await createServer({
|
|
25
|
+
// any valid user config options, plus `mode` and `configFile`
|
|
26
|
+
// configFile: path.join(__dirname, "../src/vite/empty-config.ts"), // TODO: bundler??
|
|
27
|
+
// configFile: path.join(__dirname, "../"), // TODO: bundler??
|
|
28
|
+
// root: path.join(__dirname, "../"), // TODO: bundler?
|
|
29
|
+
root: process.env.XYD_DOCUMAN_HOST || path.join(__dirname, "../host"), // TODO: bundler?
|
|
30
|
+
server: {
|
|
31
|
+
port: port,
|
|
32
|
+
fs: {
|
|
33
|
+
allow: [
|
|
34
|
+
allowCwd,
|
|
35
|
+
process.env.XYD_CLI ? path.join(__dirname, "../../") : "",
|
|
36
|
+
// path.join(__dirname, "../node_modules") // Ensure node_modules from xyd-documan is included
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
build: {
|
|
41
|
+
rollupOptions: {
|
|
42
|
+
// Exclude package `B` from the client-side bundle
|
|
43
|
+
external: ["@xyd-js/uniform", "@xyd-js/uniform/content", "@xyd-js/plugin-zero"],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
ssr: {
|
|
47
|
+
external: ["@xyd-js/uniform", "@xyd-js/uniform/content", "@xyd-js/plugin-zero"],
|
|
48
|
+
// noExternal: [
|
|
49
|
+
// "@xyd-js/uniform",
|
|
50
|
+
// "@xyd-js/uniform/content",
|
|
51
|
+
// "@xyd-js/plugin-zero"
|
|
52
|
+
// ],
|
|
53
|
+
},
|
|
54
|
+
optimizeDeps: {
|
|
55
|
+
include: ["react/jsx-runtime"],
|
|
56
|
+
},
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
plugins: [ // TODO: fix plugin ts
|
|
59
|
+
...(xydContentVitePlugins({
|
|
60
|
+
toc: {
|
|
61
|
+
minDepth: 2,
|
|
62
|
+
}
|
|
63
|
+
}) as Plugin[]),
|
|
64
|
+
reactRouter({
|
|
65
|
+
routes: resp.routes
|
|
66
|
+
}),
|
|
67
|
+
...resp.vitePlugins
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await preview.listen(port);
|
|
72
|
+
|
|
73
|
+
preview.printUrls();
|
|
74
|
+
preview.bindCLIShortcuts({print: true});
|
|
75
|
+
|
|
76
|
+
}
|
package/src/run/index.ts
ADDED
package/src/run/serve.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import url from "node:url";
|
|
5
|
+
|
|
6
|
+
import type {ServerBuild} from "react-router";
|
|
7
|
+
import {createRequestHandler} from "@react-router/express";
|
|
8
|
+
import compression from "compression";
|
|
9
|
+
import express from "express";
|
|
10
|
+
import morgan from "morgan";
|
|
11
|
+
import sourceMapSupport from "source-map-support";
|
|
12
|
+
import getPort from "get-port";
|
|
13
|
+
|
|
14
|
+
function parseNumber(raw?: string) {
|
|
15
|
+
if (raw === undefined) return undefined;
|
|
16
|
+
let maybe = Number(raw);
|
|
17
|
+
if (Number.isNaN(maybe)) return undefined;
|
|
18
|
+
return maybe;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function serve() {
|
|
22
|
+
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
|
23
|
+
|
|
24
|
+
sourceMapSupport.install({
|
|
25
|
+
retrieveSourceMap: function (source) {
|
|
26
|
+
let match = source.startsWith("file://");
|
|
27
|
+
if (match) {
|
|
28
|
+
let filePath = url.fileURLToPath(source);
|
|
29
|
+
let sourceMapPath = `${filePath}.map`;
|
|
30
|
+
if (fs.existsSync(sourceMapPath)) {
|
|
31
|
+
return {
|
|
32
|
+
url: source,
|
|
33
|
+
map: fs.readFileSync(sourceMapPath, "utf8"),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
let port = parseNumber(process.env.PORT) ?? (await getPort({port: 3000}));
|
|
42
|
+
|
|
43
|
+
let buildPathArg = path.join(process.cwd(), ".xyd/build/server/index.js")
|
|
44
|
+
|
|
45
|
+
if (!buildPathArg) {
|
|
46
|
+
console.error(`
|
|
47
|
+
Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let buildPath = path.resolve(buildPathArg);
|
|
52
|
+
|
|
53
|
+
let build: ServerBuild = await import(url.pathToFileURL(buildPath).href);
|
|
54
|
+
|
|
55
|
+
let onListen = () => {
|
|
56
|
+
let address =
|
|
57
|
+
process.env.HOST ||
|
|
58
|
+
Object.values(os.networkInterfaces())
|
|
59
|
+
.flat()
|
|
60
|
+
.find((ip) => String(ip?.family).includes("4") && !ip?.internal)
|
|
61
|
+
?.address;
|
|
62
|
+
|
|
63
|
+
if (!address) {
|
|
64
|
+
console.log(`[xyd-serve] http://localhost:${port}`);
|
|
65
|
+
} else {
|
|
66
|
+
console.log(
|
|
67
|
+
`[xyd-serve] http://localhost:${port} (http://${address}:${port})`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
build = {
|
|
73
|
+
...build,
|
|
74
|
+
assetsBuildDirectory: path.join(process.cwd(), ".xyd/build/client")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let app = express();
|
|
78
|
+
app.disable("x-powered-by");
|
|
79
|
+
app.use(compression());
|
|
80
|
+
app.use(
|
|
81
|
+
path.posix.join(build.publicPath, "assets"),
|
|
82
|
+
express.static(path.join(build.assetsBuildDirectory, "assets"), {
|
|
83
|
+
immutable: true,
|
|
84
|
+
maxAge: "1y",
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
app.use(build.publicPath, express.static(build.assetsBuildDirectory));
|
|
88
|
+
app.use(express.static("public", {maxAge: "1h"}));
|
|
89
|
+
app.use(morgan("tiny"));
|
|
90
|
+
|
|
91
|
+
app.all(
|
|
92
|
+
"*",
|
|
93
|
+
createRequestHandler({
|
|
94
|
+
build,
|
|
95
|
+
mode: process.env.NODE_ENV,
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
let server = process.env.HOST
|
|
100
|
+
? app.listen(port, process.env.HOST, onListen)
|
|
101
|
+
: app.listen(port, onListen);
|
|
102
|
+
|
|
103
|
+
["SIGTERM", "SIGINT"].forEach((signal) => {
|
|
104
|
+
process.once(signal, () => server?.close(console.error));
|
|
105
|
+
});
|
|
106
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"target": "esnext", // Change this to es2020 or esnext
|
|
7
|
+
"baseUrl": ".",
|
|
8
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": false,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"incremental": false,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"jsx": "preserve",
|
|
17
|
+
"plugins": [],
|
|
18
|
+
"strictNullChecks": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "host/**/*.ts", "host/**/*.tsx"],
|
|
21
|
+
"exclude": ["node_modules"]
|
|
22
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {defineConfig} from 'tsup';
|
|
2
|
+
import pkg from './package.json';
|
|
3
|
+
|
|
4
|
+
const deps = [
|
|
5
|
+
...Object.keys(pkg.dependencies || {}),
|
|
6
|
+
...Object.keys(pkg.devDependencies || {}),
|
|
7
|
+
].filter((dep) => [
|
|
8
|
+
"@xyd-js/core",
|
|
9
|
+
"@xyd-js/content",
|
|
10
|
+
"@xyd-js/framework",
|
|
11
|
+
"@xyd-js/ui",
|
|
12
|
+
"@xyd-js/openapi",
|
|
13
|
+
"@xyd-js/uniform",
|
|
14
|
+
"@xyd-js/theme-gusto",
|
|
15
|
+
// "@xyd-js/plugin-zero", // TODO: because plugin-zero has react-router dependency
|
|
16
|
+
].indexOf(dep) === -1)
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
entry: {
|
|
20
|
+
index: 'src/index.ts',
|
|
21
|
+
dev: 'src/commands/dev.ts',
|
|
22
|
+
build: 'src/commands/build.ts',
|
|
23
|
+
serve: 'src/commands/serve.ts',
|
|
24
|
+
},
|
|
25
|
+
dts: {
|
|
26
|
+
entry: {
|
|
27
|
+
index: 'src/index.ts',
|
|
28
|
+
dev: 'src/commands/dev.ts',
|
|
29
|
+
build: 'src/commands/build.ts',
|
|
30
|
+
serve: 'src/commands/serve.ts',
|
|
31
|
+
},
|
|
32
|
+
resolve: true, // Resolve external types
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
format: ["esm"],
|
|
36
|
+
platform: 'node',
|
|
37
|
+
shims: false,
|
|
38
|
+
splitting: false,
|
|
39
|
+
sourcemap: true,
|
|
40
|
+
clean: true,
|
|
41
|
+
bundle: true, // Enable bundling
|
|
42
|
+
external: [
|
|
43
|
+
...deps,
|
|
44
|
+
|
|
45
|
+
// needed by @xyd-js/plugin-zero
|
|
46
|
+
"react-router",
|
|
47
|
+
"@react-router/dev",
|
|
48
|
+
"@react-router/express",
|
|
49
|
+
|
|
50
|
+
"@xyd-js/react-router-dev",
|
|
51
|
+
|
|
52
|
+
"@readme/json-schema-ref-parser",
|
|
53
|
+
"@apidevtools/json-schema-ref-parser",
|
|
54
|
+
//
|
|
55
|
+
|
|
56
|
+
//
|
|
57
|
+
// Externalize Node.js built-in modules
|
|
58
|
+
/^node:.*/,
|
|
59
|
+
'fs',
|
|
60
|
+
'path',
|
|
61
|
+
'url',
|
|
62
|
+
'os',
|
|
63
|
+
'http',
|
|
64
|
+
'https',
|
|
65
|
+
'stream',
|
|
66
|
+
'zlib',
|
|
67
|
+
'util',
|
|
68
|
+
'crypto',
|
|
69
|
+
'tty',
|
|
70
|
+
|
|
71
|
+
// "lightningcss",
|
|
72
|
+
// "vite",
|
|
73
|
+
// "vite-tsconfig-paths",
|
|
74
|
+
// "react-router",
|
|
75
|
+
// "@react-router/serve",
|
|
76
|
+
// "@react-router/dev",
|
|
77
|
+
// "@xydjs/react-router-dev",
|
|
78
|
+
// "@mdx-js/rollup",
|
|
79
|
+
// "@graphql-markdown"
|
|
80
|
+
], // Ensure no dependencies are marked as external
|
|
81
|
+
})
|