rari 0.1.3
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/chunk-BLXvPPr8.js +30 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +193 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/platform-CvSUcmnc.js +102 -0
- package/dist/platform-DIsErRFA.js +3 -0
- package/dist/railway-XPhB0Ls4.js +216 -0
- package/dist/render-BtA14L2P.js +218 -0
- package/dist/runtime-client-BEWMJWMx.d.ts +283 -0
- package/dist/runtime-client-CC4YQweh.js +707 -0
- package/dist/server-BvGV8m79.js +7084 -0
- package/dist/server-MY0-nRif.d.ts +69 -0
- package/dist/server-build-Cp6_RdeA.js +3 -0
- package/dist/server-build-DaBgiV55.js +618 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +5 -0
- package/package.json +96 -0
- package/src/cli.ts +236 -0
- package/src/client.ts +61 -0
- package/src/deployment/railway.ts +244 -0
- package/src/deployment/render.ts +240 -0
- package/src/index.ts +1 -0
- package/src/platform.ts +163 -0
- package/src/router/file-routes.ts +453 -0
- package/src/router/index.ts +40 -0
- package/src/router/navigation.tsx +535 -0
- package/src/router/router.tsx +504 -0
- package/src/router/types.ts +168 -0
- package/src/router/utils.ts +473 -0
- package/src/router/vite-plugin.ts +324 -0
- package/src/runtime-client.ts +415 -0
- package/src/server.ts +79 -0
- package/src/vite/index.ts +1920 -0
- package/src/vite/server-build.ts +951 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJS = (cb, mod) => function() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { __commonJS, __require, __toESM };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { getBinaryPath, getInstallationInstructions } from "./platform-CvSUcmnc.js";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import colors from "picocolors";
|
|
6
|
+
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
const [, , command, ...args] = process.argv;
|
|
9
|
+
function logInfo(message) {
|
|
10
|
+
console.warn(`${colors.blue("info")} ${message}`);
|
|
11
|
+
}
|
|
12
|
+
function logSuccess(message) {
|
|
13
|
+
console.warn(`${colors.green("✓")} ${message}`);
|
|
14
|
+
}
|
|
15
|
+
function logError(message) {
|
|
16
|
+
console.error(`${colors.red("✗")} ${message}`);
|
|
17
|
+
}
|
|
18
|
+
function isRailwayEnvironment() {
|
|
19
|
+
return !!(process.env.RAILWAY_ENVIRONMENT || process.env.RAILWAY_PROJECT_ID || process.env.RAILWAY_SERVICE_ID);
|
|
20
|
+
}
|
|
21
|
+
function isRenderEnvironment() {
|
|
22
|
+
return !!(process.env.RENDER || process.env.RENDER_SERVICE_ID || process.env.RENDER_SERVICE_NAME);
|
|
23
|
+
}
|
|
24
|
+
function isPlatformEnvironment() {
|
|
25
|
+
return isRailwayEnvironment() || isRenderEnvironment();
|
|
26
|
+
}
|
|
27
|
+
function getPlatformName() {
|
|
28
|
+
if (isRailwayEnvironment()) return "Railway";
|
|
29
|
+
if (isRenderEnvironment()) return "Render";
|
|
30
|
+
return "local";
|
|
31
|
+
}
|
|
32
|
+
function getDeploymentConfig() {
|
|
33
|
+
const port = process.env.PORT || process.env.RSC_PORT || "3000";
|
|
34
|
+
const mode = process.env.NODE_ENV === "production" ? "production" : "development";
|
|
35
|
+
const host = isPlatformEnvironment() ? "0.0.0.0" : "127.0.0.1";
|
|
36
|
+
return {
|
|
37
|
+
port,
|
|
38
|
+
mode,
|
|
39
|
+
host
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function startRustServer() {
|
|
43
|
+
let binaryPath;
|
|
44
|
+
try {
|
|
45
|
+
binaryPath = getBinaryPath();
|
|
46
|
+
} catch {
|
|
47
|
+
logError("Failed to obtain Rari binary");
|
|
48
|
+
logError(getInstallationInstructions());
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const { port, mode, host } = getDeploymentConfig();
|
|
52
|
+
if (isPlatformEnvironment()) {
|
|
53
|
+
const platformName = getPlatformName();
|
|
54
|
+
logInfo(`${platformName} environment detected`);
|
|
55
|
+
logInfo(`Starting Rari server for ${platformName} deployment...`);
|
|
56
|
+
logInfo(`Mode: ${mode}, Host: ${host}, Port: ${port}`);
|
|
57
|
+
} else logInfo(`starting Rari server in ${mode} mode on port ${port}...`);
|
|
58
|
+
logInfo(`using binary: ${binaryPath}`);
|
|
59
|
+
const args$1 = [
|
|
60
|
+
"--mode",
|
|
61
|
+
mode,
|
|
62
|
+
"--port",
|
|
63
|
+
port,
|
|
64
|
+
"--host",
|
|
65
|
+
host
|
|
66
|
+
];
|
|
67
|
+
const rustServer = spawn(binaryPath, args$1, {
|
|
68
|
+
stdio: "inherit",
|
|
69
|
+
cwd: process.cwd(),
|
|
70
|
+
env: {
|
|
71
|
+
...process.env,
|
|
72
|
+
RUST_LOG: process.env.RUST_LOG || "info"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const shutdown = () => {
|
|
76
|
+
logInfo("shutting down...");
|
|
77
|
+
rustServer.kill("SIGTERM");
|
|
78
|
+
};
|
|
79
|
+
process.on("SIGINT", shutdown);
|
|
80
|
+
process.on("SIGTERM", shutdown);
|
|
81
|
+
rustServer.on("error", (error) => {
|
|
82
|
+
logError(`Failed to start Rari server: ${error.message}`);
|
|
83
|
+
if (error.message.includes("ENOENT")) logError("Binary not found. Please ensure Rari is properly installed.");
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
rustServer.on("exit", (code, signal) => {
|
|
87
|
+
if (signal) logInfo(`server stopped by signal ${signal}`);
|
|
88
|
+
else if (code === 0) logSuccess("server stopped successfully");
|
|
89
|
+
else {
|
|
90
|
+
logError(`server exited with code ${code}`);
|
|
91
|
+
process.exit(code || 1);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return new Promise(() => {});
|
|
95
|
+
}
|
|
96
|
+
async function deployToRailway() {
|
|
97
|
+
logInfo("Setting up Railway deployment...");
|
|
98
|
+
if (isPlatformEnvironment()) {
|
|
99
|
+
logError(`Already running in ${getPlatformName()} environment. Use "rari start" instead.`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
const { createRailwayDeployment } = await import("./railway-XPhB0Ls4.js");
|
|
103
|
+
await createRailwayDeployment();
|
|
104
|
+
}
|
|
105
|
+
async function deployToRender() {
|
|
106
|
+
logInfo("Setting up Render deployment...");
|
|
107
|
+
if (isPlatformEnvironment()) {
|
|
108
|
+
logError(`Already running in ${getPlatformName()} environment. Use "rari start" instead.`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
const { createRenderDeployment } = await import("./render-BtA14L2P.js");
|
|
112
|
+
await createRenderDeployment();
|
|
113
|
+
}
|
|
114
|
+
async function main() {
|
|
115
|
+
switch (command) {
|
|
116
|
+
case "start":
|
|
117
|
+
await startRustServer();
|
|
118
|
+
break;
|
|
119
|
+
case "deploy":
|
|
120
|
+
if (args[0] === "railway") await deployToRailway();
|
|
121
|
+
else if (args[0] === "render") await deployToRender();
|
|
122
|
+
else {
|
|
123
|
+
logError("Unknown deployment target. Available: railway, render");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
case "help":
|
|
128
|
+
case "--help":
|
|
129
|
+
case "-h":
|
|
130
|
+
console.warn(`${colors.bold}Rari CLI${colors.reset}
|
|
131
|
+
|
|
132
|
+
${colors.bold}Usage:${colors.reset}
|
|
133
|
+
${colors.cyan}rari start${colors.reset} Start the Rari server
|
|
134
|
+
${colors.cyan}rari deploy railway${colors.reset} Setup Railway deployment
|
|
135
|
+
${colors.cyan}rari deploy render${colors.reset} Setup Render deployment
|
|
136
|
+
${colors.cyan}rari help${colors.reset} Show this help message
|
|
137
|
+
|
|
138
|
+
${colors.bold}Environment Variables:${colors.reset}
|
|
139
|
+
${colors.yellow}PORT${colors.reset} Server port (default: 3000)
|
|
140
|
+
${colors.yellow}RSC_PORT${colors.reset} Alternative server port
|
|
141
|
+
${colors.yellow}NODE_ENV${colors.reset} Environment (development/production)
|
|
142
|
+
${colors.yellow}RUST_LOG${colors.reset} Rust logging level (default: info)
|
|
143
|
+
|
|
144
|
+
${colors.bold}Examples:${colors.reset}
|
|
145
|
+
${colors.gray}# Start development server on port 3000${colors.reset}
|
|
146
|
+
${colors.cyan}rari start${colors.reset}
|
|
147
|
+
|
|
148
|
+
${colors.gray}# Start production server on port 8080${colors.reset}
|
|
149
|
+
${colors.cyan}PORT=8080 NODE_ENV=production rari start${colors.reset}
|
|
150
|
+
|
|
151
|
+
${colors.gray}# Setup Railway deployment${colors.reset}
|
|
152
|
+
${colors.cyan}rari deploy railway${colors.reset}
|
|
153
|
+
|
|
154
|
+
${colors.gray}# Setup Render deployment${colors.reset}
|
|
155
|
+
${colors.cyan}rari deploy render${colors.reset}
|
|
156
|
+
|
|
157
|
+
${colors.gray}# Start with debug logging${colors.reset}
|
|
158
|
+
${colors.cyan}RUST_LOG=debug rari start${colors.reset}
|
|
159
|
+
|
|
160
|
+
${colors.bold}Deployment:${colors.reset}
|
|
161
|
+
${colors.cyan}rari deploy railway${colors.reset} Creates Railway deployment files
|
|
162
|
+
${colors.cyan}rari deploy render${colors.reset} Creates Render deployment files
|
|
163
|
+
|
|
164
|
+
Platform deployment automatically detects the environment and configures:
|
|
165
|
+
- Host binding (0.0.0.0 for platforms, 127.0.0.1 for local)
|
|
166
|
+
- Port from platform's PORT environment variable
|
|
167
|
+
- Production mode optimization
|
|
168
|
+
|
|
169
|
+
${colors.bold}Binary Resolution:${colors.reset}
|
|
170
|
+
1. Platform-specific package (rari-{platform}-{arch})
|
|
171
|
+
2. Global binary in PATH
|
|
172
|
+
3. Install from source with Cargo
|
|
173
|
+
|
|
174
|
+
${colors.bold}Notes:${colors.reset}
|
|
175
|
+
- Platform binary is automatically detected and used
|
|
176
|
+
- Platform deployment is automatically detected and configured
|
|
177
|
+
- Use Ctrl+C to stop the server gracefully
|
|
178
|
+
|
|
179
|
+
`);
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
console.error(`${colors.bold}Unknown command:${colors.reset} ${command}`);
|
|
183
|
+
console.warn(`Run "${colors.cyan}rari help${colors.reset}" for available commands`);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
main().catch((error) => {
|
|
188
|
+
logError(`CLI Error: ${error.message}`);
|
|
189
|
+
console.error(error);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
//#endregion
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-BEWMJWMx.js";
|
|
2
|
+
export { type ErrorBoundaryProps, type FileRouteInfo, HttpRuntimeClient, type LayoutProps, Link, type LinkProps, type LoadingProps, Navigate, type NavigationOptions, type NavigationState, Outlet, type PageComponent, type PageProps, RouteComponent as Route, type RouteGenerationOptions, type RouteMatch, type RouteMeta, type RouteParams, type Route as RouteType, type RouterConfig, type RouterContext, RouterProvider, type RouterProviderProps, Routes, type RuntimeClient, type SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CC4YQweh.js";
|
|
2
|
+
|
|
3
|
+
export { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-BEWMJWMx.js";
|
|
2
|
+
import { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-MY0-nRif.js";
|
|
3
|
+
export { ErrorBoundaryProps, FileRouteGenerator, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, RouteComponent as Route, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, Route as RouteType, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CC4YQweh.js";
|
|
2
|
+
import { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-BvGV8m79.js";
|
|
3
|
+
import "./server-build-DaBgiV55.js";
|
|
4
|
+
|
|
5
|
+
export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { __require } from "./chunk-BLXvPPr8.js";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
|
|
6
|
+
//#region src/platform.ts
|
|
7
|
+
const SUPPORTED_PLATFORMS = {
|
|
8
|
+
"linux-x64": "rari-linux-x64",
|
|
9
|
+
"linux-arm64": "rari-linux-arm64",
|
|
10
|
+
"darwin-x64": "rari-darwin-x64",
|
|
11
|
+
"darwin-arm64": "rari-darwin-arm64",
|
|
12
|
+
"win32-x64": "rari-win32-x64"
|
|
13
|
+
};
|
|
14
|
+
function getPlatformInfo() {
|
|
15
|
+
const platform = process.platform;
|
|
16
|
+
const arch = process.arch;
|
|
17
|
+
let normalizedPlatform;
|
|
18
|
+
switch (platform) {
|
|
19
|
+
case "darwin":
|
|
20
|
+
normalizedPlatform = "darwin";
|
|
21
|
+
break;
|
|
22
|
+
case "linux":
|
|
23
|
+
normalizedPlatform = "linux";
|
|
24
|
+
break;
|
|
25
|
+
case "win32":
|
|
26
|
+
normalizedPlatform = "win32";
|
|
27
|
+
break;
|
|
28
|
+
default: throw new Error(`Unsupported platform: ${platform}. Rari supports Linux, macOS, and Windows.`);
|
|
29
|
+
}
|
|
30
|
+
let normalizedArch;
|
|
31
|
+
switch (arch) {
|
|
32
|
+
case "x64":
|
|
33
|
+
normalizedArch = "x64";
|
|
34
|
+
break;
|
|
35
|
+
case "arm64":
|
|
36
|
+
normalizedArch = "arm64";
|
|
37
|
+
break;
|
|
38
|
+
default: throw new Error(`Unsupported architecture: ${arch}. Rari supports x64 and ARM64.`);
|
|
39
|
+
}
|
|
40
|
+
const platformKey = `${normalizedPlatform}-${normalizedArch}`;
|
|
41
|
+
const packageName = SUPPORTED_PLATFORMS[platformKey];
|
|
42
|
+
if (!packageName) throw new Error(`Unsupported platform combination: ${normalizedPlatform}-${normalizedArch}. Supported platforms: ${Object.keys(SUPPORTED_PLATFORMS).join(", ")}`);
|
|
43
|
+
const binaryName = normalizedPlatform === "win32" ? "rari.exe" : "rari";
|
|
44
|
+
return {
|
|
45
|
+
platform: normalizedPlatform,
|
|
46
|
+
arch: normalizedArch,
|
|
47
|
+
packageName,
|
|
48
|
+
binaryName
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function getBinaryPath() {
|
|
52
|
+
const { packageName, binaryName } = getPlatformInfo();
|
|
53
|
+
try {
|
|
54
|
+
let currentDir = process.cwd();
|
|
55
|
+
let workspaceRoot = null;
|
|
56
|
+
while (currentDir !== "/" && currentDir !== "") {
|
|
57
|
+
const packagesDir = join(currentDir, "packages");
|
|
58
|
+
if (existsSync(packagesDir)) {
|
|
59
|
+
workspaceRoot = currentDir;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
currentDir = join(currentDir, "..");
|
|
63
|
+
}
|
|
64
|
+
if (workspaceRoot) {
|
|
65
|
+
const packageDir = join(workspaceRoot, "packages", packageName);
|
|
66
|
+
const binaryPath = join(packageDir, "bin", binaryName);
|
|
67
|
+
if (existsSync(binaryPath)) return binaryPath;
|
|
68
|
+
}
|
|
69
|
+
} catch {}
|
|
70
|
+
try {
|
|
71
|
+
const packagePath = __require.resolve(`${packageName}/package.json`);
|
|
72
|
+
const packageDir = packagePath.replace("/package.json", "");
|
|
73
|
+
const binaryPath = join(packageDir, "bin", binaryName);
|
|
74
|
+
if (existsSync(binaryPath)) return binaryPath;
|
|
75
|
+
throw new Error(`Binary not found at ${binaryPath}`);
|
|
76
|
+
} catch {
|
|
77
|
+
throw new Error(`Failed to locate Rari binary for ${packageName}. Please ensure the platform package is installed: npm install ${packageName}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function getInstallationInstructions() {
|
|
81
|
+
const { packageName } = getPlatformInfo();
|
|
82
|
+
return `
|
|
83
|
+
To install Rari for your platform, run:
|
|
84
|
+
|
|
85
|
+
npm install ${packageName}
|
|
86
|
+
|
|
87
|
+
Or if you're using pnpm:
|
|
88
|
+
|
|
89
|
+
pnpm add ${packageName}
|
|
90
|
+
|
|
91
|
+
Or if you're using yarn:
|
|
92
|
+
|
|
93
|
+
yarn add ${packageName}
|
|
94
|
+
|
|
95
|
+
If you continue to have issues, you can also install from source:
|
|
96
|
+
|
|
97
|
+
cargo install --git https://github.com/rari-build/rari
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
export { getBinaryPath, getInstallationInstructions, getPlatformInfo };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import colors from "picocolors";
|
|
5
|
+
|
|
6
|
+
//#region src/deployment/railway.ts
|
|
7
|
+
function logInfo(message) {
|
|
8
|
+
console.warn(`${colors.blue("info")} ${message}`);
|
|
9
|
+
}
|
|
10
|
+
function logSuccess(message) {
|
|
11
|
+
console.warn(`${colors.green("✓")} ${message}`);
|
|
12
|
+
}
|
|
13
|
+
function logError(message) {
|
|
14
|
+
console.error(`${colors.red("✗")} ${message}`);
|
|
15
|
+
}
|
|
16
|
+
function logWarning(message) {
|
|
17
|
+
console.warn(`${colors.yellow("⚠")} ${message}`);
|
|
18
|
+
}
|
|
19
|
+
async function createRailwayDeployment() {
|
|
20
|
+
const cwd = process.cwd();
|
|
21
|
+
logInfo("Creating Railway deployment configuration...");
|
|
22
|
+
const packageJsonPath = join(cwd, "package.json");
|
|
23
|
+
if (!existsSync(packageJsonPath)) {
|
|
24
|
+
logError("No package.json found. Please run this command from your project root.");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
29
|
+
packageJson.scripts = packageJson.scripts || {};
|
|
30
|
+
if (packageJson.scripts.start && packageJson.scripts.start !== "rari start") {
|
|
31
|
+
logWarning(`Existing start script found: "${packageJson.scripts.start}"`);
|
|
32
|
+
logWarning("Backing up to start:original and replacing with \"rari start\"");
|
|
33
|
+
packageJson.scripts["start:original"] = packageJson.scripts.start;
|
|
34
|
+
}
|
|
35
|
+
packageJson.scripts.start = "rari start";
|
|
36
|
+
packageJson.scripts["start:local"] = "rari start";
|
|
37
|
+
packageJson.scripts["deploy:railway"] = "echo \"Push to GitHub and connect to Railway to deploy\"";
|
|
38
|
+
packageJson.engines = packageJson.engines || {};
|
|
39
|
+
if (!packageJson.engines.node) packageJson.engines.node = ">=20.0.0";
|
|
40
|
+
if (!packageJson.dependencies || !packageJson.dependencies.rari) {
|
|
41
|
+
logInfo("Adding rari dependency...");
|
|
42
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
43
|
+
packageJson.dependencies.rari = "^0.1.0";
|
|
44
|
+
}
|
|
45
|
+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
46
|
+
logSuccess("Updated package.json for Railway deployment");
|
|
47
|
+
} catch (error) {
|
|
48
|
+
logError(`Failed to update package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const railwayConfig = {
|
|
52
|
+
$schema: "https://railway.app/railway.schema.json",
|
|
53
|
+
build: { builder: "NIXPACKS" },
|
|
54
|
+
deploy: {
|
|
55
|
+
startCommand: "npm start",
|
|
56
|
+
healthcheckPath: "/",
|
|
57
|
+
healthcheckTimeout: 300,
|
|
58
|
+
restartPolicyType: "ALWAYS"
|
|
59
|
+
},
|
|
60
|
+
environments: { production: { variables: {
|
|
61
|
+
NODE_ENV: "production",
|
|
62
|
+
RUST_LOG: "info"
|
|
63
|
+
} } }
|
|
64
|
+
};
|
|
65
|
+
const railwayJsonPath = join(cwd, "railway.json");
|
|
66
|
+
if (existsSync(railwayJsonPath)) {
|
|
67
|
+
logWarning("railway.json already exists, backing up to railway.json.backup");
|
|
68
|
+
const existingConfig = readFileSync(railwayJsonPath, "utf-8");
|
|
69
|
+
writeFileSync(join(cwd, "railway.json.backup"), existingConfig);
|
|
70
|
+
}
|
|
71
|
+
writeFileSync(railwayJsonPath, `${JSON.stringify(railwayConfig, null, 2)}\n`);
|
|
72
|
+
logSuccess("Created railway.json configuration");
|
|
73
|
+
const gitignorePath = join(cwd, ".gitignore");
|
|
74
|
+
const railwayGitignoreEntries = [
|
|
75
|
+
"",
|
|
76
|
+
"# Railway",
|
|
77
|
+
".railway/",
|
|
78
|
+
""
|
|
79
|
+
].join("\n");
|
|
80
|
+
if (existsSync(gitignorePath)) {
|
|
81
|
+
const gitignoreContent = readFileSync(gitignorePath, "utf-8");
|
|
82
|
+
if (!gitignoreContent.includes(".railway/")) {
|
|
83
|
+
writeFileSync(gitignorePath, gitignoreContent + railwayGitignoreEntries);
|
|
84
|
+
logSuccess("Updated .gitignore with Railway entries");
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
const defaultGitignore = `# Dependencies
|
|
88
|
+
node_modules/
|
|
89
|
+
.pnpm-store/
|
|
90
|
+
|
|
91
|
+
# Build outputs
|
|
92
|
+
.rari/
|
|
93
|
+
dist/
|
|
94
|
+
|
|
95
|
+
# Environment variables
|
|
96
|
+
.env
|
|
97
|
+
.env.local
|
|
98
|
+
.env.production
|
|
99
|
+
|
|
100
|
+
# Railway
|
|
101
|
+
.railway/
|
|
102
|
+
|
|
103
|
+
# Logs
|
|
104
|
+
*.log
|
|
105
|
+
npm-debug.log*
|
|
106
|
+
pnpm-debug.log*
|
|
107
|
+
|
|
108
|
+
# OS files
|
|
109
|
+
.DS_Store
|
|
110
|
+
Thumbs.db
|
|
111
|
+
|
|
112
|
+
# IDE files
|
|
113
|
+
.vscode/
|
|
114
|
+
.idea/
|
|
115
|
+
*.swp
|
|
116
|
+
*.swo
|
|
117
|
+
*~
|
|
118
|
+
|
|
119
|
+
# Temporary files
|
|
120
|
+
.tmp/
|
|
121
|
+
tmp/
|
|
122
|
+
`;
|
|
123
|
+
writeFileSync(gitignorePath, defaultGitignore);
|
|
124
|
+
logSuccess("Created .gitignore with Railway entries");
|
|
125
|
+
}
|
|
126
|
+
const readmePath = join(cwd, "README.md");
|
|
127
|
+
const railwayReadmeSection = `
|
|
128
|
+
## 🚂 Deploy to Railway
|
|
129
|
+
|
|
130
|
+
This Rari application is configured for Railway deployment.
|
|
131
|
+
|
|
132
|
+
### Quick Deploy
|
|
133
|
+
|
|
134
|
+
1. **Push to GitHub**:
|
|
135
|
+
\`\`\`bash
|
|
136
|
+
git add .
|
|
137
|
+
git commit -m "Add Railway deployment"
|
|
138
|
+
git push origin main
|
|
139
|
+
\`\`\`
|
|
140
|
+
|
|
141
|
+
2. **Deploy to Railway**:
|
|
142
|
+
- Go to [railway.app](https://railway.app)
|
|
143
|
+
- Create new project → "Deploy from GitHub repo"
|
|
144
|
+
- Select your repository
|
|
145
|
+
- Click "Deploy Now"
|
|
146
|
+
|
|
147
|
+
3. **Generate Domain**:
|
|
148
|
+
- In Railway dashboard → Settings → Networking
|
|
149
|
+
- Click "Generate Domain"
|
|
150
|
+
- Your app will be live! 🎉
|
|
151
|
+
|
|
152
|
+
### Local Development
|
|
153
|
+
|
|
154
|
+
\`\`\`bash
|
|
155
|
+
# Development server
|
|
156
|
+
npm run start:local
|
|
157
|
+
|
|
158
|
+
# Production simulation
|
|
159
|
+
npm start
|
|
160
|
+
\`\`\`
|
|
161
|
+
|
|
162
|
+
### Environment Variables
|
|
163
|
+
|
|
164
|
+
Railway automatically provides:
|
|
165
|
+
- \`PORT\` - Server port (Railway assigns this)
|
|
166
|
+
- \`NODE_ENV=production\` - Production mode
|
|
167
|
+
|
|
168
|
+
Optional variables you can set:
|
|
169
|
+
- \`RUST_LOG=debug\` - Rust logging level
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
`;
|
|
173
|
+
if (existsSync(readmePath)) {
|
|
174
|
+
const readmeContent = readFileSync(readmePath, "utf-8");
|
|
175
|
+
if (!readmeContent.includes("Deploy to Railway")) {
|
|
176
|
+
writeFileSync(readmePath, readmeContent + railwayReadmeSection);
|
|
177
|
+
logSuccess("Updated README.md with Railway deployment instructions");
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
const defaultReadme = `# My Rari App
|
|
181
|
+
|
|
182
|
+
A high-performance React Server Components application powered by Rari.
|
|
183
|
+
${railwayReadmeSection}
|
|
184
|
+
## Getting Started
|
|
185
|
+
|
|
186
|
+
\`\`\`bash
|
|
187
|
+
npm install
|
|
188
|
+
npm start
|
|
189
|
+
\`\`\`
|
|
190
|
+
|
|
191
|
+
Visit [http://localhost:3000](http://localhost:3000) to see your app.
|
|
192
|
+
`;
|
|
193
|
+
writeFileSync(readmePath, defaultReadme);
|
|
194
|
+
logSuccess("Created README.md with Railway deployment instructions");
|
|
195
|
+
}
|
|
196
|
+
console.warn("");
|
|
197
|
+
logSuccess("Railway deployment setup complete! 🎉");
|
|
198
|
+
console.warn("");
|
|
199
|
+
logInfo("Next steps:");
|
|
200
|
+
console.warn(` 1. ${colors.cyan("git add .")}`);
|
|
201
|
+
console.warn(` 2. ${colors.cyan("git commit -m \"Add Railway deployment\"")}`);
|
|
202
|
+
console.warn(` 3. ${colors.cyan("git push origin main")}`);
|
|
203
|
+
console.warn(` 4. Go to ${colors.cyan("https://railway.app")} and deploy from GitHub`);
|
|
204
|
+
console.warn("");
|
|
205
|
+
logInfo("Your Rari app will automatically:");
|
|
206
|
+
console.warn(" ✅ Detect Railway environment");
|
|
207
|
+
console.warn(" ✅ Bind to 0.0.0.0 (Railway requirement)");
|
|
208
|
+
console.warn(" ✅ Use Railway's PORT environment variable");
|
|
209
|
+
console.warn(" ✅ Run in production mode");
|
|
210
|
+
console.warn(" ✅ Download platform-specific Rari binary");
|
|
211
|
+
console.warn("");
|
|
212
|
+
logSuccess("Ready for deployment! 🚀");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
export { createRailwayDeployment };
|