@xyd-js/documan 0.1.0-xyd.7 → 0.1.0-xyd.73

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/dist/serve.js DELETED
@@ -1,110 +0,0 @@
1
- // src/run/build.ts
2
- import path from "node:path";
3
- import fs from "node:fs";
4
- import { fileURLToPath } from "node:url";
5
- import { build as viteBuild } from "vite";
6
- import tsconfigPaths from "vite-tsconfig-paths";
7
- import { reactRouter } from "@xyd-js/react-router-dev/vite";
8
- import { vitePlugins as xydContentVitePlugins } from "@xyd-js/content";
9
- import { pluginZero } from "@xyd-js/plugin-zero";
10
- var __filename = fileURLToPath(import.meta.url);
11
- var __dirname = path.dirname(__filename);
12
-
13
- // src/run/dev.ts
14
- import path2 from "node:path";
15
- import { fileURLToPath as fileURLToPath2 } from "node:url";
16
- import { createServer, searchForWorkspaceRoot } from "vite";
17
- import { reactRouter as reactRouter2 } from "@xyd-js/react-router-dev/vite";
18
- import { vitePlugins as xydContentVitePlugins2 } from "@xyd-js/content";
19
- import { pluginZero as pluginZero2 } from "@xyd-js/plugin-zero";
20
- var __filename2 = fileURLToPath2(import.meta.url);
21
- var __dirname2 = path2.dirname(__filename2);
22
- var port = process.env.XYD_PORT ? parseInt(process.env.XYD_PORT) : 5175;
23
-
24
- // src/run/serve.ts
25
- import fs2 from "node:fs";
26
- import os from "node:os";
27
- import path3 from "node:path";
28
- import url from "node:url";
29
- import { createRequestHandler } from "@react-router/express";
30
- import compression from "compression";
31
- import express from "express";
32
- import morgan from "morgan";
33
- import sourceMapSupport from "source-map-support";
34
- import getPort from "get-port";
35
- function parseNumber(raw) {
36
- if (raw === void 0) return void 0;
37
- let maybe = Number(raw);
38
- if (Number.isNaN(maybe)) return void 0;
39
- return maybe;
40
- }
41
- async function serve() {
42
- process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
43
- sourceMapSupport.install({
44
- retrieveSourceMap: function(source) {
45
- let match = source.startsWith("file://");
46
- if (match) {
47
- let filePath = url.fileURLToPath(source);
48
- let sourceMapPath = `${filePath}.map`;
49
- if (fs2.existsSync(sourceMapPath)) {
50
- return {
51
- url: source,
52
- map: fs2.readFileSync(sourceMapPath, "utf8")
53
- };
54
- }
55
- }
56
- return null;
57
- }
58
- });
59
- let port2 = parseNumber(process.env.PORT) ?? await getPort({ port: 3e3 });
60
- let buildPathArg = path3.join(process.cwd(), ".xyd/build/server/index.js");
61
- if (!buildPathArg) {
62
- console.error(`
63
- Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);
64
- process.exit(1);
65
- }
66
- let buildPath = path3.resolve(buildPathArg);
67
- let build2 = await import(url.pathToFileURL(buildPath).href);
68
- let onListen = () => {
69
- let address = process.env.HOST || Object.values(os.networkInterfaces()).flat().find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
70
- if (!address) {
71
- console.log(`[xyd-serve] http://localhost:${port2}`);
72
- } else {
73
- console.log(
74
- `[xyd-serve] http://localhost:${port2} (http://${address}:${port2})`
75
- );
76
- }
77
- };
78
- build2 = {
79
- ...build2,
80
- assetsBuildDirectory: path3.join(process.cwd(), ".xyd/build/client")
81
- };
82
- let app = express();
83
- app.disable("x-powered-by");
84
- app.use(compression());
85
- app.use(
86
- path3.posix.join(build2.publicPath, "assets"),
87
- express.static(path3.join(build2.assetsBuildDirectory, "assets"), {
88
- immutable: true,
89
- maxAge: "1y"
90
- })
91
- );
92
- app.use(build2.publicPath, express.static(build2.assetsBuildDirectory));
93
- app.use(express.static("public", { maxAge: "1h" }));
94
- app.use(morgan("tiny"));
95
- app.all(
96
- "*",
97
- createRequestHandler({
98
- build: build2,
99
- mode: process.env.NODE_ENV
100
- })
101
- );
102
- let server = process.env.HOST ? app.listen(port2, process.env.HOST, onListen) : app.listen(port2, onListen);
103
- ["SIGTERM", "SIGINT"].forEach((signal) => {
104
- process.once(signal, () => server?.close(console.error));
105
- });
106
- }
107
-
108
- // src/commands/serve.ts
109
- await serve();
110
- //# sourceMappingURL=serve.js.map
package/dist/serve.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/run/build.ts","../src/run/dev.ts","../src/run/serve.ts","../src/commands/serve.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport {fileURLToPath} from \"node:url\";\n\nimport {build as viteBuild} from 'vite';\nimport tsconfigPaths from \"vite-tsconfig-paths\";\n\nimport {reactRouter} from \"@xyd-js/react-router-dev/vite\";\n// import { reactRouter } from \"@react-router/dev/vite\";\n\nimport {vitePlugins as xydContentVitePlugins} from \"@xyd-js/content\"\nimport {pluginZero} from \"@xyd-js/plugin-zero\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// Define the main function to run the builds\nexport async function build() {\n const resp = await pluginZero()\n if (!resp) {\n throw new Error(\"PluginZero not found\")\n }\n\n const buildDir = path.join(process.cwd(), \".xyd/build\");\n\n {\n const packageJsonPath = path.join(buildDir, 'package.json');\n\n const packageJsonContent = {\n type: \"module\",\n scripts: {},\n dependencies: {},\n devDependencies: {}\n };\n\n // Ensure the build directory exists\n if (!fs.existsSync(buildDir)) {\n fs.mkdirSync(buildDir, {recursive: true});\n }\n\n // Write the package.json file\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContent, null, 2), 'utf8');\n }\n\n try {\n // Build the client-side bundle\n await viteBuild({\n root: path.join(__dirname, \"../host\"),\n // @ts-ignore\n plugins: [\n ...(xydContentVitePlugins({\n toc: {\n minDepth: 2,\n }\n }) as Plugin[]),\n reactRouter({\n outDir: buildDir,\n routes: resp.routes\n }),\n tsconfigPaths(),\n ...resp.vitePlugins\n ],\n optimizeDeps: {\n include: [\"react/jsx-runtime\"],\n },\n });\n\n // Build the SSR bundle\n await viteBuild({\n root: path.join(__dirname, \"../host\"),\n build: {\n ssr: true,\n },\n // @ts-ignore\n plugins: [\n ...(xydContentVitePlugins({\n toc: {\n minDepth: 2,\n }\n }) as Plugin[]),\n reactRouter({\n outDir: buildDir,\n routes: resp.routes\n }),\n tsconfigPaths(),\n ...resp.vitePlugins\n ],\n optimizeDeps: {\n include: [\"react/jsx-runtime\"],\n },\n });\n\n console.log('Build completed successfully.'); // TODO: better message\n } catch (error) {\n console.error('Build failed:', error); // TODO: better message\n }\n}\n\n","import path from \"node:path\";\nimport {fileURLToPath} from \"node:url\";\nimport {createServer, searchForWorkspaceRoot} from \"vite\";\n\nimport {reactRouter} from \"@xyd-js/react-router-dev/vite\";\n// import { reactRouter } from \"@react-router/dev/vite\";\n\nimport {vitePlugins as xydContentVitePlugins} from \"@xyd-js/content\";\nimport {pluginZero} from \"@xyd-js/plugin-zero\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nconst port = process.env.XYD_PORT ? parseInt(process.env.XYD_PORT) : 5175;\n\nexport async function dev() {\n const resp = await pluginZero()\n if (!resp) {\n throw new Error(\"PluginZero not found\")\n }\n\n const allowCwd = searchForWorkspaceRoot(process.cwd())\n\n const preview = await createServer({\n // any valid user config options, plus `mode` and `configFile`\n // configFile: path.join(__dirname, \"../src/vite/empty-config.ts\"), // TODO: bundler??\n // configFile: path.join(__dirname, \"../\"), // TODO: bundler??\n // root: path.join(__dirname, \"../\"), // TODO: bundler?\n root: process.env.XYD_DOCUMAN_HOST || path.join(__dirname, \"../host\"), // TODO: bundler?\n server: {\n port: port,\n fs: {\n allow: [\n allowCwd,\n process.env.XYD_CLI ? path.join(__dirname, \"../../\") : \"\",\n // path.join(__dirname, \"../node_modules\") // Ensure node_modules from xyd-documan is included\n ]\n }\n },\n build: {\n rollupOptions: {\n // Exclude package `B` from the client-side bundle\n external: [\"@xyd-js/uniform\", \"@xyd-js/uniform/content\", \"@xyd-js/plugin-zero\"],\n },\n },\n ssr: {\n external: [\"@xyd-js/uniform\", \"@xyd-js/uniform/content\", \"@xyd-js/plugin-zero\"],\n // noExternal: [\n // \"@xyd-js/uniform\",\n // \"@xyd-js/uniform/content\",\n // \"@xyd-js/plugin-zero\"\n // ],\n },\n optimizeDeps: {\n include: [\"react/jsx-runtime\"],\n },\n // @ts-ignore\n plugins: [ // TODO: fix plugin ts\n ...(xydContentVitePlugins({\n toc: {\n minDepth: 2,\n }\n }) as Plugin[]),\n reactRouter({\n routes: resp.routes\n }),\n ...resp.vitePlugins\n ],\n });\n\n await preview.listen(port);\n\n preview.printUrls();\n preview.bindCLIShortcuts({print: true});\n\n}","import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport url from \"node:url\";\n\nimport type {ServerBuild} from \"react-router\";\nimport {createRequestHandler} from \"@react-router/express\";\nimport compression from \"compression\";\nimport express from \"express\";\nimport morgan from \"morgan\";\nimport sourceMapSupport from \"source-map-support\";\nimport getPort from \"get-port\";\n\nfunction parseNumber(raw?: string) {\n if (raw === undefined) return undefined;\n let maybe = Number(raw);\n if (Number.isNaN(maybe)) return undefined;\n return maybe;\n}\n\nexport async function serve() {\n process.env.NODE_ENV = process.env.NODE_ENV ?? \"production\";\n\n sourceMapSupport.install({\n retrieveSourceMap: function (source) {\n let match = source.startsWith(\"file://\");\n if (match) {\n let filePath = url.fileURLToPath(source);\n let sourceMapPath = `${filePath}.map`;\n if (fs.existsSync(sourceMapPath)) {\n return {\n url: source,\n map: fs.readFileSync(sourceMapPath, \"utf8\"),\n };\n }\n }\n return null;\n },\n });\n\n let port = parseNumber(process.env.PORT) ?? (await getPort({port: 3000}));\n\n let buildPathArg = path.join(process.cwd(), \".xyd/build/server/index.js\")\n\n if (!buildPathArg) {\n console.error(`\n Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);\n process.exit(1);\n }\n\n let buildPath = path.resolve(buildPathArg);\n\n let build: ServerBuild = await import(url.pathToFileURL(buildPath).href);\n\n let onListen = () => {\n let address =\n process.env.HOST ||\n Object.values(os.networkInterfaces())\n .flat()\n .find((ip) => String(ip?.family).includes(\"4\") && !ip?.internal)\n ?.address;\n\n if (!address) {\n console.log(`[xyd-serve] http://localhost:${port}`);\n } else {\n console.log(\n `[xyd-serve] http://localhost:${port} (http://${address}:${port})`\n );\n }\n };\n\n build = {\n ...build,\n assetsBuildDirectory: path.join(process.cwd(), \".xyd/build/client\")\n }\n\n let app = express();\n app.disable(\"x-powered-by\");\n app.use(compression());\n app.use(\n path.posix.join(build.publicPath, \"assets\"),\n express.static(path.join(build.assetsBuildDirectory, \"assets\"), {\n immutable: true,\n maxAge: \"1y\",\n })\n );\n app.use(build.publicPath, express.static(build.assetsBuildDirectory));\n app.use(express.static(\"public\", {maxAge: \"1h\"}));\n app.use(morgan(\"tiny\"));\n\n app.all(\n \"*\",\n createRequestHandler({\n build,\n mode: process.env.NODE_ENV,\n })\n );\n\n let server = process.env.HOST\n ? app.listen(port, process.env.HOST, onListen)\n : app.listen(port, onListen);\n\n [\"SIGTERM\", \"SIGINT\"].forEach((signal) => {\n process.once(signal, () => server?.close(console.error));\n });\n}\n","import {serve} from \"../\"\n\n// Execute the serve function\nawait serve();\n\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,qBAAoB;AAE5B,SAAQ,SAAS,iBAAgB;AACjC,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAG1B,SAAQ,eAAe,6BAA4B;AACnD,SAAQ,kBAAiB;AAEzB,IAAM,aAAa,cAAc,YAAY,GAAG;AAChD,IAAM,YAAY,KAAK,QAAQ,UAAU;;;ACdzC,OAAOA,WAAU;AACjB,SAAQ,iBAAAC,sBAAoB;AAC5B,SAAQ,cAAc,8BAA6B;AAEnD,SAAQ,eAAAC,oBAAkB;AAG1B,SAAQ,eAAeC,8BAA4B;AACnD,SAAQ,cAAAC,mBAAiB;AAEzB,IAAMC,cAAaJ,eAAc,YAAY,GAAG;AAChD,IAAMK,aAAYN,MAAK,QAAQK,WAAU;AAEzC,IAAM,OAAO,QAAQ,IAAI,WAAW,SAAS,QAAQ,IAAI,QAAQ,IAAI;;;ACbrE,OAAOE,SAAQ;AACf,OA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ins","pluginZero","__filename","__dirname","fs","path","port","build"]}
package/host/app/root.tsx DELETED
@@ -1,23 +0,0 @@
1
- import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
2
-
3
- export function Layout({ children }: { children: React.ReactNode }) {
4
- return (
5
- <html lang="en">
6
- <head>
7
- <meta charSet="utf-8" />
8
- <meta name="viewport" content="width=device-width, initial-scale=1" />
9
- <Meta />
10
- <Links />
11
- </head>
12
- <body>
13
- {children}
14
- <ScrollRestoration />
15
- <Scripts />
16
- </body>
17
- </html>
18
- );
19
- }
20
-
21
- export default function App() {
22
- return <Outlet />;
23
- }
@@ -1,5 +0,0 @@
1
- // we export empty routes because rr7 need this file and we load routes via xyd plugins
2
-
3
- export const routes = []
4
-
5
- export default routes
package/host/package.json DELETED
@@ -1,43 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- plugins: {
3
- autoprefixer: {},
4
- },
5
- }
@@ -1,8 +0,0 @@
1
- import type {Config} from "@react-router/dev/config";
2
-
3
- export default {
4
- // return a list of URLs to prerender at build time
5
- async prerender() {
6
- return ["/example"];
7
- },
8
- } satisfies Config;
@@ -1,22 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
1
- import {defineConfig} from 'vite';
2
-
3
- // DO NOT DELETE
4
- // This file is needed for host `vite` to run
5
- export default defineConfig(async () => {
6
- return {
7
- plugins: [],
8
- };
9
- });
@@ -1,4 +0,0 @@
1
- import {build} from "../"
2
-
3
- // Execute the build function
4
- await build();
@@ -1,5 +0,0 @@
1
- import {dev} from "../"
2
-
3
- // Execute the dev function
4
- await dev();
5
-
@@ -1,5 +0,0 @@
1
- import {serve} from "../"
2
-
3
- // Execute the serve function
4
- await serve();
5
-
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export {
2
- build,
3
-
4
- dev,
5
-
6
- serve
7
- } from "./run"
package/src/run/build.ts DELETED
@@ -1,98 +0,0 @@
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 DELETED
@@ -1,76 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
1
- export {build} from "./build"
2
-
3
- export {dev} from "./dev"
4
-
5
- export {serve} from "./serve"
6
-
package/src/run/serve.ts DELETED
@@ -1,106 +0,0 @@
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 DELETED
@@ -1,22 +0,0 @@
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
- }