@celsian/adapter-railway 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ThenJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,38 @@
1
+ export interface RailwayAdapterOptions {
2
+ /** Node.js version (default: '20') */
3
+ nodeVersion?: string;
4
+ /** Health check path (default: '/api/health') */
5
+ healthCheckPath?: string;
6
+ /** Enable Railway's restart policy (default: true) */
7
+ restartPolicy?: boolean;
8
+ /** Region hint — Railway handles this via dashboard but we document it */
9
+ region?: string;
10
+ /** Whether to generate a Dockerfile (default: false — let Nixpacks handle it) */
11
+ dockerfile?: boolean;
12
+ }
13
+ export interface DeployAdapter {
14
+ name: string;
15
+ buildEnd(options: {
16
+ serverEntry: string;
17
+ clientDir: string;
18
+ staticDir: string;
19
+ outDir: string;
20
+ }): Promise<void>;
21
+ }
22
+ /**
23
+ * Create a Railway deployment adapter.
24
+ *
25
+ * Usage in then.config.ts:
26
+ * ```ts
27
+ * import { railwayAdapter } from '@celsian/adapter-railway';
28
+ *
29
+ * export default defineConfig({
30
+ * build: {
31
+ * adapter: railwayAdapter({ healthCheckPath: '/api/health' }),
32
+ * },
33
+ * });
34
+ * ```
35
+ */
36
+ export declare function railwayAdapter(options?: RailwayAdapterOptions): DeployAdapter;
37
+ export default railwayAdapter;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sDAAsD;IACtD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,OAAO,EAAE;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,aAAa,CAwEjF;AAmCD,eAAe,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,123 @@
1
+ // @celsian/adapter-railway — Deploy CelsianJS apps to Railway
2
+ //
3
+ // Railway supports:
4
+ // - Automatic builds with Nixpacks (detects Node.js)
5
+ // - Custom Dockerfiles
6
+ // - Health checks
7
+ // - Environment variables
8
+ // - Private networking
9
+ //
10
+ // This adapter generates the deployment-specific files that Railway needs.
11
+ import { writeFile } from 'node:fs/promises';
12
+ import { join } from 'node:path';
13
+ /**
14
+ * Create a Railway deployment adapter.
15
+ *
16
+ * Usage in then.config.ts:
17
+ * ```ts
18
+ * import { railwayAdapter } from '@celsian/adapter-railway';
19
+ *
20
+ * export default defineConfig({
21
+ * build: {
22
+ * adapter: railwayAdapter({ healthCheckPath: '/api/health' }),
23
+ * },
24
+ * });
25
+ * ```
26
+ */
27
+ export function railwayAdapter(options = {}) {
28
+ const nodeVersion = options.nodeVersion ?? '20';
29
+ const healthCheckPath = options.healthCheckPath ?? '/api/health';
30
+ const generateDockerfile = options.dockerfile ?? false;
31
+ return {
32
+ name: 'railway',
33
+ async buildEnd({ outDir }) {
34
+ // 1. Generate Procfile — Railway uses this to start the app
35
+ const procfile = `web: node dist/server/entry.js\n`;
36
+ await writeFile(join(outDir, 'Procfile'), procfile);
37
+ // 2. Generate railway.json — deployment config
38
+ const railwayConfig = {
39
+ $schema: 'https://railway.app/railway.schema.json',
40
+ build: {
41
+ builder: generateDockerfile ? 'DOCKERFILE' : 'NIXPACKS',
42
+ nixpacksPlan: generateDockerfile ? undefined : {
43
+ providers: ['node'],
44
+ phases: {
45
+ setup: { nixPkgs: [`nodejs_${nodeVersion}`] },
46
+ install: { cmds: ['npm ci --production'] },
47
+ },
48
+ },
49
+ },
50
+ deploy: {
51
+ startCommand: 'node dist/server/entry.js',
52
+ healthcheckPath: healthCheckPath,
53
+ healthcheckTimeout: 10,
54
+ restartPolicyType: options.restartPolicy !== false ? 'ON_FAILURE' : 'NEVER',
55
+ restartPolicyMaxRetries: 3,
56
+ },
57
+ };
58
+ await writeFile(join(outDir, 'railway.json'), JSON.stringify(railwayConfig, null, 2) + '\n');
59
+ // 3. Optionally generate Dockerfile
60
+ if (generateDockerfile) {
61
+ const dockerfile = generateRailwayDockerfile(nodeVersion);
62
+ await writeFile(join(outDir, 'Dockerfile'), dockerfile);
63
+ }
64
+ // 4. Generate .env.example for Railway env vars
65
+ const envExample = [
66
+ '# CelsianJS — Railway Environment Variables',
67
+ '# These are automatically injected by Railway',
68
+ '',
69
+ '# Server',
70
+ 'PORT=3000',
71
+ 'HOST=0.0.0.0',
72
+ 'NODE_ENV=production',
73
+ '',
74
+ '# Railway provides these automatically:',
75
+ '# RAILWAY_ENVIRONMENT',
76
+ '# RAILWAY_GIT_COMMIT_SHA',
77
+ '# RAILWAY_SERVICE_NAME',
78
+ '',
79
+ ].join('\n');
80
+ await writeFile(join(outDir, '.env.example'), envExample);
81
+ console.log('[celsian:adapter-railway] Generated deployment files:');
82
+ console.log(' → Procfile');
83
+ console.log(' → railway.json');
84
+ if (generateDockerfile)
85
+ console.log(' → Dockerfile');
86
+ console.log(' → .env.example');
87
+ },
88
+ };
89
+ }
90
+ function generateRailwayDockerfile(nodeVersion) {
91
+ return `# CelsianJS — Railway Dockerfile
92
+ # Generated by @celsian/adapter-railway
93
+
94
+ FROM node:${nodeVersion}-alpine AS base
95
+ WORKDIR /app
96
+
97
+ # Install dependencies
98
+ FROM base AS deps
99
+ COPY package.json package-lock.json* pnpm-lock.yaml* ./
100
+ RUN \\
101
+ if [ -f pnpm-lock.yaml ]; then corepack enable && pnpm install --frozen-lockfile --prod; \\
102
+ elif [ -f package-lock.json ]; then npm ci --production; \\
103
+ else npm install --production; fi
104
+
105
+ # Production image
106
+ FROM base AS runner
107
+ ENV NODE_ENV=production
108
+ ENV PORT=3000
109
+ ENV HOST=0.0.0.0
110
+
111
+ COPY --from=deps /app/node_modules ./node_modules
112
+ COPY dist/ ./dist/
113
+
114
+ EXPOSE 3000
115
+
116
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \\
117
+ CMD wget -qO- http://localhost:3000/api/health || exit 1
118
+
119
+ CMD ["node", "dist/server/entry.js"]
120
+ `;
121
+ }
122
+ export default railwayAdapter;
123
+ //# sourceM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BAAkB,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,WAAmB;IACpD,OAAO;;;YAGG,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BtB,CAAC;AACF,CAAC;AAED,eAAe,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@celsian/adapter-railway",
3
+ "version": "0.1.0",
4
+ "description": "CelsianJS adapter for Railway — generates Procfile, Dockerfile, and health check config",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@celsian/server": "0.1.0"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc -b"
26
+ }
27
+ }