@cedarjs/cli 9.0.0-canary.1784 → 9.0.0-canary.3124
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/README.md +7 -10
- package/dist/cfw.js +10 -6
- package/dist/commands/build/buildHandler.js +220 -45
- package/dist/commands/build/buildPackagesTask.js +21 -20
- package/dist/commands/build.js +13 -2
- package/dist/commands/check.js +4 -6
- package/dist/commands/console.js +6 -4
- package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
- package/dist/commands/deploy/baremetal/baremetalHandler.js +116 -50
- package/dist/commands/deploy/baremetal.js +11 -4
- package/dist/commands/deploy/flightcontrolHandler.js +28 -15
- package/dist/commands/deploy/helpers/deployHandler.js +11 -6
- package/dist/commands/deploy/netlify.js +1 -1
- package/dist/commands/deploy/packing/nft.js +1 -2
- package/dist/commands/deploy/render.js +1 -1
- package/dist/commands/deploy/renderHandler.js +24 -13
- package/dist/commands/deploy/serverlessHandler.js +69 -27
- package/dist/commands/deploy/vercel.js +1 -1
- 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 +17 -17
- package/dist/commands/destroy/helpers.js +8 -2
- package/dist/commands/destroy/layout/layout.js +1 -2
- package/dist/commands/destroy/page/pageHandler.js +3 -3
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +31 -12
- package/dist/commands/destroy/sdl/sdlHandler.js +3 -3
- package/dist/commands/dev/apiDebugFlag.js +5 -4
- package/dist/commands/dev/devHandler.js +219 -68
- package/dist/commands/dev/packageWatchCommands.js +8 -3
- package/dist/commands/dev.js +16 -6
- package/dist/commands/execHandler.js +49 -29
- package/dist/commands/experimental/live-queries/liveQueries.js +32 -0
- package/dist/commands/experimental/live-queries/liveQueriesHandler.js +448 -0
- package/dist/commands/experimental/live-queries/templates/liveQueriesListener.ts.template +153 -0
- package/dist/commands/experimental/live-queries/templates/migration.sql.template +100 -0
- package/dist/commands/experimental/setupInngest.js +2 -2
- package/dist/commands/experimental/setupInngestHandler.js +13 -12
- package/dist/commands/experimental/setupOpentelemetry.js +2 -2
- package/dist/commands/experimental/setupOpentelemetryHandler.js +14 -10
- package/dist/commands/experimental/setupReactCompiler.js +2 -2
- package/dist/commands/experimental/setupReactCompilerHandler.js +48 -33
- package/dist/commands/experimental/setupRsc.js +1 -1
- package/dist/commands/experimental/setupRscHandler.js +20 -16
- package/dist/commands/experimental/setupStreamingSsr.js +2 -2
- package/dist/commands/experimental/setupStreamingSsrHandler.js +49 -34
- package/dist/commands/experimental/templates/opentelemetry.ts.template +2 -1
- 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/templates/streamingSsr/tsconfig.json.template +6 -6
- package/dist/commands/experimental/util.js +27 -25
- package/dist/commands/experimental.js +3 -2
- package/dist/commands/generate/cell/cell.js +20 -0
- package/dist/commands/generate/cell/cellHandler.js +89 -40
- package/dist/commands/generate/cell/templates/cell.tsx.template +21 -2
- package/dist/commands/generate/cell/templates/cellFragment.tsx.template +43 -0
- package/dist/commands/generate/cell/templates/cellList.tsx.template +21 -2
- package/dist/commands/generate/cell/templates/storiesFragment.tsx.template +23 -0
- package/dist/commands/generate/cell/templates/test.js.template +1 -1
- package/dist/commands/generate/cell/templates/testFragment.js.template +30 -0
- package/dist/commands/generate/component/componentHandler.js +14 -16
- package/dist/commands/generate/dataMigration/dataMigration.js +36 -18
- package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +1 -1
- package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +1 -1
- package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +63 -34
- package/dist/commands/generate/dbAuth/templates/login.oauth.tsx.template +164 -0
- package/dist/commands/generate/dbAuth/templates/signup.oauth.tsx.template +147 -0
- package/dist/commands/generate/directive/directiveHandler.js +14 -16
- package/dist/commands/generate/function/function.js +1 -0
- package/dist/commands/generate/function/functionHandler.js +14 -19
- package/dist/commands/generate/helpers.js +34 -18
- package/dist/commands/generate/job/job.js +1 -0
- package/dist/commands/generate/job/jobHandler.js +20 -24
- 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 +11 -5
- package/dist/commands/generate/ogImage/ogImage.js +1 -0
- package/dist/commands/generate/ogImage/ogImageHandler.js +18 -11
- package/dist/commands/generate/package/filesTask.js +9 -0
- package/dist/commands/generate/package/packageHandler.js +50 -61
- package/dist/commands/generate/package/templates/test.ts.template +2 -2
- package/dist/commands/generate/package/templates/vitest.config.ts.template +9 -0
- package/dist/commands/generate/page/pageHandler.js +27 -24
- package/dist/commands/generate/realtime/realtime.js +2 -2
- package/dist/commands/generate/realtime/realtimeHandler.js +51 -32
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +1 -1
- package/dist/commands/generate/scaffold/scaffold.js +1 -0
- package/dist/commands/generate/scaffold/scaffoldHandler.js +176 -49
- package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +1 -1
- package/dist/commands/generate/script/script.js +1 -0
- package/dist/commands/generate/script/scriptHandler.js +10 -6
- package/dist/commands/generate/script/templates/script.ts.template +9 -4
- package/dist/commands/generate/script/templates/tsconfig.json.template +16 -2
- package/dist/commands/generate/sdl/sdl.js +4 -3
- package/dist/commands/generate/sdl/sdlHandler.js +135 -46
- package/dist/commands/generate/sdl/stubFiles.js +132 -0
- package/dist/commands/generate/sdl/templates/sdl.js.template +2 -1
- package/dist/commands/generate/sdl/templates/sdl.ts.template +2 -1
- package/dist/commands/generate/secret/secret.js +20 -20
- package/dist/commands/generate/service/service.js +5 -5
- package/dist/commands/generate/service/serviceHandler.js +126 -61
- package/dist/commands/generate/service/templates/scenarios.ts.template +4 -2
- package/dist/commands/generate/service/templates/service.ts.template +22 -8
- package/dist/commands/generate/service/templates/test.ts.template +2 -2
- package/dist/commands/generate/yargsCommandHelpers.js +7 -2
- package/dist/commands/generate/yargsHandlerHelpers.js +20 -18
- package/dist/commands/generate.js +4 -4
- package/dist/commands/info.js +2 -2
- package/dist/commands/jobsHandler.js +7 -4
- package/dist/commands/lint.js +26 -69
- package/dist/commands/prerenderHandler.js +95 -58
- package/dist/commands/prismaHandler.js +51 -26
- package/dist/commands/record/init.js +2 -2
- package/dist/commands/record.js +4 -3
- package/dist/commands/serve.js +245 -31
- package/dist/commands/serveApiHandler.js +7 -6
- package/dist/commands/serveBothHandler.js +22 -13
- package/dist/commands/serveWebHandler.js +3 -2
- package/dist/commands/setup/auth/auth.js +15 -11
- package/dist/commands/setup/cache/cache.js +1 -1
- package/dist/commands/setup/cache/cacheHandler.js +15 -9
- package/dist/commands/setup/database/database.js +15 -0
- package/dist/commands/setup/database/postgres.js +19 -0
- package/dist/commands/setup/database/postgresHandler.js +196 -0
- package/dist/commands/setup/database/templates/db.ts.template +32 -0
- 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 +132 -6
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +28 -6
- package/dist/commands/setup/deploy/providers/coherence.js +1 -1
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +60 -31
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +69 -51
- package/dist/commands/setup/deploy/providers/netlify.js +6 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +114 -13
- package/dist/commands/setup/deploy/providers/renderHandler.js +44 -41
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +7 -5
- package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
- package/dist/commands/setup/deploy/providers/universalDeployHandler.js +186 -0
- package/dist/commands/setup/deploy/providers/vercel.js +6 -0
- package/dist/commands/setup/deploy/providers/vercelHandler.js +115 -14
- 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/deploy/templates/render.js +32 -17
- package/dist/commands/setup/docker/docker.js +2 -2
- package/dist/commands/setup/docker/dockerHandler.js +74 -39
- 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} +4 -7
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +3 -3
- package/dist/commands/setup/docker/templates/docker-compose.prod.yml +2 -5
- package/dist/commands/setup/docker/templates/dockerignore +1 -0
- package/dist/commands/setup/generator/generator.js +1 -1
- package/dist/commands/setup/generator/generatorHandler.js +5 -4
- package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +6 -3
- package/dist/commands/setup/graphql/features/fragments/fragments.js +1 -1
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +5 -7
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +1 -1
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +4 -3
- package/dist/commands/setup/i18n/i18n.js +1 -1
- package/dist/commands/setup/i18n/i18nHandler.js +21 -17
- package/dist/commands/setup/jobs/jobs.js +1 -1
- package/dist/commands/setup/jobs/jobsHandler.js +17 -12
- package/dist/commands/setup/mailer/mailer.js +1 -1
- package/dist/commands/setup/mailer/mailerHandler.js +13 -11
- package/dist/commands/setup/middleware/ogImage/ogImage.js +1 -1
- package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +2 -1
- package/dist/commands/setup/monitoring/sentry/sentry.js +1 -1
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +18 -12
- package/dist/commands/setup/neon/neon.js +35 -0
- package/dist/commands/setup/neon/neonHandler.js +264 -0
- package/dist/commands/setup/package/package.js +1 -1
- package/dist/commands/setup/package/packageHandler.js +18 -14
- package/dist/commands/setup/realtime/addRealtimeToGraphql.js +1 -1
- package/dist/commands/setup/realtime/realtime.js +1 -1
- package/dist/commands/setup/realtime/realtimeHandler.js +26 -37
- package/dist/commands/setup/realtime/templates/realtime.ts.template +1 -1
- package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +1 -1
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +1 -1
- package/dist/commands/setup/server-file/serverFile.js +1 -1
- package/dist/commands/setup/server-file/serverFileHandler.js +18 -10
- package/dist/commands/setup/tenancy/authCodemod.js +66 -0
- package/dist/commands/setup/tenancy/dbCodemod.js +64 -0
- package/dist/commands/setup/tenancy/graphqlCodemod.js +88 -0
- package/dist/commands/setup/tenancy/preflight.js +49 -0
- package/dist/commands/setup/tenancy/schemaPrisma.js +81 -0
- package/dist/commands/setup/tenancy/signupCodemod.js +153 -0
- package/dist/commands/setup/tenancy/templates/InvitePage.tsx.template +63 -0
- package/dist/commands/setup/tenancy/templates/OrgScope.tsx.template +40 -0
- package/dist/commands/setup/tenancy/templates/ensureDefaultOrganizations.dataMigration.ts.template +39 -0
- package/dist/commands/setup/tenancy/templates/organizations.scenarios.ts.template +59 -0
- package/dist/commands/setup/tenancy/templates/organizations.sdl.ts.template +89 -0
- package/dist/commands/setup/tenancy/templates/organizations.test.ts.template +389 -0
- package/dist/commands/setup/tenancy/templates/organizations.ts.template +394 -0
- package/dist/commands/setup/tenancy/templates/requireMembership.test.ts.template +35 -0
- package/dist/commands/setup/tenancy/templates/requireMembership.ts.template +25 -0
- package/dist/commands/setup/tenancy/tenancy.js +30 -0
- package/dist/commands/setup/tenancy/tenancyHandler.js +425 -0
- package/dist/commands/setup/ui/helpers/helpers.js +5 -1
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +16 -8
- package/dist/commands/setup/ui/libraries/mantineHandler.js +26 -16
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +40 -29
- package/dist/commands/setup/uploads/schemaPrisma.js +41 -0
- package/dist/commands/setup/uploads/serverFile.js +151 -0
- package/dist/commands/setup/uploads/templates/requireUploadToken.ts.template +15 -0
- package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +23 -24
- package/dist/commands/setup/uploads/templates/uploads.sdl.ts.template +79 -0
- package/dist/commands/setup/uploads/templates/uploads.ts.template +89 -0
- package/dist/commands/setup/uploads/templates/withDataUri.ts.template +14 -0
- package/dist/commands/setup/uploads/templates/withSignedUrl.ts.template +16 -0
- package/dist/commands/setup/uploads/uploads.js +49 -7
- package/dist/commands/setup/uploads/uploadsHandler.js +266 -72
- package/dist/commands/setup.js +5 -4
- package/dist/commands/studio.js +1 -1
- package/dist/commands/studioHandler.js +2 -2
- package/dist/commands/test/datasourceWarning.js +42 -0
- package/dist/commands/test/testHandler.js +104 -0
- package/dist/commands/test/viteVersionCheck.js +75 -0
- package/dist/commands/test.js +16 -19
- package/dist/commands/type-check.js +2 -1
- package/dist/commands/type-checkHandler.js +25 -18
- package/dist/commands/upgrade/preUpgradeScripts.js +11 -11
- package/dist/commands/upgrade/upgrade.js +4 -2
- package/dist/commands/upgrade/upgradeHandler.js +97 -73
- package/dist/index.js +15 -11
- package/dist/lib/background.js +22 -1
- package/dist/lib/configureStorybook.js +2 -2
- package/dist/lib/exec.js +68 -63
- package/dist/lib/exit.js +20 -5
- package/dist/lib/extendFile.js +23 -13
- package/dist/lib/generatePrismaClient.js +48 -12
- package/dist/lib/index.js +137 -106
- package/dist/lib/loadEnvFiles.js +1 -1
- package/dist/lib/locking.js +8 -4
- package/dist/lib/merge/algorithms.js +4 -1
- package/dist/lib/merge/index.js +78 -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 +13 -7
- package/dist/lib/pluralHelpers.js +6 -2
- package/dist/lib/project.js +3 -1
- package/dist/lib/rollback.js +7 -7
- package/dist/lib/schemaHelpers.js +16 -19
- package/dist/lib/test.js +20 -5
- package/dist/lib/updateCheck.js +47 -18
- package/dist/middleware/checkNodeVersion.js +9 -4
- package/dist/middleware/{detectProjectRxVersion.js → detectProjectCedarVersion.js} +2 -2
- 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 -12
- package/dist/telemetry/send.js +14 -10
- package/dist/testLib/cells.js +5 -3
- package/package.json +44 -41
- package/LICENSE +0 -21
- package/dist/commands/consoleHandler.js +0 -68
- package/dist/commands/setup/tsconfig/tsconfig.js +0 -25
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +0 -59
- package/dist/commands/setup/uploads/dbCodemod.js +0 -28
- package/dist/commands/setup/uploads/templates/signedUrl.ts.template +0 -21
- 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 -83
- package/dist/commands/testEsm.js +0 -36
- package/dist/commands/testHandler.js +0 -137
- package/dist/commands/testHandlerEsm.js +0 -85
- package/dist/commands/ts-to-js.js +0 -20
- package/dist/lib/cedarPluralize.js +0 -56
- package/dist/lib/colors.js +0 -18
- package/dist/testLib/getFilesWithPattern.js +0 -21
- /package/dist/{index.d.js → global.d.js} +0 -0
package/dist/commands/serve.js
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "path";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { serve as serveSrvx } from "srvx";
|
|
3
5
|
import { terminalLink } from "termi-link";
|
|
4
6
|
import * as apiServerCLIConfig from "@cedarjs/api-server/apiCliConfig";
|
|
5
7
|
import * as bothServerCLIConfig from "@cedarjs/api-server/bothCliConfig";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
9
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
8
10
|
import * as webServerCLIConfig from "@cedarjs/web-server";
|
|
9
|
-
import c from "../lib/colors.js";
|
|
10
11
|
import { getPaths, getConfig } from "../lib/index.js";
|
|
11
12
|
import { serverFileExists } from "../lib/project.js";
|
|
12
13
|
import { webSsrServerHandler } from "./serveWebHandler.js";
|
|
14
|
+
function refuseServerFileUnderUD() {
|
|
15
|
+
console.error(
|
|
16
|
+
c.error(
|
|
17
|
+
"\n api/src/server.ts was detected, but a custom server file is not supported with --ud. It is a Fastify concept \u2014 anything registered there (Realtime, custom plugins, custom middleware) would silently be skipped if serving continued.\n"
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
function resolveUDEntryPath() {
|
|
23
|
+
const base = path.join(getPaths().api.dist, "ud", "index");
|
|
24
|
+
for (const ext of [".mjs", ".js"]) {
|
|
25
|
+
const entryPath = base + ext;
|
|
26
|
+
if (fs.existsSync(entryPath)) {
|
|
27
|
+
return entryPath;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
async function startUDServer(entryPath, host, port) {
|
|
33
|
+
const mod = await import(pathToFileURL(entryPath).href);
|
|
34
|
+
const fetchable = mod.default ?? mod;
|
|
35
|
+
if (!fetchable || typeof fetchable.fetch !== "function") {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`UD entry at ${entryPath} does not export a Fetchable (\`export default { fetch }\`).`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const server = serveSrvx({
|
|
41
|
+
...fetchable,
|
|
42
|
+
port,
|
|
43
|
+
hostname: host,
|
|
44
|
+
gracefulShutdown: false,
|
|
45
|
+
manual: true
|
|
46
|
+
});
|
|
47
|
+
server.serve();
|
|
48
|
+
await server.ready();
|
|
49
|
+
return server;
|
|
50
|
+
}
|
|
13
51
|
const command = "serve [side]";
|
|
14
52
|
const description = "Start a server for serving both the api and web sides";
|
|
15
53
|
const builder = async (yargs) => {
|
|
@@ -18,7 +56,14 @@ const builder = async (yargs) => {
|
|
|
18
56
|
yargs.command({
|
|
19
57
|
command: "$0",
|
|
20
58
|
description: bothServerCLIConfig.description,
|
|
21
|
-
builder:
|
|
59
|
+
builder: (yargs2) => {
|
|
60
|
+
bothServerCLIConfig.builder(yargs2);
|
|
61
|
+
return yargs2.option("ud", {
|
|
62
|
+
description: "Use the Universal Deploy server for the API side. The web side is served by the existing static file server. Pass --ud to opt in; the default is Fastify for both sides.",
|
|
63
|
+
type: "boolean",
|
|
64
|
+
default: false
|
|
65
|
+
});
|
|
66
|
+
},
|
|
22
67
|
handler: async (argv) => {
|
|
23
68
|
recordTelemetryAttributes({
|
|
24
69
|
command: "serve",
|
|
@@ -26,25 +71,129 @@ const builder = async (yargs) => {
|
|
|
26
71
|
host: argv.host,
|
|
27
72
|
socket: argv.socket
|
|
28
73
|
});
|
|
74
|
+
if (argv.ud) {
|
|
75
|
+
if (argv.port) {
|
|
76
|
+
console.error(
|
|
77
|
+
c.error(
|
|
78
|
+
"\n The --port flag is not supported with --ud. Use --web-port and --api-port instead.\n"
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
const udEntryPath = resolveUDEntryPath();
|
|
84
|
+
if (!udEntryPath) {
|
|
85
|
+
console.error(
|
|
86
|
+
c.error(
|
|
87
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
const webDistIndexHtml = path.join(getPaths().web.dist, "index.html");
|
|
93
|
+
if (!fs.existsSync(webDistIndexHtml)) {
|
|
94
|
+
console.error(
|
|
95
|
+
c.error(
|
|
96
|
+
"\n Web build artifacts not found.\n Please run `yarn cedar build` before serving.\n"
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
if (serverFileExists()) {
|
|
102
|
+
refuseServerFileUnderUD();
|
|
103
|
+
}
|
|
104
|
+
const { getAPIHost, getAPIPort, getWebHost, getWebPort } = await import("@cedarjs/api-server/cliHelpers");
|
|
105
|
+
const apiPort = argv.apiPort ?? getAPIPort();
|
|
106
|
+
const apiHost = argv.apiHost ?? getAPIHost();
|
|
107
|
+
const webPort = argv.webPort ?? getWebPort({ isPublicSide: true });
|
|
108
|
+
const webHost = argv.webHost ?? getWebHost({ isPublicSide: true });
|
|
109
|
+
const apiRootPath = argv.apiRootPath ?? "/";
|
|
110
|
+
const apiTarget = `http://${apiHost.includes(":") ? `[${apiHost}]` : apiHost}:${apiPort}`;
|
|
111
|
+
const { staticMiddleware } = await import("srvx/static");
|
|
112
|
+
const apiUrl = getConfig().web.apiUrl;
|
|
113
|
+
const webDist = getPaths().web.dist;
|
|
114
|
+
const prerenderIndexPath = path.join(webDist, "200.html");
|
|
115
|
+
const fallbackIndexPath = fs.existsSync(prerenderIndexPath) ? prerenderIndexPath : path.join(webDist, "index.html");
|
|
116
|
+
const spaHtml = fs.readFileSync(fallbackIndexPath, "utf-8");
|
|
117
|
+
const webServer = serveSrvx({
|
|
118
|
+
// Dummy fetch handler. All requests are handled by middleware
|
|
119
|
+
fetch: async () => new Response("Not Found", { status: 404 }),
|
|
120
|
+
middleware: [
|
|
121
|
+
staticMiddleware({ dir: webDist }),
|
|
122
|
+
async (req, next) => {
|
|
123
|
+
const url = new URL(req.url, "http://localhost");
|
|
124
|
+
if (!url.pathname.startsWith(apiUrl)) {
|
|
125
|
+
return next();
|
|
126
|
+
}
|
|
127
|
+
const targetPath = url.pathname.slice(apiUrl.length) || "/";
|
|
128
|
+
const root = apiRootPath === "/" ? "" : apiRootPath;
|
|
129
|
+
const targetUrl = `${apiTarget}${root}${targetPath}${url.search}`;
|
|
130
|
+
const forwardedHeaders = new Headers(req.headers);
|
|
131
|
+
if (!forwardedHeaders.has("x-forwarded-host")) {
|
|
132
|
+
forwardedHeaders.set(
|
|
133
|
+
"x-forwarded-host",
|
|
134
|
+
req.headers.get("host") || url.host
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (!forwardedHeaders.has("x-forwarded-proto")) {
|
|
138
|
+
forwardedHeaders.set("x-forwarded-proto", "http");
|
|
139
|
+
}
|
|
140
|
+
return fetch(targetUrl, {
|
|
141
|
+
method: req.method,
|
|
142
|
+
headers: forwardedHeaders,
|
|
143
|
+
body: req.body,
|
|
144
|
+
// @ts-expect-error - `duplex` is required when forwarding a
|
|
145
|
+
// request body via fetch (Node 18+).
|
|
146
|
+
duplex: "half"
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
() => {
|
|
150
|
+
const headers = { "Content-Type": "text/html" };
|
|
151
|
+
return new Response(spaHtml, { headers });
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
port: webPort,
|
|
155
|
+
hostname: webHost,
|
|
156
|
+
gracefulShutdown: false,
|
|
157
|
+
manual: true
|
|
158
|
+
});
|
|
159
|
+
webServer.serve();
|
|
160
|
+
await webServer.ready();
|
|
161
|
+
console.log(`Web server listening at http://${webHost}:${webPort}`);
|
|
162
|
+
process.stdout.write(
|
|
163
|
+
`API server starting at http://${apiHost}:${apiPort}...`
|
|
164
|
+
);
|
|
165
|
+
await startUDServer(udEntryPath, apiHost, apiPort);
|
|
166
|
+
process.stdout.write(
|
|
167
|
+
`\rAPI server listening at http://${apiHost}:${apiPort}
|
|
168
|
+
`
|
|
169
|
+
);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
29
172
|
if (serverFileExists()) {
|
|
30
|
-
const
|
|
31
|
-
await bothServerFileHandler(argv);
|
|
173
|
+
const serveBothHandlers = await import("./serveBothHandler.js");
|
|
174
|
+
await serveBothHandlers.bothServerFileHandler(argv);
|
|
32
175
|
} else if (rscEnabled || streamingEnabled) {
|
|
33
|
-
const
|
|
34
|
-
await bothSsrRscServerHandler(argv, rscEnabled);
|
|
176
|
+
const serveBothHandlers = await import("./serveBothHandler.js");
|
|
177
|
+
await serveBothHandlers.bothSsrRscServerHandler(argv, rscEnabled);
|
|
35
178
|
} else {
|
|
36
|
-
|
|
37
|
-
const { handler } = await import("@cedarjs/api-server/cjs/bothCliConfigHandler");
|
|
38
|
-
await handler(argv);
|
|
39
|
-
} else {
|
|
40
|
-
await bothServerCLIConfig.handler(argv);
|
|
41
|
-
}
|
|
179
|
+
await bothServerCLIConfig.handler(argv);
|
|
42
180
|
}
|
|
43
181
|
}
|
|
44
182
|
}).command({
|
|
45
183
|
command: "api",
|
|
46
184
|
description: apiServerCLIConfig.description,
|
|
47
|
-
builder:
|
|
185
|
+
builder: (yargs2) => {
|
|
186
|
+
if (typeof apiServerCLIConfig.builder === "function") {
|
|
187
|
+
apiServerCLIConfig.builder(yargs2);
|
|
188
|
+
}
|
|
189
|
+
return yargs2.option("ud", {
|
|
190
|
+
// UD serving is opt-in. Pass --ud to use the new srvx server instead
|
|
191
|
+
// of the legacy Fastify server.
|
|
192
|
+
description: "Use the Universal Deploy server. Pass --ud to opt in; the default is Fastify.",
|
|
193
|
+
type: "boolean",
|
|
194
|
+
default: false
|
|
195
|
+
});
|
|
196
|
+
},
|
|
48
197
|
handler: async (argv) => {
|
|
49
198
|
recordTelemetryAttributes({
|
|
50
199
|
command: "serve",
|
|
@@ -53,16 +202,39 @@ const builder = async (yargs) => {
|
|
|
53
202
|
socket: argv.socket,
|
|
54
203
|
apiRootPath: argv.apiRootPath
|
|
55
204
|
});
|
|
205
|
+
const { getAPIHost, getAPIPort } = await import("@cedarjs/api-server/cliHelpers");
|
|
206
|
+
const apiPort = argv.port ?? getAPIPort({ isPublicSide: true });
|
|
207
|
+
const apiHost = argv.host ?? getAPIHost({ isPublicSide: true });
|
|
208
|
+
argv.port = apiPort;
|
|
209
|
+
argv.host = apiHost;
|
|
210
|
+
if (argv.ud) {
|
|
211
|
+
if (serverFileExists()) {
|
|
212
|
+
refuseServerFileUnderUD();
|
|
213
|
+
}
|
|
214
|
+
const udEntryPath = resolveUDEntryPath();
|
|
215
|
+
if (!udEntryPath) {
|
|
216
|
+
console.error(
|
|
217
|
+
c.error(
|
|
218
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
process.stdout.write(
|
|
224
|
+
`API server starting at http://${apiHost}:${apiPort}...`
|
|
225
|
+
);
|
|
226
|
+
await startUDServer(udEntryPath, apiHost, apiPort);
|
|
227
|
+
process.stdout.write(
|
|
228
|
+
`\rAPI server listening at http://${apiHost}:${apiPort}
|
|
229
|
+
`
|
|
230
|
+
);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
56
233
|
if (serverFileExists()) {
|
|
57
234
|
const { apiServerFileHandler } = await import("./serveApiHandler.js");
|
|
58
235
|
await apiServerFileHandler(argv);
|
|
59
236
|
} else {
|
|
60
|
-
|
|
61
|
-
const { handler } = await import("@cedarjs/api-server/cjs/apiCliConfigHandler");
|
|
62
|
-
await handler(argv);
|
|
63
|
-
} else {
|
|
64
|
-
await apiServerCLIConfig.handler(argv);
|
|
65
|
-
}
|
|
237
|
+
await apiServerCLIConfig.handler(argv);
|
|
66
238
|
}
|
|
67
239
|
}
|
|
68
240
|
}).command({
|
|
@@ -88,7 +260,7 @@ const builder = async (yargs) => {
|
|
|
88
260
|
command: "serve"
|
|
89
261
|
});
|
|
90
262
|
const positionalArgs = argv._;
|
|
91
|
-
if (positionalArgs.includes("web") && !
|
|
263
|
+
if (positionalArgs.includes("web") && !webSideIsBuilt(streamingEnabled || rscEnabled)) {
|
|
92
264
|
console.error(
|
|
93
265
|
c.error(
|
|
94
266
|
"\n Please run `yarn cedar build web` before trying to serve web. \n"
|
|
@@ -114,23 +286,56 @@ const builder = async (yargs) => {
|
|
|
114
286
|
);
|
|
115
287
|
process.exit(1);
|
|
116
288
|
}
|
|
289
|
+
if (argv.ud) {
|
|
290
|
+
const udEntryPath = resolveUDEntryPath();
|
|
291
|
+
if (!udEntryPath) {
|
|
292
|
+
console.error(
|
|
293
|
+
c.error(
|
|
294
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
117
300
|
}
|
|
118
301
|
if (positionalArgs.length === 1) {
|
|
119
302
|
if (!apiSideExists && !rscEnabled) {
|
|
120
303
|
console.error(
|
|
121
304
|
c.error(
|
|
122
|
-
"\
|
|
305
|
+
"\nUnable to serve web and api as no `api` folder exists. Please use `yarn cedar serve web` instead. \n"
|
|
123
306
|
)
|
|
124
307
|
);
|
|
125
308
|
process.exit(1);
|
|
126
309
|
}
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
310
|
+
if (argv.ud) {
|
|
311
|
+
const udEntryPath = resolveUDEntryPath();
|
|
312
|
+
if (!udEntryPath) {
|
|
313
|
+
console.error(
|
|
314
|
+
c.error(
|
|
315
|
+
"\n Universal Deploy server entry not found. Please run `yarn cedar build --ud` before serving.\n"
|
|
316
|
+
)
|
|
317
|
+
);
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
const webDistIndexHtml = path.join(getPaths().web.dist, "index.html");
|
|
321
|
+
if (!fs.existsSync(webDistIndexHtml)) {
|
|
322
|
+
console.error(
|
|
323
|
+
c.error(
|
|
324
|
+
"\n Web build artifacts not found.\n Please run `yarn cedar build` before serving.\n"
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
const apiExistsButIsNotBuilt = apiSideExists && !fs.existsSync(getPaths().api.dist);
|
|
331
|
+
if (apiExistsButIsNotBuilt || !webSideIsBuilt(streamingEnabled || rscEnabled)) {
|
|
332
|
+
console.error(
|
|
333
|
+
c.error(
|
|
334
|
+
"\nPlease run `yarn cedar build` before trying to serve your Cedar app.\n"
|
|
335
|
+
)
|
|
336
|
+
);
|
|
337
|
+
process.exit(1);
|
|
338
|
+
}
|
|
134
339
|
}
|
|
135
340
|
}
|
|
136
341
|
if (!process.env.NODE_ENV) {
|
|
@@ -143,6 +348,15 @@ const builder = async (yargs) => {
|
|
|
143
348
|
)}`
|
|
144
349
|
);
|
|
145
350
|
};
|
|
351
|
+
function webSideIsBuilt(isStreamingOrRSC) {
|
|
352
|
+
if (isStreamingOrRSC) {
|
|
353
|
+
return fs.existsSync(
|
|
354
|
+
path.join(getPaths().web.distBrowser, "client-build-manifest.json")
|
|
355
|
+
);
|
|
356
|
+
} else {
|
|
357
|
+
return fs.existsSync(path.join(getPaths().web.dist, "index.html"));
|
|
358
|
+
}
|
|
359
|
+
}
|
|
146
360
|
export {
|
|
147
361
|
builder,
|
|
148
362
|
command,
|
|
@@ -1,15 +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
|
-
args.push("--apiPort", argv.port);
|
|
6
|
+
args.push("--apiPort", String(argv.port));
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
const filteredArgs = args.filter((arg) => Boolean(arg));
|
|
9
|
+
await runBin("node", filteredArgs, {
|
|
9
10
|
cwd: getPaths().api.dist,
|
|
10
11
|
stdio: "inherit"
|
|
11
12
|
});
|
|
12
|
-
}
|
|
13
|
+
}
|
|
13
14
|
export {
|
|
14
15
|
apiServerFileHandler
|
|
15
16
|
};
|
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import concurrently from "concurrently";
|
|
3
|
-
import
|
|
4
|
-
import { handler as apiServerHandler } from "@cedarjs/api-server/cjs/apiCliConfigHandler";
|
|
3
|
+
import { handler as apiServerHandler } from "@cedarjs/api-server/apiCliConfigHandler";
|
|
5
4
|
import {
|
|
6
5
|
getAPIHost,
|
|
7
6
|
getAPIPort,
|
|
7
|
+
getAPIRootPath,
|
|
8
8
|
getWebHost,
|
|
9
9
|
getWebPort
|
|
10
|
-
} from "@cedarjs/api-server/
|
|
10
|
+
} from "@cedarjs/api-server/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";
|
|
16
|
+
const hasStringMessage = (error) => {
|
|
17
|
+
const message = typeof error === "object" && error !== null ? Reflect.get(error, "message") : void 0;
|
|
18
|
+
return typeof error === "object" && error !== null && "message" in error && typeof message === "string";
|
|
19
|
+
};
|
|
14
20
|
const bothServerFileHandler = async (argv) => {
|
|
15
21
|
if (getConfig().experimental?.rsc?.enabled || getConfig().experimental?.streamingSsr?.enabled) {
|
|
16
22
|
logSkippingFastifyWebServer();
|
|
17
|
-
await
|
|
23
|
+
await runBin("cedar-serve-fe", [], {
|
|
18
24
|
cwd: getPaths().web.base,
|
|
19
25
|
stdio: "inherit"
|
|
20
26
|
});
|
|
21
27
|
} else {
|
|
22
28
|
argv.apiPort ??= getAPIPort();
|
|
23
29
|
argv.apiHost ??= getAPIHost();
|
|
24
|
-
argv.webPort ??= getWebPort();
|
|
25
|
-
argv.webHost ??= getWebHost();
|
|
30
|
+
argv.webPort ??= getWebPort({ isPublicSide: true });
|
|
31
|
+
argv.webHost ??= getWebHost({ isPublicSide: true });
|
|
32
|
+
const apiRootPath = argv.apiRootPath ?? getAPIRootPath();
|
|
26
33
|
const apiProxyTarget = [
|
|
27
34
|
"http://",
|
|
28
35
|
argv.apiHost.includes(":") ? `[${argv.apiHost}]` : argv.apiHost,
|
|
29
36
|
":",
|
|
30
37
|
argv.apiPort,
|
|
31
|
-
|
|
38
|
+
apiRootPath
|
|
32
39
|
].join("");
|
|
33
40
|
const { result } = concurrently(
|
|
34
41
|
[
|
|
35
42
|
{
|
|
36
43
|
name: "api",
|
|
37
|
-
command:
|
|
44
|
+
command: `${formatRunBinCommand("node", [path.join("dist", "server.js"), "--apiPort", String(argv.apiPort), "--apiHost", argv.apiHost, "--apiRootPath", apiRootPath])}`,
|
|
38
45
|
cwd: getPaths().api.base,
|
|
39
46
|
prefixColor: "cyan"
|
|
40
47
|
},
|
|
41
48
|
{
|
|
42
49
|
name: "web",
|
|
43
|
-
command:
|
|
50
|
+
command: `${formatRunBinCommand("cedar-web-server", ["--port", String(argv.webPort), "--host", argv.webHost, "--api-proxy-target", apiProxyTarget])}`,
|
|
44
51
|
cwd: getPaths().base,
|
|
45
52
|
prefixColor: "blue"
|
|
46
53
|
}
|
|
@@ -54,10 +61,11 @@ const bothServerFileHandler = async (argv) => {
|
|
|
54
61
|
try {
|
|
55
62
|
await result;
|
|
56
63
|
} catch (error) {
|
|
57
|
-
|
|
64
|
+
const message = hasStringMessage(error) ? error.message : void 0;
|
|
65
|
+
if (typeof message !== "undefined") {
|
|
58
66
|
errorTelemetry(
|
|
59
67
|
process.argv,
|
|
60
|
-
`Error concurrently starting sides: ${
|
|
68
|
+
`Error concurrently starting sides: ${message}`
|
|
61
69
|
);
|
|
62
70
|
exitWithError(error);
|
|
63
71
|
}
|
|
@@ -66,14 +74,15 @@ const bothServerFileHandler = async (argv) => {
|
|
|
66
74
|
};
|
|
67
75
|
const bothSsrRscServerHandler = async (argv, rscEnabled) => {
|
|
68
76
|
const apiPromise = apiServerHandler({
|
|
69
|
-
apiRootPath: argv.apiRootPath,
|
|
77
|
+
apiRootPath: argv.apiRootPath ?? getAPIRootPath(),
|
|
70
78
|
host: argv.apiHost,
|
|
71
79
|
port: argv.apiPort
|
|
72
80
|
});
|
|
73
|
-
const fePromise =
|
|
81
|
+
const fePromise = runBin("cedar-serve-fe", [], {
|
|
74
82
|
cwd: getPaths().web.base,
|
|
75
83
|
stdio: "inherit",
|
|
76
84
|
env: rscEnabled ? {
|
|
85
|
+
...process.env,
|
|
77
86
|
// TODO (RSC): Is this how we want to do it? If so, we need to find a way
|
|
78
87
|
// to merge this with users' NODE_OPTIONS
|
|
79
88
|
NODE_OPTIONS: "--conditions react-server"
|
|
@@ -1,10 +1,11 @@
|
|
|
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 ? {
|
|
8
|
+
...process.env,
|
|
8
9
|
// TODO (RSC): Is this how we want to do it? If so, we need to find a way
|
|
9
10
|
// to merge this with users' NODE_OPTIONS
|
|
10
11
|
NODE_OPTIONS: "--conditions react-server"
|
|
@@ -1,11 +1,9 @@
|
|
|
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
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "@cedarjs/cli-helpers";
|
|
4
|
+
import { standardAuthBuilder } from "@cedarjs/cli-helpers/auth/setupHelpers";
|
|
5
|
+
import { addRootPackages } from "@cedarjs/cli-helpers/packageManager/packages";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
9
7
|
import { getPaths } from "../../../lib/index.js";
|
|
10
8
|
const command = "auth <provider>";
|
|
11
9
|
const description = "Set up an auth configuration";
|
|
@@ -198,7 +196,7 @@ async function getAuthSetupHandler(module) {
|
|
|
198
196
|
} else {
|
|
199
197
|
customRequire = require;
|
|
200
198
|
}
|
|
201
|
-
} catch
|
|
199
|
+
} catch {
|
|
202
200
|
customRequire = require;
|
|
203
201
|
}
|
|
204
202
|
const packageJsonPath = customRequire.resolve("@cedarjs/cli/package.json");
|
|
@@ -216,22 +214,28 @@ async function getAuthSetupHandler(module) {
|
|
|
216
214
|
if (packument.error) {
|
|
217
215
|
throw new Error(packument.error);
|
|
218
216
|
}
|
|
219
|
-
} catch (
|
|
217
|
+
} catch (e) {
|
|
220
218
|
throw new Error(
|
|
221
|
-
`Couldn't fetch packument for ${module}: ${
|
|
219
|
+
`Couldn't fetch packument for ${module}: ${e instanceof Error ? e.message : String(e)}`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
if (!packument.versions || typeof packument.versions !== "object" || Array.isArray(packument.versions)) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Couldn't fetch packument for ${module}: invalid versions field`
|
|
222
225
|
);
|
|
223
226
|
}
|
|
224
227
|
const versionIsPublished = Object.keys(packument.versions).includes(version);
|
|
225
228
|
if (!versionIsPublished) {
|
|
226
229
|
version = "canary";
|
|
227
230
|
}
|
|
228
|
-
await
|
|
231
|
+
await addRootPackages([`${module}@${version}`], {
|
|
232
|
+
dev: true,
|
|
229
233
|
stdio: "inherit",
|
|
230
234
|
cwd: getPaths().base
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
237
|
const setupModule = await import(module);
|
|
234
|
-
return setupModule.
|
|
238
|
+
return setupModule.handler;
|
|
235
239
|
}
|
|
236
240
|
function isInstalled(module) {
|
|
237
241
|
const { dependencies, devDependencies } = JSON.parse(
|
|
@@ -254,7 +258,7 @@ function isInstalled(module) {
|
|
|
254
258
|
return possiblePaths.some((modulePath) => {
|
|
255
259
|
return fs.existsSync(path.join(modulePath, "package.json"));
|
|
256
260
|
});
|
|
257
|
-
} catch
|
|
261
|
+
} catch {
|
|
258
262
|
return false;
|
|
259
263
|
}
|
|
260
264
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { terminalLink } from "termi-link";
|
|
2
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
2
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
3
3
|
const command = "cache <client>";
|
|
4
4
|
const description = "Sets up an init file for service caching";
|
|
5
5
|
const builder = (yargs) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
|
-
import {
|
|
4
|
+
import { terminalLink } from "termi-link";
|
|
5
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { addEnvVarTask } from "@cedarjs/cli-helpers/project";
|
|
5
7
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
6
|
-
import c from "../../../lib/colors.js";
|
|
7
8
|
import { addPackagesTask, getPaths, writeFile } from "../../../lib/index.js";
|
|
8
9
|
import { isTypeScriptProject } from "../../../lib/project.js";
|
|
9
10
|
const CLIENT_PACKAGE_MAP = {
|
|
@@ -14,15 +15,18 @@ const CLIENT_HOST_MAP = {
|
|
|
14
15
|
memcached: "localhost:11211",
|
|
15
16
|
redis: "redis://localhost:6379"
|
|
16
17
|
};
|
|
17
|
-
const handler = async ({
|
|
18
|
-
|
|
18
|
+
const handler = async ({
|
|
19
|
+
client,
|
|
20
|
+
force
|
|
21
|
+
}) => {
|
|
22
|
+
const extension = isTypeScriptProject() ? "ts" : "js";
|
|
19
23
|
const tasks = new Listr([
|
|
20
24
|
await addPackagesTask({
|
|
21
25
|
packages: [CLIENT_PACKAGE_MAP[client]],
|
|
22
26
|
side: "api"
|
|
23
27
|
}),
|
|
24
28
|
{
|
|
25
|
-
title: `Writing api/src/lib/cache
|
|
29
|
+
title: `Writing api/src/lib/cache.${extension}`,
|
|
26
30
|
task: () => {
|
|
27
31
|
const template = fs.readFileSync(
|
|
28
32
|
path.join(
|
|
@@ -51,7 +55,7 @@ const handler = async ({ client, force }) => {
|
|
|
51
55
|
task.title = `One more thing...
|
|
52
56
|
|
|
53
57
|
${c.tip("Check out the Service Cache docs for config and usage:")}
|
|
54
|
-
${
|
|
58
|
+
${terminalLink("", "https://cedarjs.com/docs/services#caching")}
|
|
55
59
|
`;
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -59,9 +63,11 @@ const handler = async ({ client, force }) => {
|
|
|
59
63
|
try {
|
|
60
64
|
await tasks.run();
|
|
61
65
|
} catch (e) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
67
|
+
errorTelemetry(process.argv, message);
|
|
68
|
+
console.error(c.error(message));
|
|
69
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
70
|
+
process.exit(exitCode);
|
|
65
71
|
}
|
|
66
72
|
};
|
|
67
73
|
export {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { terminalLink } from "termi-link";
|
|
2
|
+
import * as setupDatabasePostgres from "./postgres.js";
|
|
3
|
+
const command = "database <command>";
|
|
4
|
+
const description = "Switch your project's database";
|
|
5
|
+
const builder = (yargs) => yargs.command(setupDatabasePostgres).demandCommand().epilogue(
|
|
6
|
+
`Also see the ${terminalLink(
|
|
7
|
+
"CedarJS CLI Reference",
|
|
8
|
+
"https://cedarjs.com/docs/cli-commands#setup"
|
|
9
|
+
)}`
|
|
10
|
+
);
|
|
11
|
+
export {
|
|
12
|
+
builder,
|
|
13
|
+
command,
|
|
14
|
+
description
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
2
|
+
const command = "postgres";
|
|
3
|
+
const description = "Switch your project from SQLite to PostgreSQL (schema, dependencies, and database adapter)";
|
|
4
|
+
function builder(yargs) {
|
|
5
|
+
return yargs;
|
|
6
|
+
}
|
|
7
|
+
async function handler() {
|
|
8
|
+
recordTelemetryAttributes({
|
|
9
|
+
command: "setup database postgres"
|
|
10
|
+
});
|
|
11
|
+
const { handler: handler2 } = await import("./postgresHandler.js");
|
|
12
|
+
return handler2();
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
builder,
|
|
16
|
+
command,
|
|
17
|
+
description,
|
|
18
|
+
handler
|
|
19
|
+
};
|