@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
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import execa from "execa";
|
|
4
|
+
import { Listr } from "listr2";
|
|
5
|
+
import { colors } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { installPackages } from "@cedarjs/cli-helpers/installHelpers";
|
|
7
|
+
import { prettyPrintCedarCommand } from "@cedarjs/cli-helpers/packageManager";
|
|
8
|
+
import { addWorkspacePackages } from "@cedarjs/cli-helpers/packageManager/packages";
|
|
9
|
+
import { getPaths } from "@cedarjs/cli-helpers/paths";
|
|
10
|
+
import { resolveFile } from "@cedarjs/project-config";
|
|
11
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
12
|
+
function checkProjectShape(cedarPaths) {
|
|
13
|
+
const schemaPath = path.join(cedarPaths.api.base, "db", "schema.prisma");
|
|
14
|
+
const dbPath = resolveFile(path.join(cedarPaths.api.lib, "db"));
|
|
15
|
+
if (!fs.existsSync(schemaPath)) {
|
|
16
|
+
return blocked(`Could not find ${schemaPath}.`);
|
|
17
|
+
}
|
|
18
|
+
if (!dbPath) {
|
|
19
|
+
return blocked(`No ${path.join(cedarPaths.api.lib, "db")} file found`);
|
|
20
|
+
}
|
|
21
|
+
const schemaContent = fs.readFileSync(schemaPath, "utf-8");
|
|
22
|
+
const hasPgAdapter = fs.readFileSync(dbPath, "utf-8").includes("PrismaPg");
|
|
23
|
+
if (schemaContent.includes('provider = "postgresql"') && hasPgAdapter) {
|
|
24
|
+
return {
|
|
25
|
+
ok: false,
|
|
26
|
+
alreadyConverted: true,
|
|
27
|
+
message: "This project is already configured for PostgreSQL."
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (!schemaContent.includes('provider = "sqlite"') || hasPgAdapter) {
|
|
31
|
+
return blocked(
|
|
32
|
+
"This command only converts a project that is still on SQLite, with the default adapter in api/src/lib/db.ts (or db.js) untouched. This project doesn't match that shape (a different provider, or a partial previous conversion). Please switch it over to PostgreSQL manually."
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return { ok: true, dbPath };
|
|
36
|
+
}
|
|
37
|
+
function blocked(message) {
|
|
38
|
+
return { ok: false, alreadyConverted: false, message };
|
|
39
|
+
}
|
|
40
|
+
function getSqliteToPostgresTasks({
|
|
41
|
+
dbPath
|
|
42
|
+
}) {
|
|
43
|
+
const cedarPaths = getPaths();
|
|
44
|
+
const schemaPath = path.join(cedarPaths.api.base, "db", "schema.prisma");
|
|
45
|
+
const rootPkgPath = path.join(cedarPaths.base, "package.json");
|
|
46
|
+
const apiPkgPath = path.join(cedarPaths.api.base, "package.json");
|
|
47
|
+
const dbTsTemplatePath = path.join(
|
|
48
|
+
import.meta.dirname,
|
|
49
|
+
"templates",
|
|
50
|
+
"db.ts.template"
|
|
51
|
+
);
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
title: "Removing SQLite dependencies from api/package.json",
|
|
55
|
+
task: () => {
|
|
56
|
+
const pkg = JSON.parse(fs.readFileSync(apiPkgPath, "utf-8"));
|
|
57
|
+
if (pkg.dependencies) {
|
|
58
|
+
delete pkg.dependencies["better-sqlite3"];
|
|
59
|
+
delete pkg.dependencies["@prisma/adapter-better-sqlite3"];
|
|
60
|
+
}
|
|
61
|
+
fs.writeFileSync(apiPkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
title: "Removing better-sqlite3 dependenciesMeta",
|
|
66
|
+
task: () => {
|
|
67
|
+
if (!fs.existsSync(rootPkgPath)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const pkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
|
|
71
|
+
if (pkg.dependenciesMeta?.["better-sqlite3"]) {
|
|
72
|
+
delete pkg.dependenciesMeta["better-sqlite3"];
|
|
73
|
+
if (Object.keys(pkg.dependenciesMeta).length === 0) {
|
|
74
|
+
delete pkg.dependenciesMeta;
|
|
75
|
+
}
|
|
76
|
+
fs.writeFileSync(rootPkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
title: "Switching Prisma schema to PostgreSQL",
|
|
82
|
+
task: () => {
|
|
83
|
+
const schemaContent = fs.readFileSync(schemaPath, "utf-8");
|
|
84
|
+
fs.writeFileSync(
|
|
85
|
+
schemaPath,
|
|
86
|
+
schemaContent.replace(
|
|
87
|
+
'provider = "sqlite"',
|
|
88
|
+
'provider = "postgresql"'
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
title: "Updating database adapter",
|
|
95
|
+
task: () => {
|
|
96
|
+
const pgDbTs = fs.readFileSync(dbTsTemplatePath, "utf-8");
|
|
97
|
+
fs.writeFileSync(dbPath, pgDbTs);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
title: "Adding required api packages...",
|
|
102
|
+
task: async () => {
|
|
103
|
+
await addWorkspacePackages("api", ["@prisma/adapter-pg@7.8.0"], {
|
|
104
|
+
cwd: cedarPaths.api.base
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
function readEnvVar(envContent, name) {
|
|
111
|
+
return envContent.match(new RegExp(`^${name}=(.*)$`, "m"))?.[1] || void 0;
|
|
112
|
+
}
|
|
113
|
+
async function handler() {
|
|
114
|
+
const cedarPaths = getPaths();
|
|
115
|
+
const shape = checkProjectShape(cedarPaths);
|
|
116
|
+
if (!shape.ok) {
|
|
117
|
+
if (shape.alreadyConverted) {
|
|
118
|
+
console.log(colors.note(shape.message));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
console.error(colors.error(shape.message));
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
const envPath = path.join(cedarPaths.base, ".env");
|
|
125
|
+
const envContent = fs.existsSync(envPath) ? fs.readFileSync(envPath, "utf-8") : "";
|
|
126
|
+
const databaseUrl = readEnvVar(envContent, "DATABASE_URL");
|
|
127
|
+
const tasks = new Listr(
|
|
128
|
+
[
|
|
129
|
+
...getSqliteToPostgresTasks({ dbPath: shape.dbPath }),
|
|
130
|
+
installPackages,
|
|
131
|
+
{
|
|
132
|
+
title: "Running Prisma migrations",
|
|
133
|
+
skip: () => {
|
|
134
|
+
if (!databaseUrl) {
|
|
135
|
+
return `No DATABASE_URL found in \`.env\`. Set it to your PostgreSQL connection string, then run \`${prettyPrintCedarCommand(["prisma", "migrate", "dev"])}\``;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
},
|
|
139
|
+
task: () => {
|
|
140
|
+
const result = execa.commandSync(
|
|
141
|
+
"yarn cedar prisma migrate dev --name init-postgres",
|
|
142
|
+
{
|
|
143
|
+
cwd: cedarPaths.base,
|
|
144
|
+
stdio: ["inherit", "inherit", "pipe"],
|
|
145
|
+
reject: false
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
if (result.exitCode !== 0) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
"Prisma migration failed:\n\n" + result.stderr + `
|
|
151
|
+
|
|
152
|
+
You can try running it manually:
|
|
153
|
+
${prettyPrintCedarCommand(["prisma", "migrate", "dev", "--name", "init-postgres"])}`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
{
|
|
160
|
+
exitOnError: false,
|
|
161
|
+
collectErrors: "minimal"
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
try {
|
|
165
|
+
await tasks.run();
|
|
166
|
+
if (tasks.errors.length > 0) {
|
|
167
|
+
for (const error of tasks.errors) {
|
|
168
|
+
if (isErrorWithMessage(error)) {
|
|
169
|
+
errorTelemetry(process.argv, error.message);
|
|
170
|
+
console.error(colors.error(error.message));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
} catch (e) {
|
|
176
|
+
if (isErrorWithMessage(e)) {
|
|
177
|
+
errorTelemetry(process.argv, e.message);
|
|
178
|
+
console.error(colors.error(e.message));
|
|
179
|
+
}
|
|
180
|
+
if (isErrorWithExitCode(e)) {
|
|
181
|
+
process.exit(e.exitCode);
|
|
182
|
+
}
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function isErrorWithMessage(e) {
|
|
187
|
+
return !!e && typeof e === "object" && "message" in e;
|
|
188
|
+
}
|
|
189
|
+
function isErrorWithExitCode(e) {
|
|
190
|
+
return !!e && typeof e === "object" && "exitCode" in e && typeof e.exitCode === "number";
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
checkProjectShape,
|
|
194
|
+
getSqliteToPostgresTasks,
|
|
195
|
+
handler
|
|
196
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
2
|
+
import { PrismaClient } from 'api/db/generated/prisma/client.mts'
|
|
3
|
+
|
|
4
|
+
import { emitLogLevels, handlePrismaLogging } from '@cedarjs/api/logger'
|
|
5
|
+
|
|
6
|
+
import { logger } from './logger.js'
|
|
7
|
+
|
|
8
|
+
export * from 'api/db/generated/prisma/client.mts'
|
|
9
|
+
|
|
10
|
+
if (!process.env.DATABASE_URL) {
|
|
11
|
+
throw new Error('DATABASE_URL environment variable is not set')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
|
|
15
|
+
const prismaClient = new PrismaClient({
|
|
16
|
+
log: emitLogLevels(['info', 'warn', 'error']),
|
|
17
|
+
adapter,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
handlePrismaLogging({
|
|
21
|
+
db: prismaClient,
|
|
22
|
+
logger,
|
|
23
|
+
logLevels: ['info', 'warn', 'error'],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Global Prisma client extensions should be added here, as $extend
|
|
28
|
+
* returns a new instance.
|
|
29
|
+
* export const db = prismaClient.$extend(...)
|
|
30
|
+
* Add any .$on hooks before using $extend
|
|
31
|
+
*/
|
|
32
|
+
export const db = prismaClient
|
|
@@ -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
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import * as parser from "@babel/parser";
|
|
4
|
+
import * as t from "@babel/types";
|
|
3
5
|
import execa from "execa";
|
|
4
6
|
import { Listr } from "listr2";
|
|
5
|
-
import { getConfigPath } from "@cedarjs/project-config";
|
|
7
|
+
import { getConfigPath, getConfig } from "@cedarjs/project-config";
|
|
6
8
|
import { getPaths, writeFilesTask } from "../../../../lib/index.js";
|
|
7
9
|
const updateApiURLTask = (apiUrl) => {
|
|
8
10
|
const configTomlPath = getConfigPath();
|
|
@@ -25,6 +27,9 @@ const updateApiURLTask = (apiUrl) => {
|
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
29
|
};
|
|
30
|
+
function getUserApiUrl() {
|
|
31
|
+
return getConfig().web.apiUrl;
|
|
32
|
+
}
|
|
28
33
|
const preRequisiteCheckTask = (preRequisites) => {
|
|
29
34
|
return {
|
|
30
35
|
title: "Checking pre-requisites",
|
|
@@ -35,9 +40,10 @@ const preRequisiteCheckTask = (preRequisites) => {
|
|
|
35
40
|
task: async () => {
|
|
36
41
|
try {
|
|
37
42
|
await execa(...preReq.command);
|
|
38
|
-
} catch (
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
} catch (e) {
|
|
44
|
+
const baseMsg = e instanceof Error ? e.message : String(e);
|
|
45
|
+
const err = new Error(baseMsg + "\n" + preReq.errorMessage);
|
|
46
|
+
throw err;
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
};
|
|
@@ -53,7 +59,7 @@ const addFilesTask = ({
|
|
|
53
59
|
return {
|
|
54
60
|
title: `${title}...`,
|
|
55
61
|
task: () => {
|
|
56
|
-
|
|
62
|
+
const fileNameToContentMap = {};
|
|
57
63
|
files.forEach((fileData) => {
|
|
58
64
|
fileNameToContentMap[fileData.path] = fileData.content;
|
|
59
65
|
});
|
|
@@ -61,6 +67,121 @@ const addFilesTask = ({
|
|
|
61
67
|
}
|
|
62
68
|
};
|
|
63
69
|
};
|
|
70
|
+
const verifyUDSetupTask = () => {
|
|
71
|
+
return {
|
|
72
|
+
title: "Checking if Universal Deploy is set up...",
|
|
73
|
+
task: () => {
|
|
74
|
+
const paths = getPaths();
|
|
75
|
+
const viteConfigTs = path.join(paths.web.base, "vite.config.ts");
|
|
76
|
+
const viteConfigJs = path.join(paths.web.base, "vite.config.js");
|
|
77
|
+
const viteConfigPath = fs.existsSync(viteConfigTs) ? viteConfigTs : viteConfigJs;
|
|
78
|
+
if (!fs.existsSync(viteConfigPath)) {
|
|
79
|
+
throw new Error("Vite config file not found");
|
|
80
|
+
}
|
|
81
|
+
const content = fs.readFileSync(viteConfigPath, "utf-8");
|
|
82
|
+
if (!content.includes("cedarUniversalDeployPlugin")) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
"Universal Deploy is not set up. Please run `yarn cedar setup deploy universal-deploy` first."
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
function resolveConfigObject(arg) {
|
|
91
|
+
if (t.isObjectExpression(arg)) {
|
|
92
|
+
return arg;
|
|
93
|
+
}
|
|
94
|
+
if (t.isArrowFunctionExpression(arg)) {
|
|
95
|
+
if (t.isObjectExpression(arg.body)) {
|
|
96
|
+
return arg.body;
|
|
97
|
+
}
|
|
98
|
+
if (t.isBlockStatement(arg.body)) {
|
|
99
|
+
const returnStmt = arg.body.body.find((s) => t.isReturnStatement(s));
|
|
100
|
+
if (t.isObjectExpression(returnStmt?.argument)) {
|
|
101
|
+
return returnStmt.argument;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if (t.isFunctionExpression(arg)) {
|
|
107
|
+
if (t.isBlockStatement(arg.body)) {
|
|
108
|
+
const returnStmt = arg.body.body.find(t.isReturnStatement);
|
|
109
|
+
if (t.isObjectExpression(returnStmt?.argument)) {
|
|
110
|
+
return returnStmt.argument;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
function insertPluginsBeforeCedar({
|
|
118
|
+
content,
|
|
119
|
+
pluginCodes
|
|
120
|
+
}) {
|
|
121
|
+
const ast = parser.parse(content, {
|
|
122
|
+
sourceType: "module",
|
|
123
|
+
plugins: ["typescript", "jsx"]
|
|
124
|
+
});
|
|
125
|
+
const defaultExport = ast.program.body.find(t.isExportDefaultDeclaration);
|
|
126
|
+
if (!defaultExport) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const declaration = defaultExport.declaration;
|
|
130
|
+
const configArg = resolveConfigObject(declaration.arguments[0]);
|
|
131
|
+
if (!configArg) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const pluginsProp = configArg.properties.find(t.isObjectProperty);
|
|
135
|
+
if (!t.isArrayExpression(pluginsProp?.value)) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const arrayExpr = pluginsProp.value;
|
|
139
|
+
const elements = arrayExpr.elements;
|
|
140
|
+
const cedarIndex = elements.findIndex(
|
|
141
|
+
(el) => t.isCallExpression(el) && t.isIdentifier(el.callee) && el.callee.name === "cedar"
|
|
142
|
+
);
|
|
143
|
+
if (cedarIndex === -1) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const cedarElement = elements[cedarIndex];
|
|
147
|
+
if (!cedarElement || !t.isCallExpression(cedarElement)) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const cedarNode = cedarElement;
|
|
151
|
+
if (!cedarNode.loc || !arrayExpr.loc || !pluginsProp.loc || cedarNode.start == null || arrayExpr.start == null || arrayExpr.end == null) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const isInline = cedarNode.loc.start.line === arrayExpr.loc.start.line;
|
|
155
|
+
if (isInline) {
|
|
156
|
+
const precedingText = content.slice(0, arrayExpr.start);
|
|
157
|
+
const followingText = content.slice(arrayExpr.end);
|
|
158
|
+
const existingCodes = elements.flatMap((el) => {
|
|
159
|
+
if (el?.start == null || el.end == null) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
return [content.slice(el.start, el.end)];
|
|
163
|
+
});
|
|
164
|
+
const lines2 = content.split("\n");
|
|
165
|
+
const pluginsLine = pluginsProp.loc.start.line;
|
|
166
|
+
const pluginsIndent = (lines2[pluginsLine - 1].match(/^\s*/) ?? [""])[0];
|
|
167
|
+
const elemIndent = pluginsIndent + " ";
|
|
168
|
+
const allCodes = [...existingCodes];
|
|
169
|
+
allCodes.splice(cedarIndex, 0, ...pluginCodes);
|
|
170
|
+
const multiline = [
|
|
171
|
+
"[",
|
|
172
|
+
...allCodes.map((code) => `${elemIndent}${code},`),
|
|
173
|
+
`${pluginsIndent}]`
|
|
174
|
+
].join("\n");
|
|
175
|
+
return precedingText + multiline + followingText;
|
|
176
|
+
}
|
|
177
|
+
const cedarLine = cedarNode.loc.start.line;
|
|
178
|
+
const insertPos = cedarNode.start - cedarNode.loc.start.column;
|
|
179
|
+
const lines = content.split("\n");
|
|
180
|
+
const indent = (lines[cedarLine - 1].match(/^\s*/) ?? [""])[0];
|
|
181
|
+
const insertion = pluginCodes.map((code) => `${indent}${code},
|
|
182
|
+
`).join("");
|
|
183
|
+
return content.slice(0, insertPos) + insertion + content.slice(insertPos);
|
|
184
|
+
}
|
|
64
185
|
const addToGitIgnoreTask = ({ paths }) => {
|
|
65
186
|
return {
|
|
66
187
|
title: "Updating .gitignore...",
|
|
@@ -68,6 +189,7 @@ const addToGitIgnoreTask = ({ paths }) => {
|
|
|
68
189
|
if (!fs.existsSync(path.resolve(getPaths().base, ".gitignore"))) {
|
|
69
190
|
return "No gitignore present, skipping.";
|
|
70
191
|
}
|
|
192
|
+
return void 0;
|
|
71
193
|
},
|
|
72
194
|
task: async (_ctx, task) => {
|
|
73
195
|
const gitIgnore = path.resolve(getPaths().base, ".gitignore");
|
|
@@ -86,6 +208,7 @@ const addToDotEnvTask = ({ lines }) => {
|
|
|
86
208
|
if (!fs.existsSync(path.resolve(getPaths().base, ".env"))) {
|
|
87
209
|
return "No .env present, skipping.";
|
|
88
210
|
}
|
|
211
|
+
return void 0;
|
|
89
212
|
},
|
|
90
213
|
task: async (_ctx, task) => {
|
|
91
214
|
const env = path.resolve(getPaths().base, ".env");
|
|
@@ -101,6 +224,9 @@ export {
|
|
|
101
224
|
addFilesTask,
|
|
102
225
|
addToDotEnvTask,
|
|
103
226
|
addToGitIgnoreTask,
|
|
227
|
+
getUserApiUrl,
|
|
228
|
+
insertPluginsBeforeCedar,
|
|
104
229
|
preRequisiteCheckTask,
|
|
105
|
-
updateApiURLTask
|
|
230
|
+
updateApiURLTask,
|
|
231
|
+
verifyUDSetupTask
|
|
106
232
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
import { Listr } from "listr2";
|
|
3
|
-
import
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
4
7
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
5
|
-
import c from "../../../../lib/colors.js";
|
|
6
8
|
import {
|
|
7
9
|
addPackagesTask,
|
|
8
10
|
getPaths,
|
|
@@ -36,6 +38,24 @@ const handler = async ({ force }) => {
|
|
|
36
38
|
command: "setup deploy baremetal",
|
|
37
39
|
force
|
|
38
40
|
});
|
|
41
|
+
if (fs.existsSync(path.join(getPaths().base, ".pnp.cjs"))) {
|
|
42
|
+
console.warn(
|
|
43
|
+
c.warning(
|
|
44
|
+
"Your project uses Yarn PnP (Plug'n'Play), which is not officially supported for Baremetal deployments. The generated ecosystem.config.js file uses node_modules/.bin/cedar as the PM2 script path, which will most likely not work under PnP.\n\nYou will need to manually configure the server. See also the packageManagerCommand field in deploy.toml."
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
console.log();
|
|
48
|
+
const { confirmed } = await prompts({
|
|
49
|
+
type: "confirm",
|
|
50
|
+
name: "confirmed",
|
|
51
|
+
message: "Generate the default config anyway? (You can edit it later)"
|
|
52
|
+
});
|
|
53
|
+
if (!confirmed) {
|
|
54
|
+
console.log("Aborting baremetal setup.");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
console.log();
|
|
58
|
+
}
|
|
39
59
|
const tasks = new Listr(
|
|
40
60
|
[
|
|
41
61
|
await addPackagesTask({
|
|
@@ -53,9 +73,11 @@ const handler = async ({ force }) => {
|
|
|
53
73
|
try {
|
|
54
74
|
await tasks.run();
|
|
55
75
|
} catch (e) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
77
|
+
errorTelemetry(process.argv, message);
|
|
78
|
+
console.error(c.error(message));
|
|
79
|
+
const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
|
|
80
|
+
process.exit(exitCode);
|
|
59
81
|
}
|
|
60
82
|
};
|
|
61
83
|
export {
|