@xyd-js/documan 0.1.0-xyd.14 → 0.1.0-xyd.15

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,2 @@
1
+
2
+ export { }
package/dist/build.js ADDED
@@ -0,0 +1,117 @@
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 { execSync } from "child_process";
6
+ import { build as viteBuild } from "vite";
7
+ import tsconfigPaths from "vite-tsconfig-paths";
8
+ import { reactRouter } from "@xyd-js/react-router-dev/vite";
9
+ import { vitePlugins as xydContentVitePlugins } from "@xyd-js/content";
10
+ import { pluginZero } from "@xyd-js/plugin-zero";
11
+ var __filename = fileURLToPath(import.meta.url);
12
+ var __dirname = path.dirname(__filename);
13
+ async function build() {
14
+ const resp = await pluginZero();
15
+ if (!resp) {
16
+ throw new Error("PluginZero not found");
17
+ }
18
+ const buildDir = path.join(process.cwd(), ".xyd/build");
19
+ {
20
+ const packageJsonPath = path.join(buildDir, "package.json");
21
+ const packageJsonContent = {
22
+ type: "module",
23
+ scripts: {},
24
+ dependencies: {
25
+ // TODO: better
26
+ "@xyd-js/content": "latest",
27
+ "@xyd-js/components": "latest",
28
+ "@xyd-js/framework": "latest",
29
+ "@xyd-js/theme-poetry": "latest",
30
+ "@react-router/node": "^7.1.1",
31
+ "isbot": "^5"
32
+ },
33
+ devDependencies: {}
34
+ };
35
+ if (!fs.existsSync(buildDir)) {
36
+ fs.mkdirSync(buildDir, { recursive: true });
37
+ }
38
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContent, null, 2), "utf8");
39
+ console.log("Installing dependencies...");
40
+ execSync("npm install", { cwd: buildDir, stdio: "inherit" });
41
+ }
42
+ try {
43
+ await viteBuild({
44
+ root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || path.join(__dirname, "../host"),
45
+ // @ts-ignore
46
+ plugins: [
47
+ ...xydContentVitePlugins({
48
+ toc: {
49
+ minDepth: 2
50
+ }
51
+ }),
52
+ reactRouter({
53
+ outDir: buildDir,
54
+ routes: resp.routes
55
+ }),
56
+ tsconfigPaths(),
57
+ ...resp.vitePlugins
58
+ ],
59
+ optimizeDeps: {
60
+ include: ["react/jsx-runtime"]
61
+ }
62
+ });
63
+ await viteBuild({
64
+ root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || path.join(__dirname, "../host"),
65
+ build: {
66
+ ssr: true
67
+ },
68
+ // @ts-ignore
69
+ plugins: [
70
+ ...xydContentVitePlugins({
71
+ toc: {
72
+ minDepth: 2
73
+ }
74
+ }),
75
+ reactRouter({
76
+ outDir: buildDir,
77
+ routes: resp.routes
78
+ }),
79
+ tsconfigPaths(),
80
+ ...resp.vitePlugins
81
+ ],
82
+ optimizeDeps: {
83
+ include: ["react/jsx-runtime"]
84
+ }
85
+ });
86
+ console.log("Build completed successfully.");
87
+ } catch (error) {
88
+ console.error("Build failed:", error);
89
+ }
90
+ }
91
+
92
+ // src/run/dev.ts
93
+ import path2 from "node:path";
94
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
95
+ import { createServer, searchForWorkspaceRoot } from "vite";
96
+ import { reactRouter as reactRouter2 } from "@xyd-js/react-router-dev/vite";
97
+ import { vitePlugins as xydContentVitePlugins2 } from "@xyd-js/content";
98
+ import { pluginZero as pluginZero2 } from "@xyd-js/plugin-zero";
99
+ var __filename2 = fileURLToPath2(import.meta.url);
100
+ var __dirname2 = path2.dirname(__filename2);
101
+ var port = process.env.XYD_PORT ? parseInt(process.env.XYD_PORT) : 5175;
102
+
103
+ // src/run/serve.ts
104
+ import fs2 from "node:fs";
105
+ import os from "node:os";
106
+ import path3 from "node:path";
107
+ import url from "node:url";
108
+ import { createRequestHandler } from "@react-router/express";
109
+ import compression from "compression";
110
+ import express from "express";
111
+ import morgan from "morgan";
112
+ import sourceMapSupport from "source-map-support";
113
+ import getPort from "get-port";
114
+
115
+ // src/commands/build.ts
116
+ await build();
117
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run/build.ts","../src/run/dev.ts","../src/run/serve.ts","../src/commands/build.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport {fileURLToPath} from \"node:url\";\nimport {execSync} from 'child_process';\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 // TODO: probably we should have better mechanism - maybe bundle?\n\n const packageJsonPath = path.join(buildDir, 'package.json');\n\n const packageJsonContent = {\n type: \"module\",\n scripts: {},\n dependencies: { // TODO: better\n \"@xyd-js/content\": \"latest\",\n \"@xyd-js/components\": \"latest\",\n \"@xyd-js/framework\": \"latest\",\n \"@xyd-js/theme-poetry\": \"latest\",\n \"@react-router/node\": \"^7.1.1\",\n \"isbot\": \"^5\"\n },\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 // Install packages inside buildDir\n console.log('Installing dependencies...');\n execSync('npm install', {cwd: buildDir, stdio: 'inherit'});\n }\n\n try {\n // Build the client-side bundle\n await viteBuild({\n root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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_CLI ? __dirname : 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 {build} from \"../\"\n\n// Execute the build function\nawait build();"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,qBAAoB;AAC5B,SAAQ,gBAAe;AAEvB,SAAQ,SAAS,iBAAgB;AACjC,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAG1B,SAAQ,eAAe,6BAA4B;AACnD,SAAQ,kBAAiB;A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ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/dev.js ADDED
@@ -0,0 +1,96 @@
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
+ async function dev() {
24
+ const resp = await pluginZero2();
25
+ if (!resp) {
26
+ throw new Error("PluginZero not found");
27
+ }
28
+ const allowCwd = searchForWorkspaceRoot(process.cwd());
29
+ const preview = await createServer({
30
+ // any valid user config options, plus `mode` and `configFile`
31
+ // configFile: path.join(__dirname, "../src/vite/empty-config.ts"), // TODO: bundler??
32
+ // configFile: path.join(__dirname, "../"), // TODO: bundler??
33
+ // root: path.join(__dirname, "../"), // TODO: bundler?
34
+ root: process.env.XYD_CLI ? __dirname2 : process.env.XYD_DOCUMAN_HOST || path2.join(__dirname2, "../host"),
35
+ // TODO: bundler?
36
+ server: {
37
+ port,
38
+ fs: {
39
+ allow: [
40
+ allowCwd,
41
+ process.env.XYD_CLI ? path2.join(__dirname2, "../../") : ""
42
+ // path.join(__dirname, "../node_modules") // Ensure node_modules from xyd-documan is included
43
+ ]
44
+ }
45
+ },
46
+ build: {
47
+ rollupOptions: {
48
+ // Exclude package `B` from the client-side bundle
49
+ external: ["@xyd-js/uniform", "@xyd-js/uniform/content", "@xyd-js/plugin-zero"]
50
+ }
51
+ },
52
+ ssr: {
53
+ external: ["@xyd-js/uniform", "@xyd-js/uniform/content", "@xyd-js/plugin-zero"]
54
+ // noExternal: [
55
+ // "@xyd-js/uniform",
56
+ // "@xyd-js/uniform/content",
57
+ // "@xyd-js/plugin-zero"
58
+ // ],
59
+ },
60
+ optimizeDeps: {
61
+ include: ["react/jsx-runtime"]
62
+ },
63
+ // @ts-ignore
64
+ plugins: [
65
+ // TODO: fix plugin ts
66
+ ...xydContentVitePlugins2({
67
+ toc: {
68
+ minDepth: 2
69
+ }
70
+ }),
71
+ reactRouter2({
72
+ routes: resp.routes
73
+ }),
74
+ ...resp.vitePlugins
75
+ ]
76
+ });
77
+ await preview.listen(port);
78
+ preview.printUrls();
79
+ preview.bindCLIShortcuts({ print: true });
80
+ }
81
+
82
+ // src/run/serve.ts
83
+ import fs2 from "node:fs";
84
+ import os from "node:os";
85
+ import path3 from "node:path";
86
+ import url from "node:url";
87
+ import { createRequestHandler } from "@react-router/express";
88
+ import compression from "compression";
89
+ import express from "express";
90
+ import morgan from "morgan";
91
+ import sourceMapSupport from "source-map-support";
92
+ import getPort from "get-port";
93
+
94
+ // src/commands/dev.ts
95
+ await dev();
96
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run/build.ts","../src/run/dev.ts","../src/run/serve.ts","../src/commands/dev.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport {fileURLToPath} from \"node:url\";\nimport {execSync} from 'child_process';\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 // TODO: probably we should have better mechanism - maybe bundle?\n\n const packageJsonPath = path.join(buildDir, 'package.json');\n\n const packageJsonContent = {\n type: \"module\",\n scripts: {},\n dependencies: { // TODO: better\n \"@xyd-js/content\": \"latest\",\n \"@xyd-js/components\": \"latest\",\n \"@xyd-js/framework\": \"latest\",\n \"@xyd-js/theme-poetry\": \"latest\",\n \"@react-router/node\": \"^7.1.1\",\n \"isbot\": \"^5\"\n },\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 // Install packages inside buildDir\n console.log('Installing dependencies...');\n execSync('npm install', {cwd: buildDir, stdio: 'inherit'});\n }\n\n try {\n // Build the client-side bundle\n await viteBuild({\n root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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_CLI ? __dirname : 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 {dev} from \"../\"\n\n// Execute the dev function\nawait dev();\n\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,qBAAoB;AAG5B,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;;;ACfzC,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,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OAAO,SAAS;AAGhB,SAAQ,4BAA2B;AACnC,OAAO,iBAAiB;AACxB,OAAO,aAAa;AACpB,OAAO,YAAY;AACnB,OAAO,sBAAsB;AAC7B,OAAO,aAAa;;;ACRpB,MAAM,IAAI;","names":["path","fileURLToPath","reactRouter","xydContentVitePlugins","pluginZero","__filename","__dirname","fs","path"]}
@@ -0,0 +1,7 @@
1
+ declare function build(): Promise<void>;
2
+
3
+ declare function dev(): Promise<void>;
4
+
5
+ declare function serve(): Promise<void>;
6
+
7
+ export { build, dev, serve };
package/dist/index.js ADDED
@@ -0,0 +1,249 @@
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 { execSync } from "child_process";
6
+ import { build as viteBuild } from "vite";
7
+ import tsconfigPaths from "vite-tsconfig-paths";
8
+ import { reactRouter } from "@xyd-js/react-router-dev/vite";
9
+ import { vitePlugins as xydContentVitePlugins } from "@xyd-js/content";
10
+ import { pluginZero } from "@xyd-js/plugin-zero";
11
+ var __filename = fileURLToPath(import.meta.url);
12
+ var __dirname = path.dirname(__filename);
13
+ async function build() {
14
+ const resp = await pluginZero();
15
+ if (!resp) {
16
+ throw new Error("PluginZero not found");
17
+ }
18
+ const buildDir = path.join(process.cwd(), ".xyd/build");
19
+ {
20
+ const packageJsonPath = path.join(buildDir, "package.json");
21
+ const packageJsonContent = {
22
+ type: "module",
23
+ scripts: {},
24
+ dependencies: {
25
+ // TODO: better
26
+ "@xyd-js/content": "latest",
27
+ "@xyd-js/components": "latest",
28
+ "@xyd-js/framework": "latest",
29
+ "@xyd-js/theme-poetry": "latest",
30
+ "@react-router/node": "^7.1.1",
31
+ "isbot": "^5"
32
+ },
33
+ devDependencies: {}
34
+ };
35
+ if (!fs.existsSync(buildDir)) {
36
+ fs.mkdirSync(buildDir, { recursive: true });
37
+ }
38
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContent, null, 2), "utf8");
39
+ console.log("Installing dependencies...");
40
+ execSync("npm install", { cwd: buildDir, stdio: "inherit" });
41
+ }
42
+ try {
43
+ await viteBuild({
44
+ root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || path.join(__dirname, "../host"),
45
+ // @ts-ignore
46
+ plugins: [
47
+ ...xydContentVitePlugins({
48
+ toc: {
49
+ minDepth: 2
50
+ }
51
+ }),
52
+ reactRouter({
53
+ outDir: buildDir,
54
+ routes: resp.routes
55
+ }),
56
+ tsconfigPaths(),
57
+ ...resp.vitePlugins
58
+ ],
59
+ optimizeDeps: {
60
+ include: ["react/jsx-runtime"]
61
+ }
62
+ });
63
+ await viteBuild({
64
+ root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || path.join(__dirname, "../host"),
65
+ build: {
66
+ ssr: true
67
+ },
68
+ // @ts-ignore
69
+ plugins: [
70
+ ...xydContentVitePlugins({
71
+ toc: {
72
+ minDepth: 2
73
+ }
74
+ }),
75
+ reactRouter({
76
+ outDir: buildDir,
77
+ routes: resp.routes
78
+ }),
79
+ tsconfigPaths(),
80
+ ...resp.vitePlugins
81
+ ],
82
+ optimizeDeps: {
83
+ include: ["react/jsx-runtime"]
84
+ }
85
+ });
86
+ console.log("Build completed successfully.");
87
+ } catch (error) {
88
+ console.error("Build failed:", error);
89
+ }
90
+ }
91
+
92
+ // src/run/dev.ts
93
+ import path2 from "node:path";
94
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
95
+ import { createServer, searchForWorkspaceRoot } from "vite";
96
+ import { reactRouter as reactRouter2 } from "@xyd-js/react-router-dev/vite";
97
+ import { vitePlugins as xydContentVitePlugins2 } from "@xyd-js/content";
98
+ import { pluginZero as pluginZero2 } from "@xyd-js/plugin-zero";
99
+ var __filename2 = fileURLToPath2(import.meta.url);
100
+ var __dirname2 = path2.dirname(__filename2);
101
+ var port = process.env.XYD_PORT ? parseInt(process.env.XYD_PORT) : 5175;
102
+ async function dev() {
103
+ const resp = await pluginZero2();
104
+ if (!resp) {
105
+ throw new Error("PluginZero not found");
106
+ }
107
+ const allowCwd = searchForWorkspaceRoot(process.cwd());
108
+ const preview = await createServer({
109
+ // any valid user config options, plus `mode` and `configFile`
110
+ // configFile: path.join(__dirname, "../src/vite/empty-config.ts"), // TODO: bundler??
111
+ // configFile: path.join(__dirname, "../"), // TODO: bundler??
112
+ // root: path.join(__dirname, "../"), // TODO: bundler?
113
+ root: process.env.XYD_CLI ? __dirname2 : process.env.XYD_DOCUMAN_HOST || path2.join(__dirname2, "../host"),
114
+ // TODO: bundler?
115
+ server: {
116
+ port,
117
+ fs: {
118
+ allow: [
119
+ allowCwd,
120
+ process.env.XYD_CLI ? path2.join(__dirname2, "../../") : ""
121
+ // path.join(__dirname, "../node_modules") // Ensure node_modules from xyd-documan is included
122
+ ]
123
+ }
124
+ },
125
+ build: {
126
+ rollupOptions: {
127
+ // Exclude package `B` from the client-side bundle
128
+ external: ["@xyd-js/uniform", "@xyd-js/uniform/content", "@xyd-js/plugin-zero"]
129
+ }
130
+ },
131
+ ssr: {
132
+ external: ["@xyd-js/uniform", "@xyd-js/uniform/content", "@xyd-js/plugin-zero"]
133
+ // noExternal: [
134
+ // "@xyd-js/uniform",
135
+ // "@xyd-js/uniform/content",
136
+ // "@xyd-js/plugin-zero"
137
+ // ],
138
+ },
139
+ optimizeDeps: {
140
+ include: ["react/jsx-runtime"]
141
+ },
142
+ // @ts-ignore
143
+ plugins: [
144
+ // TODO: fix plugin ts
145
+ ...xydContentVitePlugins2({
146
+ toc: {
147
+ minDepth: 2
148
+ }
149
+ }),
150
+ reactRouter2({
151
+ routes: resp.routes
152
+ }),
153
+ ...resp.vitePlugins
154
+ ]
155
+ });
156
+ await preview.listen(port);
157
+ preview.printUrls();
158
+ preview.bindCLIShortcuts({ print: true });
159
+ }
160
+
161
+ // src/run/serve.ts
162
+ import fs2 from "node:fs";
163
+ import os from "node:os";
164
+ import path3 from "node:path";
165
+ import url from "node:url";
166
+ import { createRequestHandler } from "@react-router/express";
167
+ import compression from "compression";
168
+ import express from "express";
169
+ import morgan from "morgan";
170
+ import sourceMapSupport from "source-map-support";
171
+ import getPort from "get-port";
172
+ function parseNumber(raw) {
173
+ if (raw === void 0) return void 0;
174
+ let maybe = Number(raw);
175
+ if (Number.isNaN(maybe)) return void 0;
176
+ return maybe;
177
+ }
178
+ async function serve() {
179
+ process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
180
+ sourceMapSupport.install({
181
+ retrieveSourceMap: function(source) {
182
+ let match = source.startsWith("file://");
183
+ if (match) {
184
+ let filePath = url.fileURLToPath(source);
185
+ let sourceMapPath = `${filePath}.map`;
186
+ if (fs2.existsSync(sourceMapPath)) {
187
+ return {
188
+ url: source,
189
+ map: fs2.readFileSync(sourceMapPath, "utf8")
190
+ };
191
+ }
192
+ }
193
+ return null;
194
+ }
195
+ });
196
+ let port2 = parseNumber(process.env.PORT) ?? await getPort({ port: 3e3 });
197
+ let buildPathArg = path3.join(process.cwd(), ".xyd/build/server/index.js");
198
+ if (!buildPathArg) {
199
+ console.error(`
200
+ Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);
201
+ process.exit(1);
202
+ }
203
+ let buildPath = path3.resolve(buildPathArg);
204
+ let build2 = await import(url.pathToFileURL(buildPath).href);
205
+ let onListen = () => {
206
+ let address = process.env.HOST || Object.values(os.networkInterfaces()).flat().find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
207
+ if (!address) {
208
+ console.log(`[xyd-serve] http://localhost:${port2}`);
209
+ } else {
210
+ console.log(
211
+ `[xyd-serve] http://localhost:${port2} (http://${address}:${port2})`
212
+ );
213
+ }
214
+ };
215
+ build2 = {
216
+ ...build2,
217
+ assetsBuildDirectory: path3.join(process.cwd(), ".xyd/build/client")
218
+ };
219
+ let app = express();
220
+ app.disable("x-powered-by");
221
+ app.use(compression());
222
+ app.use(
223
+ path3.posix.join(build2.publicPath, "assets"),
224
+ express.static(path3.join(build2.assetsBuildDirectory, "assets"), {
225
+ immutable: true,
226
+ maxAge: "1y"
227
+ })
228
+ );
229
+ app.use(build2.publicPath, express.static(build2.assetsBuildDirectory));
230
+ app.use(express.static("public", { maxAge: "1h" }));
231
+ app.use(morgan("tiny"));
232
+ app.all(
233
+ "*",
234
+ createRequestHandler({
235
+ build: build2,
236
+ mode: process.env.NODE_ENV
237
+ })
238
+ );
239
+ let server = process.env.HOST ? app.listen(port2, process.env.HOST, onListen) : app.listen(port2, onListen);
240
+ ["SIGTERM", "SIGINT"].forEach((signal) => {
241
+ process.once(signal, () => server?.close(console.error));
242
+ });
243
+ }
244
+ export {
245
+ build,
246
+ dev,
247
+ serve
248
+ };
249
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run/build.ts","../src/run/dev.ts","../src/run/serve.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport {fileURLToPath} from \"node:url\";\nimport {execSync} from 'child_process';\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 // TODO: probably we should have better mechanism - maybe bundle?\n\n const packageJsonPath = path.join(buildDir, 'package.json');\n\n const packageJsonContent = {\n type: \"module\",\n scripts: {},\n dependencies: { // TODO: better\n \"@xyd-js/content\": \"latest\",\n \"@xyd-js/components\": \"latest\",\n \"@xyd-js/framework\": \"latest\",\n \"@xyd-js/theme-poetry\": \"latest\",\n \"@react-router/node\": \"^7.1.1\",\n \"isbot\": \"^5\"\n },\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 // Install packages inside buildDir\n console.log('Installing dependencies...');\n execSync('npm install', {cwd: buildDir, stdio: 'inherit'});\n }\n\n try {\n // Build the client-side bundle\n await viteBuild({\n root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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_CLI ? __dirname : 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"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAQ,qBAAoB;AAC5B,SAAQ,gBAAe;AAEvB,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;AAGzC,eAAsB,QAAQ;AAC1B,QAAM,OAAO,MAAM,WAAW;AAC9B,MAAI,CAAC,MAAM;AACP,UAAM,IAAI,MAAM,sBAAsB;AAAA,EAC1C;AAEA,QAAM,WAAW,KAAK,KAAK,QAAQ,IAAI,GAAG,YAAY;AAEtD;AAGI,UAAM,kBAAkB,KAAK,KAAK,UAAU,cAAc;AAE1D,UAAM,qBAAqB;AAAA,MACvB,MAAM;AAAA,MACN,SAAS,CAAC;AAAA,MACV,cAAc;AAAA;AAAA,QACV,mBAAmB;AAAA,QACnB,sBAAsB;AAAA,QACtB,qBAAqB;AAAA,QACrB,wBAAwB;AAAA,QACxB,sBAAsB;AAAA,QACtB,SAAS;AAAA,MACb;AAAA,MACA,iBAAiB,CAAC;AAAA,IACtB;AAGA,QAAI,CAAC,GAAG,WAAW,QAAQ,GAAG;AAC1B,SAAG,UAAU,UAAU,EAAC,WAAW,KAAI,CAAC;AAAA,IAC5C;AAGA,OAAG,cAAc,iBAAiB,KAAK,UAAU,oBAAoB,MAAM,CAAC,GAAG,MAAM;AAGrF,YAAQ,IAAI,4BAA4B;AACxC,aAAS,eAAe,EAAC,KAAK,UAAU,OAAO,UAAS,CAAC;AAAA,EAC7D;AAEA,MAAI;AAEA,UAAM,UAAU;AAAA,MACZ,MAAM,QAAQ,IAAI,UAAU,YAAY,QA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/dist/serve.js ADDED
@@ -0,0 +1,110 @@
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
@@ -0,0 +1 @@
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\";\nimport {execSync} from 'child_process';\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 // TODO: probably we should have better mechanism - maybe bundle?\n\n const packageJsonPath = path.join(buildDir, 'package.json');\n\n const packageJsonContent = {\n type: \"module\",\n scripts: {},\n dependencies: { // TODO: better\n \"@xyd-js/content\": \"latest\",\n \"@xyd-js/components\": \"latest\",\n \"@xyd-js/framework\": \"latest\",\n \"@xyd-js/theme-poetry\": \"latest\",\n \"@react-router/node\": \"^7.1.1\",\n \"isbot\": \"^5\"\n },\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 // Install packages inside buildDir\n console.log('Installing dependencies...');\n execSync('npm install', {cwd: buildDir, stdio: 'inherit'});\n }\n\n try {\n // Build the client-side bundle\n await viteBuild({\n root: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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: process.env.XYD_CLI ? __dirname : process.env.XYD_DOCUMAN_HOST || 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_CLI ? __dirname : 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;AAG5B,SAAQ,SAAS,iBAAgB;AACjC,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAG1B,SAAQ,eAAe,6BAA4B;AACnD,SAAQ,kBAAiB;AAEzB,IAAM,aAAa,cAAc,YAAY,GAAG;AAChD,IAAM,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AAAA;AAAA,MACA,MAAM,QAAQ,IAAI;AAAA,IACtB,CAAC;AAAA,EACL;AAEA,MAAI,SAAS,QAAQ,IAAI,OACnB,IAAI,OAAOD,OAAM,QAAQ,IAAI,MAAM,QAAQ,IAC3C,IAAI,OAAOA,OAAM,QAAQ;AAE/B,GAAC,WAAW,QAAQ,EAAE,QAAQ,CAAC,WAAW;AACtC,YAAQ,KAAK,QAAQ,MAAM,QAAQ,MAAM,QAAQ,KAAK,CAAC;AAAA,EAC3D,CAAC;AACL;;;ACtGA,MAAM,MAAM;","names":["path","fileURLToPath","reactRouter","xydContentVitePlugins","pluginZero","__filename","__dirname","fs","path","port","build"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyd-js/documan",
3
- "version": "0.1.0-xyd.14",
3
+ "version": "0.1.0-xyd.15",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",