@cedarjs/cli 4.2.0 → 4.2.1-next.258
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/cfw.js +8 -6
- package/dist/commands/build/buildHandler.js +43 -42
- package/dist/commands/build/buildPackagesTask.js +6 -6
- package/dist/commands/build.js +7 -1
- package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
- package/dist/commands/deploy/baremetal/baremetalHandler.js +117 -65
- package/dist/commands/deploy/baremetal.js +24 -3
- package/dist/commands/deploy/flightcontrolHandler.js +16 -14
- package/dist/commands/deploy/helpers/deployHandler.js +10 -5
- package/dist/commands/deploy/packing/nft.js +1 -2
- package/dist/commands/deploy/render.js +1 -1
- package/dist/commands/deploy/renderHandler.js +22 -12
- package/dist/commands/deploy/serverlessHandler.js +67 -25
- package/dist/commands/destroy/component/component.js +2 -3
- package/dist/commands/destroy/directive/directive.js +1 -3
- package/dist/commands/destroy/directive/directiveHandler.js +2 -4
- package/dist/commands/destroy/function/function.js +1 -3
- package/dist/commands/destroy/handlerHelpers.js +16 -16
- package/dist/commands/destroy/helpers.js +8 -2
- package/dist/commands/destroy/layout/layout.js +1 -2
- package/dist/commands/destroy/page/pageHandler.js +1 -1
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +28 -9
- package/dist/commands/destroy/sdl/sdlHandler.js +1 -1
- package/dist/commands/dev/devHandler.js +25 -25
- package/dist/commands/dev.js +3 -0
- package/dist/commands/experimental/live-queries/liveQueriesHandler.js +110 -4
- package/dist/commands/experimental/setupInngest.js +1 -1
- package/dist/commands/experimental/setupInngestHandler.js +12 -11
- package/dist/commands/experimental/setupOpentelemetry.js +1 -1
- package/dist/commands/experimental/setupOpentelemetryHandler.js +11 -7
- package/dist/commands/experimental/setupReactCompiler.js +1 -1
- package/dist/commands/experimental/setupReactCompilerHandler.js +45 -30
- package/dist/commands/experimental/setupRscHandler.js +14 -11
- package/dist/commands/experimental/setupStreamingSsr.js +1 -1
- package/dist/commands/experimental/setupStreamingSsrHandler.js +46 -31
- package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
- package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
- package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
- package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
- package/dist/commands/experimental/util.js +3 -2
- package/dist/commands/generate/cell/cellHandler.js +22 -21
- package/dist/commands/generate/component/componentHandler.js +14 -16
- package/dist/commands/generate/dataMigration/dataMigration.js +24 -13
- package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +40 -30
- package/dist/commands/generate/directive/directiveHandler.js +12 -14
- package/dist/commands/generate/function/function.js +1 -0
- package/dist/commands/generate/function/functionHandler.js +12 -17
- package/dist/commands/generate/helpers.js +17 -17
- package/dist/commands/generate/job/job.js +1 -0
- package/dist/commands/generate/job/jobHandler.js +15 -17
- package/dist/commands/generate/layout/layoutHandler.js +13 -16
- package/dist/commands/generate/model/model.js +1 -0
- package/dist/commands/generate/model/modelHandler.js +9 -3
- package/dist/commands/generate/ogImage/ogImage.js +1 -0
- package/dist/commands/generate/ogImage/ogImageHandler.js +16 -9
- package/dist/commands/generate/package/packageHandler.js +32 -49
- package/dist/commands/generate/page/pageHandler.js +25 -22
- package/dist/commands/generate/realtime/realtime.js +1 -1
- package/dist/commands/generate/realtime/realtimeHandler.js +46 -20
- package/dist/commands/generate/scaffold/scaffold.js +1 -0
- package/dist/commands/generate/scaffold/scaffoldHandler.js +35 -27
- package/dist/commands/generate/script/script.js +1 -0
- package/dist/commands/generate/script/templates/tsconfig.json.template +14 -0
- package/dist/commands/generate/sdl/sdl.js +4 -3
- package/dist/commands/generate/sdl/sdlHandler.js +38 -18
- package/dist/commands/generate/secret/secret.js +19 -19
- package/dist/commands/generate/service/service.js +5 -5
- package/dist/commands/generate/service/serviceHandler.js +59 -22
- package/dist/commands/generate/yargsCommandHelpers.js +6 -1
- package/dist/commands/generate/yargsHandlerHelpers.js +18 -10
- package/dist/commands/generate.js +3 -10
- package/dist/commands/jobsHandler.js +3 -2
- package/dist/commands/prismaHandler.js +10 -9
- package/dist/commands/serve.js +84 -137
- package/dist/commands/serveApiHandler.js +5 -5
- package/dist/commands/serveBothHandler.js +10 -7
- package/dist/commands/serveWebHandler.js +2 -2
- package/dist/commands/setup/auth/auth.js +12 -6
- package/dist/commands/setup/cache/cacheHandler.js +11 -6
- package/dist/commands/setup/deploy/deploy.js +4 -3
- package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
- package/dist/commands/setup/deploy/helpers/index.js +157 -5
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +26 -4
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +53 -25
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +33 -23
- package/dist/commands/setup/deploy/providers/netlify.js +6 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +112 -11
- package/dist/commands/setup/deploy/providers/renderHandler.js +10 -5
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +5 -3
- package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
- package/dist/commands/setup/deploy/providers/universalDeployHandler.js +188 -0
- package/dist/commands/setup/deploy/providers/vercel.js +6 -0
- package/dist/commands/setup/deploy/providers/vercelHandler.js +113 -12
- package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
- package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
- package/dist/commands/setup/deploy/templates/netlify.js +2 -1
- package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
- package/dist/commands/setup/docker/docker.js +1 -1
- package/dist/commands/setup/docker/dockerHandler.js +72 -37
- package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
- package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
- package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +1 -1
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +2 -2
- package/dist/commands/setup/generator/generatorHandler.js +4 -3
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +2 -2
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +2 -2
- package/dist/commands/setup/i18n/i18nHandler.js +18 -15
- package/dist/commands/setup/jobs/jobsHandler.js +10 -5
- package/dist/commands/setup/mailer/mailerHandler.js +11 -9
- package/dist/commands/setup/package/packageHandler.js +14 -10
- package/dist/commands/setup/realtime/realtimeHandler.js +22 -20
- package/dist/commands/setup/server-file/serverFileHandler.js +16 -8
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +5 -3
- package/dist/commands/setup/ui/helpers/helpers.js +5 -1
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +11 -5
- package/dist/commands/setup/ui/libraries/mantineHandler.js +21 -13
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +38 -26
- package/dist/commands/setup/uploads/uploadsHandler.js +7 -4
- package/dist/commands/setup.js +1 -2
- package/dist/commands/test/testHandler.js +2 -1
- package/dist/commands/test/testHandlerEsm.js +2 -2
- package/dist/commands/type-checkHandler.js +4 -6
- package/dist/commands/upgrade/upgradeHandler.js +2 -4
- package/dist/index.js +10 -4
- package/dist/lib/configureStorybook.js +2 -2
- package/dist/lib/exec.js +36 -24
- package/dist/lib/exit.js +19 -4
- package/dist/lib/extendFile.js +22 -12
- package/dist/lib/index.js +119 -85
- package/dist/lib/merge/algorithms.js +4 -1
- package/dist/lib/merge/index.js +76 -41
- package/dist/lib/merge/semanticIdentity.js +18 -6
- package/dist/lib/merge/strategy.js +86 -36
- package/dist/lib/packages.js +23 -13
- package/dist/lib/plugin.js +12 -5
- package/dist/lib/pluralHelpers.js +1 -1
- package/dist/lib/project.js +3 -1
- package/dist/lib/rollback.js +7 -7
- package/dist/lib/schemaHelpers.js +12 -12
- package/dist/lib/test.js +4 -0
- package/dist/lib/updateCheck.js +6 -4
- package/dist/middleware/checkNodeVersion.js +5 -0
- package/dist/plugin.js +18 -12
- package/dist/telemetry/exporter.js +12 -5
- package/dist/telemetry/index.js +4 -3
- package/dist/telemetry/resource.js +9 -5
- package/dist/telemetry/send.js +14 -10
- package/package.json +15 -12
- package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
- package/dist/commands/setup/vite/vite.js +0 -38
- package/dist/commands/setup/vite/viteHandler.js +0 -82
- /package/dist/{index.d.js → global.d.js} +0 -0
package/dist/commands/serve.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { fork } from "node:child_process";
|
|
2
1
|
import fs from "node:fs";
|
|
3
|
-
import net from "node:net";
|
|
4
2
|
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { serve as serveSrvx } from "srvx";
|
|
5
5
|
import { terminalLink } from "termi-link";
|
|
6
6
|
import * as apiServerCLIConfig from "@cedarjs/api-server/apiCliConfig";
|
|
7
7
|
import * as bothServerCLIConfig from "@cedarjs/api-server/bothCliConfig";
|
|
@@ -11,6 +11,35 @@ import * as webServerCLIConfig from "@cedarjs/web-server";
|
|
|
11
11
|
import { getPaths, getConfig } from "../lib/index.js";
|
|
12
12
|
import { serverFileExists } from "../lib/project.js";
|
|
13
13
|
import { webSsrServerHandler } from "./serveWebHandler.js";
|
|
14
|
+
function resolveUDEntryPath() {
|
|
15
|
+
const base = path.join(getPaths().api.dist, "ud", "index");
|
|
16
|
+
for (const ext of [".mjs", ".js"]) {
|
|
17
|
+
const entryPath = base + ext;
|
|
18
|
+
if (fs.existsSync(entryPath)) {
|
|
19
|
+
return entryPath;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
async function startUDServer(entryPath, host, port) {
|
|
25
|
+
const mod = await import(pathToFileURL(entryPath).href);
|
|
26
|
+
const fetchable = mod.default ?? mod;
|
|
27
|
+
if (!fetchable || typeof fetchable.fetch !== "function") {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`UD entry at ${entryPath} does not export a Fetchable (\`export default { fetch }\`).`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const server = serveSrvx({
|
|
33
|
+
...fetchable,
|
|
34
|
+
port,
|
|
35
|
+
hostname: host,
|
|
36
|
+
gracefulShutdown: false,
|
|
37
|
+
manual: true
|
|
38
|
+
});
|
|
39
|
+
server.serve();
|
|
40
|
+
await server.ready();
|
|
41
|
+
return server;
|
|
42
|
+
}
|
|
14
43
|
const command = "serve [side]";
|
|
15
44
|
const description = "Start a server for serving both the api and web sides";
|
|
16
45
|
const builder = async (yargs) => {
|
|
@@ -43,14 +72,11 @@ const builder = async (yargs) => {
|
|
|
43
72
|
);
|
|
44
73
|
process.exit(1);
|
|
45
74
|
}
|
|
46
|
-
const udEntryPath =
|
|
47
|
-
if (!
|
|
75
|
+
const udEntryPath = resolveUDEntryPath();
|
|
76
|
+
if (!udEntryPath) {
|
|
48
77
|
console.error(
|
|
49
78
|
c.error(
|
|
50
|
-
`
|
|
51
|
-
Universal Deploy server entry not found at ${udEntryPath}.
|
|
52
|
-
Please run \`yarn cedar build --ud\` before serving.
|
|
53
|
-
`
|
|
79
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
54
80
|
)
|
|
55
81
|
);
|
|
56
82
|
process.exit(1);
|
|
@@ -77,61 +103,52 @@ const builder = async (yargs) => {
|
|
|
77
103
|
const webPort = argv.webPort ?? getWebPort();
|
|
78
104
|
const webHost = argv.webHost ?? getWebHost();
|
|
79
105
|
const apiRootPath = argv.apiRootPath ?? "/";
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const apiTarget = `http://${apiHost.includes(":") ? `[${apiHost}]` : apiHost}:${apiPort}`;
|
|
107
|
+
const { serveStatic } = await import("srvx/static");
|
|
108
|
+
const apiUrl = getConfig().web.apiUrl;
|
|
109
|
+
const webDist = getPaths().web.dist;
|
|
110
|
+
const prerenderIndexPath = path.join(webDist, "200.html");
|
|
111
|
+
const fallbackIndexPath = fs.existsSync(prerenderIndexPath) ? prerenderIndexPath : path.join(webDist, "index.html");
|
|
112
|
+
const spaHtml = fs.readFileSync(fallbackIndexPath, "utf-8");
|
|
113
|
+
const webServer = serveSrvx({
|
|
114
|
+
// Dummy fetch handler. All requests are handled by middleware
|
|
115
|
+
fetch: async () => new Response("Not Found", { status: 404 }),
|
|
116
|
+
middleware: [
|
|
117
|
+
serveStatic({ dir: webDist }),
|
|
118
|
+
async (req, next) => {
|
|
119
|
+
const url = new URL(req.url, "http://localhost");
|
|
120
|
+
if (!url.pathname.startsWith(apiUrl)) {
|
|
121
|
+
return next();
|
|
122
|
+
}
|
|
123
|
+
const targetPath = url.pathname.slice(apiUrl.length) || "/";
|
|
124
|
+
const root = apiRootPath === "/" ? "" : apiRootPath;
|
|
125
|
+
const targetUrl = `${apiTarget}${root}${targetPath}${url.search}`;
|
|
126
|
+
return fetch(targetUrl, {
|
|
127
|
+
method: req.method,
|
|
128
|
+
headers: req.headers,
|
|
129
|
+
body: req.body,
|
|
130
|
+
// @ts-expect-error - `duplex` is required when forwarding a
|
|
131
|
+
// request body via fetch (Node 18+).
|
|
132
|
+
duplex: "half"
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
() => {
|
|
136
|
+
const headers = { "Content-Type": "text/html" };
|
|
137
|
+
return new Response(spaHtml, { headers });
|
|
109
138
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
Failed to start UD API server: ${err.message}
|
|
116
|
-
`)
|
|
117
|
-
);
|
|
118
|
-
process.exit(1);
|
|
119
|
-
});
|
|
120
|
-
child.on("exit", (code) => {
|
|
121
|
-
if (code !== 0) {
|
|
122
|
-
console.error(
|
|
123
|
-
c.error(`
|
|
124
|
-
UD API server exited with code ${code}
|
|
125
|
-
`)
|
|
126
|
-
);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
}
|
|
139
|
+
],
|
|
140
|
+
port: webPort,
|
|
141
|
+
hostname: webHost,
|
|
142
|
+
gracefulShutdown: false,
|
|
143
|
+
manual: true
|
|
129
144
|
});
|
|
145
|
+
webServer.serve();
|
|
146
|
+
await webServer.ready();
|
|
130
147
|
console.log(`Web server listening at http://${webHost}:${webPort}`);
|
|
131
148
|
process.stdout.write(
|
|
132
149
|
`API server starting at http://${apiHost}:${apiPort}...`
|
|
133
150
|
);
|
|
134
|
-
await
|
|
151
|
+
await startUDServer(udEntryPath, apiHost, apiPort);
|
|
135
152
|
process.stdout.write(
|
|
136
153
|
`\rAPI server listening at http://${apiHost}:${apiPort}
|
|
137
154
|
`
|
|
@@ -177,61 +194,25 @@ const builder = async (yargs) => {
|
|
|
177
194
|
apiRootPath: argv.apiRootPath
|
|
178
195
|
});
|
|
179
196
|
if (argv.ud) {
|
|
180
|
-
const udEntryPath =
|
|
181
|
-
if (!
|
|
197
|
+
const udEntryPath = resolveUDEntryPath();
|
|
198
|
+
if (!udEntryPath) {
|
|
182
199
|
console.error(
|
|
183
200
|
c.error(
|
|
184
|
-
`
|
|
185
|
-
Universal Deploy server entry not found at ${udEntryPath}.
|
|
186
|
-
Please run \`yarn cedar build --ud\` before serving.
|
|
187
|
-
`
|
|
201
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
188
202
|
)
|
|
189
203
|
);
|
|
190
204
|
process.exit(1);
|
|
191
205
|
}
|
|
192
|
-
const udArgs = [];
|
|
193
|
-
if (argv.port) {
|
|
194
|
-
udArgs.push("--port", String(argv.port));
|
|
195
|
-
}
|
|
196
|
-
if (argv.host) {
|
|
197
|
-
udArgs.push("--host", argv.host);
|
|
198
|
-
}
|
|
199
|
-
const child = fork(udEntryPath, udArgs, {
|
|
200
|
-
execArgv: process.execArgv,
|
|
201
|
-
env: {
|
|
202
|
-
...process.env,
|
|
203
|
-
NODE_ENV: process.env.NODE_ENV ?? "production",
|
|
204
|
-
PORT: argv.port ? String(argv.port) : process.env.PORT,
|
|
205
|
-
HOST: argv.host ?? process.env.HOST
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
child.on("error", (err) => {
|
|
209
|
-
console.error(
|
|
210
|
-
c.error(`
|
|
211
|
-
Failed to start UD server: ${err.message}
|
|
212
|
-
`)
|
|
213
|
-
);
|
|
214
|
-
process.exit(1);
|
|
215
|
-
});
|
|
216
206
|
const apiPort = argv.port ?? parseInt(process.env.PORT ?? "8911", 10);
|
|
217
207
|
const apiHost = argv.host ?? process.env.HOST ?? "localhost";
|
|
218
208
|
process.stdout.write(
|
|
219
209
|
`API server starting at http://${apiHost}:${apiPort}...`
|
|
220
210
|
);
|
|
221
|
-
await
|
|
211
|
+
await startUDServer(udEntryPath, apiHost, apiPort);
|
|
222
212
|
process.stdout.write(
|
|
223
213
|
`\rAPI server listening at http://${apiHost}:${apiPort}
|
|
224
214
|
`
|
|
225
215
|
);
|
|
226
|
-
await new Promise((resolve, reject) => {
|
|
227
|
-
child.on("exit", (code) => {
|
|
228
|
-
if (code !== 0) {
|
|
229
|
-
reject(new Error(`UD server exited with code ${code}`));
|
|
230
|
-
} else {
|
|
231
|
-
resolve();
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
216
|
return;
|
|
236
217
|
}
|
|
237
218
|
if (serverFileExists()) {
|
|
@@ -296,14 +277,11 @@ const builder = async (yargs) => {
|
|
|
296
277
|
process.exit(1);
|
|
297
278
|
}
|
|
298
279
|
if (argv.ud) {
|
|
299
|
-
const udEntryPath =
|
|
300
|
-
if (!
|
|
280
|
+
const udEntryPath = resolveUDEntryPath();
|
|
281
|
+
if (!udEntryPath) {
|
|
301
282
|
console.error(
|
|
302
283
|
c.error(
|
|
303
|
-
`
|
|
304
|
-
Universal Deploy server entry not found at ${udEntryPath}.
|
|
305
|
-
Please run \`yarn cedar build --ud\` before serving.
|
|
306
|
-
`
|
|
284
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
307
285
|
)
|
|
308
286
|
);
|
|
309
287
|
process.exit(1);
|
|
@@ -320,14 +298,11 @@ const builder = async (yargs) => {
|
|
|
320
298
|
process.exit(1);
|
|
321
299
|
}
|
|
322
300
|
if (argv.ud) {
|
|
323
|
-
const udEntryPath =
|
|
324
|
-
if (!
|
|
301
|
+
const udEntryPath = resolveUDEntryPath();
|
|
302
|
+
if (!udEntryPath) {
|
|
325
303
|
console.error(
|
|
326
304
|
c.error(
|
|
327
|
-
`
|
|
328
|
-
Universal Deploy server entry not found at ${udEntryPath}.
|
|
329
|
-
Please run \`yarn cedar build --ud\` before serving.
|
|
330
|
-
`
|
|
305
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
331
306
|
)
|
|
332
307
|
);
|
|
333
308
|
process.exit(1);
|
|
@@ -372,34 +347,6 @@ function webSideIsBuilt(isStreamingOrRSC) {
|
|
|
372
347
|
return fs.existsSync(path.join(getPaths().web.dist, "index.html"));
|
|
373
348
|
}
|
|
374
349
|
}
|
|
375
|
-
function waitForPort(host, port) {
|
|
376
|
-
const maxAttempts = 50;
|
|
377
|
-
const intervalMs = 200;
|
|
378
|
-
return new Promise((resolve, reject) => {
|
|
379
|
-
let attempts = 0;
|
|
380
|
-
const tryConnect = () => {
|
|
381
|
-
attempts++;
|
|
382
|
-
const socket = net.createConnection({ host, port });
|
|
383
|
-
socket.on("connect", () => {
|
|
384
|
-
socket.destroy();
|
|
385
|
-
resolve();
|
|
386
|
-
});
|
|
387
|
-
socket.on("error", () => {
|
|
388
|
-
socket.destroy();
|
|
389
|
-
if (attempts >= maxAttempts) {
|
|
390
|
-
reject(
|
|
391
|
-
new Error(
|
|
392
|
-
`API server did not become ready on port ${port} after ${maxAttempts * intervalMs}ms`
|
|
393
|
-
)
|
|
394
|
-
);
|
|
395
|
-
} else {
|
|
396
|
-
setTimeout(tryConnect, intervalMs);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
};
|
|
400
|
-
tryConnect();
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
350
|
export {
|
|
404
351
|
builder,
|
|
405
352
|
command,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
|
|
2
2
|
import { getPaths } from "@cedarjs/project-config";
|
|
3
|
-
|
|
4
|
-
const args = ["
|
|
3
|
+
async function apiServerFileHandler(argv) {
|
|
4
|
+
const args = ["server.js", "--apiRootPath", argv.apiRootPath ?? "/"];
|
|
5
5
|
if (argv.port) {
|
|
6
6
|
args.push("--apiPort", String(argv.port));
|
|
7
7
|
}
|
|
8
8
|
const filteredArgs = args.filter((arg) => Boolean(arg));
|
|
9
|
-
await
|
|
9
|
+
await runBin("node", filteredArgs, {
|
|
10
10
|
cwd: getPaths().api.dist,
|
|
11
11
|
stdio: "inherit"
|
|
12
12
|
});
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
export {
|
|
15
15
|
apiServerFileHandler
|
|
16
16
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import concurrently from "concurrently";
|
|
3
|
-
import execa from "execa";
|
|
4
3
|
import { handler as apiServerHandler } from "@cedarjs/api-server/cjs/apiCliConfigHandler";
|
|
5
4
|
import {
|
|
6
5
|
getAPIHost,
|
|
7
6
|
getAPIPort,
|
|
7
|
+
getAPIRootPath,
|
|
8
8
|
getWebHost,
|
|
9
9
|
getWebPort
|
|
10
10
|
} from "@cedarjs/api-server/cjs/cliHelpers";
|
|
11
|
+
import { formatRunBinCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
12
|
+
import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
|
|
11
13
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
12
14
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
13
15
|
import { exitWithError } from "../lib/exit.js";
|
|
@@ -18,7 +20,7 @@ const hasStringMessage = (error) => {
|
|
|
18
20
|
const bothServerFileHandler = async (argv) => {
|
|
19
21
|
if (getConfig().experimental?.rsc?.enabled || getConfig().experimental?.streamingSsr?.enabled) {
|
|
20
22
|
logSkippingFastifyWebServer();
|
|
21
|
-
await
|
|
23
|
+
await runBin("cedar-serve-fe", [], {
|
|
22
24
|
cwd: getPaths().web.base,
|
|
23
25
|
stdio: "inherit"
|
|
24
26
|
});
|
|
@@ -27,24 +29,25 @@ const bothServerFileHandler = async (argv) => {
|
|
|
27
29
|
argv.apiHost ??= getAPIHost();
|
|
28
30
|
argv.webPort ??= getWebPort();
|
|
29
31
|
argv.webHost ??= getWebHost();
|
|
32
|
+
const apiRootPath = argv.apiRootPath ?? getAPIRootPath();
|
|
30
33
|
const apiProxyTarget = [
|
|
31
34
|
"http://",
|
|
32
35
|
argv.apiHost.includes(":") ? `[${argv.apiHost}]` : argv.apiHost,
|
|
33
36
|
":",
|
|
34
37
|
argv.apiPort,
|
|
35
|
-
|
|
38
|
+
apiRootPath
|
|
36
39
|
].join("");
|
|
37
40
|
const { result } = concurrently(
|
|
38
41
|
[
|
|
39
42
|
{
|
|
40
43
|
name: "api",
|
|
41
|
-
command:
|
|
44
|
+
command: `${formatRunBinCommand("node", [path.join("dist", "server.js"), "--apiPort", String(argv.apiPort), "--apiHost", argv.apiHost, "--apiRootPath", apiRootPath])}`,
|
|
42
45
|
cwd: getPaths().api.base,
|
|
43
46
|
prefixColor: "cyan"
|
|
44
47
|
},
|
|
45
48
|
{
|
|
46
49
|
name: "web",
|
|
47
|
-
command:
|
|
50
|
+
command: `${formatRunBinCommand("cedar-web-server", ["--port", String(argv.webPort), "--host", argv.webHost, "--api-proxy-target", apiProxyTarget])}`,
|
|
48
51
|
cwd: getPaths().base,
|
|
49
52
|
prefixColor: "blue"
|
|
50
53
|
}
|
|
@@ -71,11 +74,11 @@ const bothServerFileHandler = async (argv) => {
|
|
|
71
74
|
};
|
|
72
75
|
const bothSsrRscServerHandler = async (argv, rscEnabled) => {
|
|
73
76
|
const apiPromise = apiServerHandler({
|
|
74
|
-
apiRootPath: argv.apiRootPath,
|
|
77
|
+
apiRootPath: argv.apiRootPath ?? getAPIRootPath(),
|
|
75
78
|
host: argv.apiHost,
|
|
76
79
|
port: argv.apiPort
|
|
77
80
|
});
|
|
78
|
-
const fePromise =
|
|
81
|
+
const fePromise = runBin("cedar-serve-fe", [], {
|
|
79
82
|
cwd: getPaths().web.base,
|
|
80
83
|
stdio: "inherit",
|
|
81
84
|
env: rscEnabled ? {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
|
|
2
2
|
import { getPaths } from "@cedarjs/project-config";
|
|
3
3
|
const webSsrServerHandler = async (rscEnabled) => {
|
|
4
|
-
await
|
|
4
|
+
await runBin("cedar-serve-fe", [], {
|
|
5
5
|
cwd: getPaths().web.base,
|
|
6
6
|
stdio: "inherit",
|
|
7
7
|
env: rscEnabled ? {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import execa from "execa";
|
|
4
3
|
import { terminalLink } from "termi-link";
|
|
5
4
|
import {
|
|
6
5
|
recordTelemetryAttributes,
|
|
7
6
|
standardAuthBuilder
|
|
8
7
|
} from "@cedarjs/cli-helpers";
|
|
8
|
+
import { addRootPackages } from "@cedarjs/cli-helpers/packageManager/packages";
|
|
9
9
|
import { getPaths } from "../../../lib/index.js";
|
|
10
10
|
const command = "auth <provider>";
|
|
11
11
|
const description = "Set up an auth configuration";
|
|
@@ -198,7 +198,7 @@ async function getAuthSetupHandler(module) {
|
|
|
198
198
|
} else {
|
|
199
199
|
customRequire = require;
|
|
200
200
|
}
|
|
201
|
-
} catch
|
|
201
|
+
} catch {
|
|
202
202
|
customRequire = require;
|
|
203
203
|
}
|
|
204
204
|
const packageJsonPath = customRequire.resolve("@cedarjs/cli/package.json");
|
|
@@ -216,16 +216,22 @@ async function getAuthSetupHandler(module) {
|
|
|
216
216
|
if (packument.error) {
|
|
217
217
|
throw new Error(packument.error);
|
|
218
218
|
}
|
|
219
|
-
} catch (
|
|
219
|
+
} catch (e) {
|
|
220
220
|
throw new Error(
|
|
221
|
-
`Couldn't fetch packument for ${module}: ${
|
|
221
|
+
`Couldn't fetch packument for ${module}: ${e instanceof Error ? e.message : String(e)}`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (!packument.versions || typeof packument.versions !== "object" || Array.isArray(packument.versions)) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Couldn't fetch packument for ${module}: invalid versions field`
|
|
222
227
|
);
|
|
223
228
|
}
|
|
224
229
|
const versionIsPublished = Object.keys(packument.versions).includes(version);
|
|
225
230
|
if (!versionIsPublished) {
|
|
226
231
|
version = "canary";
|
|
227
232
|
}
|
|
228
|
-
await
|
|
233
|
+
await addRootPackages([`${module}@${version}`], {
|
|
234
|
+
dev: true,
|
|
229
235
|
stdio: "inherit",
|
|
230
236
|
cwd: getPaths().base
|
|
231
237
|
});
|
|
@@ -254,7 +260,7 @@ function isInstalled(module) {
|
|
|
254
260
|
return possiblePaths.some((modulePath) => {
|
|
255
261
|
return fs.existsSync(path.join(modulePath, "package.json"));
|
|
256
262
|
});
|
|
257
|
-
} catch
|
|
263
|
+
} catch {
|
|
258
264
|
return false;
|
|
259
265
|
}
|
|
260
266
|
}
|
|
@@ -14,15 +14,18 @@ const CLIENT_HOST_MAP = {
|
|
|
14
14
|
memcached: "localhost:11211",
|
|
15
15
|
redis: "redis://localhost:6379"
|
|
16
16
|
};
|
|
17
|
-
const handler = async ({
|
|
18
|
-
|
|
17
|
+
const handler = async ({
|
|
18
|
+
client,
|
|
19
|
+
force
|
|
20
|
+
}) => {
|
|
21
|
+
const extension = isTypeScriptProject() ? "ts" : "js";
|
|
19
22
|
const tasks = new Listr([
|
|
20
23
|
await addPackagesTask({
|
|
21
24
|
packages: [CLIENT_PACKAGE_MAP[client]],
|
|
22
25
|
side: "api"
|
|
23
26
|
}),
|
|
24
27
|
{
|
|
25
|
-
title: `Writing api/src/lib/cache
|
|
28
|
+
title: `Writing api/src/lib/cache.${extension}`,
|
|
26
29
|
task: () => {
|
|
27
30
|
const template = fs.readFileSync(
|
|
28
31
|
path.join(
|
|
@@ -59,9 +62,11 @@ const handler = async ({ client, force }) => {
|
|
|
59
62
|
try {
|
|
60
63
|
await tasks.run();
|
|
61
64
|
} catch (e) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
66
|
+
errorTelemetry(process.argv, message);
|
|
67
|
+
console.error(c.error(message));
|
|
68
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
69
|
+
process.exit(exitCode);
|
|
65
70
|
}
|
|
66
71
|
};
|
|
67
72
|
export {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const command = "deploy <target>";
|
|
2
|
-
const description = "Setup deployment to various targets";
|
|
3
1
|
import { terminalLink } from "termi-link";
|
|
4
2
|
import * as setupDeployBaremetal from "./providers/baremetal.js";
|
|
5
3
|
import * as setupDeployCoherence from "./providers/coherence.js";
|
|
@@ -7,8 +5,11 @@ import * as setupDeployFlightcontrol from "./providers/flightcontrol.js";
|
|
|
7
5
|
import * as setupDeployNetlify from "./providers/netlify.js";
|
|
8
6
|
import * as setupDeployRender from "./providers/render.js";
|
|
9
7
|
import * as setupDeployServerless from "./providers/serverless.js";
|
|
8
|
+
import * as setupDeployUniversalDeploy from "./providers/universal-deploy.js";
|
|
10
9
|
import * as setupDeployVercel from "./providers/vercel.js";
|
|
11
|
-
const
|
|
10
|
+
const command = "deploy <target>";
|
|
11
|
+
const description = "Setup deployment to various targets";
|
|
12
|
+
const builder = (yargs) => yargs.command(setupDeployBaremetal).command(setupDeployCoherence).command(setupDeployFlightcontrol).command(setupDeployNetlify).command(setupDeployRender).command(setupDeployServerless).command(setupDeployUniversalDeploy).command(setupDeployVercel).demandCommand().option("force", {
|
|
12
13
|
alias: "f",
|
|
13
14
|
default: false,
|
|
14
15
|
description: "Overwrite existing configuration",
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
function createHandler(componentName) {
|
|
2
2
|
return async function handler(argv) {
|
|
3
|
-
const {
|
|
3
|
+
const { existsSync } = await import("node:fs");
|
|
4
|
+
const tsPath = `../providers/${componentName}Handler.ts`;
|
|
5
|
+
const jsPath = `../providers/${componentName}Handler.js`;
|
|
6
|
+
const resolvedPath = existsSync(new URL(tsPath, import.meta.url)) ? tsPath : jsPath;
|
|
7
|
+
const { handler: importedHandler } = await import(resolvedPath);
|
|
4
8
|
return importedHandler(argv);
|
|
5
9
|
};
|
|
6
10
|
}
|