@cedarjs/cli 2.8.1-next.109 → 2.8.1-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/build/buildHandler.js +6 -9
- package/dist/commands/build.js +1 -2
- package/dist/commands/check.js +4 -2
- package/dist/commands/console.js +2 -2
- package/dist/commands/consoleHandler.js +4 -10
- package/dist/commands/dev/devHandler.js +4 -1
- package/dist/commands/execHandler.js +4 -11
- package/dist/commands/generate/dataMigration/dataMigration.js +2 -1
- package/dist/commands/generate/realtime/realtimeHandler.js +3 -3
- package/dist/commands/generate/service/serviceHandler.js +2 -1
- package/dist/commands/generate.js +1 -8
- package/dist/commands/jobsHandler.js +2 -4
- package/dist/commands/lint.js +2 -2
- package/dist/commands/prerenderHandler.js +35 -65
- package/dist/commands/prismaHandler.js +18 -41
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +3 -3
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +12 -4
- package/dist/commands/setup/deploy/providers/renderHandler.js +12 -5
- package/dist/commands/setup/jobs/jobsHandler.js +4 -3
- package/dist/commands/setup/realtime/realtime.js +1 -1
- package/dist/commands/setup/realtime/realtimeHandler.js +1 -20
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +1 -1
- package/dist/commands/test.js +1 -5
- package/dist/commands/testEsm.js +1 -5
- package/dist/commands/{test/testHandler.js → testHandler.js} +30 -43
- package/dist/commands/{test/testHandlerEsm.js → testHandlerEsm.js} +23 -38
- package/dist/commands/type-checkHandler.js +12 -21
- package/dist/commands/upgrade/upgradeHandler.js +9 -22
- package/dist/lib/background.js +0 -2
- package/dist/lib/generatePrismaClient.js +4 -4
- package/dist/lib/schemaHelpers.js +6 -3
- package/dist/lib/test.js +0 -10
- package/dist/telemetry/resource.js +3 -1
- package/dist/testLib/cells.js +3 -5
- package/package.json +19 -17
- package/dist/commands/test/datasourceWarning.js +0 -42
|
@@ -29,9 +29,7 @@ function checkWorkspacePackageEntryPoints(cedarPaths) {
|
|
|
29
29
|
if (!fs.existsSync(pkgJsonPath)) {
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
|
-
const pkgJson = JSON.parse(
|
|
33
|
-
fs.readFileSync(pkgJsonPath, "utf8")
|
|
34
|
-
);
|
|
32
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
35
33
|
const pkgName = pkgJson.name || entry.name;
|
|
36
34
|
const pkgDir = path.join(packagesDir, entry.name);
|
|
37
35
|
const entryFiles = /* @__PURE__ */ new Set();
|
|
@@ -80,13 +78,12 @@ const handler = async ({
|
|
|
80
78
|
const cedarConfig = getConfig();
|
|
81
79
|
const useFragments = cedarConfig.graphql?.fragments;
|
|
82
80
|
const useTrustedDocuments = cedarConfig.graphql?.trustedDocuments;
|
|
81
|
+
const usePackagesWorkspace = cedarConfig.experimental?.packagesWorkspace?.enabled;
|
|
83
82
|
const prismaSchemaExists = fs.existsSync(cedarPaths.api.prismaConfig);
|
|
84
83
|
const prerenderRoutes = prerender && workspace.includes("web") ? detectPrerenderRoutes() : [];
|
|
85
84
|
const shouldGeneratePrismaClient = prisma && prismaSchemaExists && (workspace.includes("api") || prerenderRoutes.length > 0);
|
|
86
85
|
const packageJsonPath = path.join(cedarPaths.base, "package.json");
|
|
87
|
-
const packageJson = JSON.parse(
|
|
88
|
-
fs.readFileSync(packageJsonPath, "utf8")
|
|
89
|
-
);
|
|
86
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
90
87
|
const packageJsonWorkspaces = packageJson.workspaces;
|
|
91
88
|
const nonApiWebWorkspaces = Array.isArray(packageJsonWorkspaces) && packageJsonWorkspaces.length > 2 ? workspace.filter((w) => w !== "api" && w !== "web") : [];
|
|
92
89
|
const gqlFeaturesTaskTitle = `Generating types needed for ${[
|
|
@@ -104,11 +101,11 @@ const handler = async ({
|
|
|
104
101
|
});
|
|
105
102
|
}
|
|
106
103
|
},
|
|
107
|
-
nonApiWebWorkspaces.length > 0 && {
|
|
104
|
+
nonApiWebWorkspaces.length > 0 && usePackagesWorkspace && {
|
|
108
105
|
title: "Building Packages...",
|
|
109
106
|
task: (_ctx, task) => buildPackagesTask(task, nonApiWebWorkspaces)
|
|
110
107
|
},
|
|
111
|
-
(workspace.includes("web") || workspace.includes("api")) && {
|
|
108
|
+
(workspace.includes("web") || workspace.includes("api")) && usePackagesWorkspace && {
|
|
112
109
|
title: "Checking workspace packages...",
|
|
113
110
|
task: () => {
|
|
114
111
|
const problems = checkWorkspacePackageEntryPoints(cedarPaths);
|
|
@@ -180,7 +177,7 @@ Run ` + c.info("yarn cedar build") + " (without specifying a workspace) to build
|
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
|
-
].filter(
|
|
180
|
+
].filter(Boolean);
|
|
184
181
|
const triggerPrerender = async () => {
|
|
185
182
|
console.log("Starting prerendering...");
|
|
186
183
|
if (prerenderRoutes.length === 0) {
|
package/dist/commands/build.js
CHANGED
|
@@ -9,8 +9,7 @@ const builder = (yargs) => {
|
|
|
9
9
|
yargs.positional("workspace", {
|
|
10
10
|
default: ["api", "web", "packages/*"],
|
|
11
11
|
description: "What workspace(s) to build. Valid values are: web, api, packages/*, <package-name>",
|
|
12
|
-
type: "
|
|
13
|
-
array: true
|
|
12
|
+
type: "array"
|
|
14
13
|
}).option("verbose", {
|
|
15
14
|
alias: "v",
|
|
16
15
|
default: false,
|
package/dist/commands/check.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
2
2
|
import c from "../lib/colors.js";
|
|
3
|
+
import { getPaths } from "../lib/index.js";
|
|
3
4
|
const command = "check";
|
|
4
5
|
const aliases = ["diagnostics"];
|
|
5
6
|
const description = "Get structural diagnostics for a Redwood project (experimental)";
|
|
6
7
|
const handler = async () => {
|
|
7
8
|
recordTelemetryAttributes({ command: "check" });
|
|
8
|
-
const { printDiagnostics, DiagnosticSeverity } = await import("@cedarjs/structure");
|
|
9
|
-
|
|
9
|
+
const { printDiagnostics, DiagnosticSeverity } = (await import("@cedarjs/structure")).default;
|
|
10
|
+
console.log("DiagnosticServerity", DiagnosticSeverity);
|
|
11
|
+
printDiagnostics(getPaths().base, {
|
|
10
12
|
getSeverityLabel: (severity) => {
|
|
11
13
|
if (severity === DiagnosticSeverity.Error) {
|
|
12
14
|
return c.error("error");
|
package/dist/commands/console.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const command = "console";
|
|
2
2
|
const aliases = ["c"];
|
|
3
3
|
const description = "Launch an interactive Redwood shell (experimental)";
|
|
4
|
-
const handler = async () => {
|
|
4
|
+
const handler = async (options) => {
|
|
5
5
|
const { handler: handler2 } = await import("./consoleHandler.js");
|
|
6
|
-
return handler2();
|
|
6
|
+
return handler2(options);
|
|
7
7
|
};
|
|
8
8
|
export {
|
|
9
9
|
aliases,
|
|
@@ -6,9 +6,6 @@ import { registerApiSideBabelHook } from "@cedarjs/babel-config";
|
|
|
6
6
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
7
7
|
import { getPaths } from "../lib/index.js";
|
|
8
8
|
const paths = getPaths();
|
|
9
|
-
function isREPLServerWithHistory(replServer) {
|
|
10
|
-
return "history" in replServer && "lines" in replServer;
|
|
11
|
-
}
|
|
12
9
|
const loadPrismaClient = (replContext) => {
|
|
13
10
|
const createdRequire = createRequire(import.meta.url);
|
|
14
11
|
const { db } = createdRequire(path.join(paths.api.lib, "db"));
|
|
@@ -17,19 +14,16 @@ const loadPrismaClient = (replContext) => {
|
|
|
17
14
|
};
|
|
18
15
|
const consoleHistoryFile = path.join(paths.generated.base, "console_history");
|
|
19
16
|
const persistConsoleHistory = (r) => {
|
|
20
|
-
const lines = isREPLServerWithHistory(r) ? r.lines : [];
|
|
21
17
|
fs.appendFileSync(
|
|
22
18
|
consoleHistoryFile,
|
|
23
|
-
lines.filter((line) => line.trim()).join("\n") + "\n",
|
|
19
|
+
r.lines.filter((line) => line.trim()).join("\n") + "\n",
|
|
24
20
|
"utf8"
|
|
25
21
|
);
|
|
26
22
|
};
|
|
27
23
|
const loadConsoleHistory = async (r) => {
|
|
28
24
|
try {
|
|
29
25
|
const history = await fs.promises.readFile(consoleHistoryFile, "utf8");
|
|
30
|
-
|
|
31
|
-
history.split("\n").reverse().map((line) => r.history.push(line));
|
|
32
|
-
}
|
|
26
|
+
history.split("\n").reverse().map((line) => r.history.push(line));
|
|
33
27
|
} catch {
|
|
34
28
|
}
|
|
35
29
|
};
|
|
@@ -59,8 +53,8 @@ const handler = (_options) => {
|
|
|
59
53
|
} else {
|
|
60
54
|
try {
|
|
61
55
|
callback(null, await Promise.resolve(result));
|
|
62
|
-
} catch (
|
|
63
|
-
callback(
|
|
56
|
+
} catch (error) {
|
|
57
|
+
callback(error, null);
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
60
|
});
|
|
@@ -83,7 +83,10 @@ const handler = async ({
|
|
|
83
83
|
}
|
|
84
84
|
if (workspace.includes("api")) {
|
|
85
85
|
try {
|
|
86
|
-
await generatePrismaClient({
|
|
86
|
+
await generatePrismaClient({
|
|
87
|
+
verbose: false,
|
|
88
|
+
force: false
|
|
89
|
+
});
|
|
87
90
|
} catch (e) {
|
|
88
91
|
const message = getErrorMessage(e);
|
|
89
92
|
errorTelemetry(process.argv, `Error generating prisma client: ${message}`);
|
|
@@ -36,21 +36,14 @@ const printAvailableScriptsToConsole = () => {
|
|
|
36
36
|
const handler = async (args) => {
|
|
37
37
|
recordTelemetryAttributes({
|
|
38
38
|
command: "exec",
|
|
39
|
-
prisma:
|
|
40
|
-
list:
|
|
39
|
+
prisma: args.prisma,
|
|
40
|
+
list: args.list
|
|
41
41
|
});
|
|
42
42
|
const { name, prisma, list, ...scriptArgs } = args;
|
|
43
43
|
if (list || !name) {
|
|
44
44
|
printAvailableScriptsToConsole();
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
if (Array.isArray(scriptArgs._)) {
|
|
48
|
-
scriptArgs._ = scriptArgs._.slice(1);
|
|
49
|
-
}
|
|
50
|
-
delete scriptArgs.$0;
|
|
51
|
-
delete scriptArgs.l;
|
|
52
|
-
delete scriptArgs.s;
|
|
53
|
-
delete scriptArgs.silent;
|
|
54
47
|
const scriptPath = resolveScriptPath(name);
|
|
55
48
|
if (!scriptPath) {
|
|
56
49
|
console.error(
|
|
@@ -64,11 +57,11 @@ No script called \`${name}\` in the ./scripts folder.
|
|
|
64
57
|
const scriptTasks = [
|
|
65
58
|
{
|
|
66
59
|
title: "Generating Prisma client",
|
|
67
|
-
enabled: () =>
|
|
60
|
+
enabled: () => Boolean(prisma),
|
|
68
61
|
task: () => generatePrismaClient({
|
|
69
62
|
force: false,
|
|
70
63
|
verbose: !args.silent,
|
|
71
|
-
silent:
|
|
64
|
+
silent: args.silent
|
|
72
65
|
})
|
|
73
66
|
},
|
|
74
67
|
{
|
|
@@ -3,6 +3,7 @@ import { paramCase } from "change-case";
|
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import { terminalLink } from "termi-link";
|
|
5
5
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
6
|
+
import { dbReexportsPrismaClient } from "@cedarjs/internal/dist/project";
|
|
6
7
|
import { getDataMigrationsPath } from "@cedarjs/project-config";
|
|
7
8
|
import c from "../../../lib/colors.js";
|
|
8
9
|
import {
|
|
@@ -43,7 +44,7 @@ const files = async ({ name, typescript }) => {
|
|
|
43
44
|
getPaths().api.prismaConfig
|
|
44
45
|
);
|
|
45
46
|
const outputPath = path.join(dataMigrationsPath, outputFilename);
|
|
46
|
-
const prismaImportSource = "src/lib/db";
|
|
47
|
+
const prismaImportSource = dbReexportsPrismaClient() ? "src/lib/db" : "@prisma/client";
|
|
47
48
|
return {
|
|
48
49
|
[outputPath]: await generateTemplate(TEMPLATE_PATHS[extension], {
|
|
49
50
|
name,
|
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import camelcase from "camelcase";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import pascalcase from "pascalcase";
|
|
5
|
-
import pluralize from "pluralize";
|
|
5
|
+
import pluralize, { singular } from "pluralize";
|
|
6
6
|
import prompts from "prompts";
|
|
7
7
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
8
8
|
import { projectIsEsm } from "@cedarjs/project-config";
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { isTypeScriptProject } from "../../../lib/project.js";
|
|
18
18
|
import { isRealtimeSetup, isServerFileSetup } from "../../experimental/util.js";
|
|
19
19
|
const templateVariables = (name) => {
|
|
20
|
-
name =
|
|
20
|
+
name = singular(name.toLowerCase());
|
|
21
21
|
return {
|
|
22
22
|
name,
|
|
23
23
|
collectionName: pluralize(name),
|
|
@@ -38,7 +38,7 @@ const templateVariables = (name) => {
|
|
|
38
38
|
async function handler({ name, type, force, verbose, silent }) {
|
|
39
39
|
const redwoodPaths = getPaths();
|
|
40
40
|
const ts = isTypeScriptProject();
|
|
41
|
-
name =
|
|
41
|
+
name = singular(name.toLowerCase());
|
|
42
42
|
let functionType = type;
|
|
43
43
|
if (!functionType) {
|
|
44
44
|
const response = await prompts({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import camelcase from "camelcase";
|
|
3
|
+
import { dbReexportsPrismaClient } from "@cedarjs/internal/dist/project";
|
|
3
4
|
import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
|
|
4
5
|
import { transformTSToJS } from "../../../lib/index.js";
|
|
5
6
|
import { getSchema, verifyModelName } from "../../../lib/schemaHelpers.js";
|
|
@@ -222,7 +223,7 @@ const files = async ({
|
|
|
222
223
|
const componentName = camelcase(pluralize(name));
|
|
223
224
|
const model = name;
|
|
224
225
|
const idName = await getIdName(model);
|
|
225
|
-
const prismaImportSource = "src/lib/db";
|
|
226
|
+
const prismaImportSource = dbReexportsPrismaClient() ? "src/lib/db" : "@prisma/client";
|
|
226
227
|
const modelRelations = relations || relationsForModel(await getSchema(model));
|
|
227
228
|
const serviceFile = await templateForFile({
|
|
228
229
|
name,
|
|
@@ -22,19 +22,12 @@ import * as generateService from "./generate/service/service.js";
|
|
|
22
22
|
const command = "generate <type>";
|
|
23
23
|
const aliases = ["g"];
|
|
24
24
|
const description = "Generate boilerplate code and type definitions";
|
|
25
|
-
const getExitCode = (error) => {
|
|
26
|
-
if (typeof error !== "object" || error === null) {
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
const exitCode = Reflect.get(error, "exitCode");
|
|
30
|
-
return typeof exitCode === "number" ? exitCode : void 0;
|
|
31
|
-
};
|
|
32
25
|
const builder = (yargs) => yargs.command("types", "Generate supplementary code", {}, () => {
|
|
33
26
|
recordTelemetryAttributes({ command: "generate types" });
|
|
34
27
|
try {
|
|
35
28
|
execa.sync("yarn", ["rw-gen"], { stdio: "inherit" });
|
|
36
29
|
} catch (error) {
|
|
37
|
-
process.exitCode =
|
|
30
|
+
process.exitCode = error.exitCode ?? 1;
|
|
38
31
|
}
|
|
39
32
|
}).command(generateCell).command(generateComponent).command(generateDataMigration).command(generateDbAuth).command(generateDirective).command(generateFunction).command(generateJob).command(generateLayout).command(generateModel).command(generateOgImage).command(generatePackage).command(generatePage).command(generateRealtime).command(generateScaffold).command(generateScript).command(generateSdl).command(generateSecret).command(generateService).demandCommand().epilogue(
|
|
40
33
|
`Also see the ${terminalLink(
|
|
@@ -6,12 +6,10 @@ const handler = async ({
|
|
|
6
6
|
commands: _commands,
|
|
7
7
|
...options
|
|
8
8
|
}) => {
|
|
9
|
-
const
|
|
10
|
-
const commandArg = positionalArgs.pop();
|
|
11
|
-
const args = [commandArg == null ? "" : String(commandArg)];
|
|
9
|
+
const args = [_.pop()];
|
|
12
10
|
for (const [name, value] of Object.entries(options)) {
|
|
13
11
|
args.push(name.length > 1 ? `--${name}` : `-${name}`);
|
|
14
|
-
args.push(
|
|
12
|
+
args.push(value);
|
|
15
13
|
}
|
|
16
14
|
let command = `yarn rw-jobs ${args.join(" ")}`;
|
|
17
15
|
const originalLogLevel = process.env.LOG_LEVEL;
|
package/dist/commands/lint.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import execa from "execa";
|
|
4
4
|
import { terminalLink } from "termi-link";
|
|
5
5
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
6
|
-
import { getPaths, getConfig } from "
|
|
6
|
+
import { getPaths, getConfig } from "../lib/index.js";
|
|
7
7
|
function detectLegacyEslintConfig() {
|
|
8
8
|
const projectRoot = getPaths().base;
|
|
9
9
|
const legacyConfigFiles = [
|
|
@@ -88,7 +88,7 @@ const handler = async ({
|
|
|
88
88
|
recordTelemetryAttributes({ command: "lint", fix, format });
|
|
89
89
|
const config = getConfig();
|
|
90
90
|
const legacyConfigFiles = detectLegacyEslintConfig();
|
|
91
|
-
if (legacyConfigFiles.length > 0 && config
|
|
91
|
+
if (legacyConfigFiles.length > 0 && config.eslintLegacyConfigWarning) {
|
|
92
92
|
showLegacyEslintDeprecationWarning(legacyConfigFiles);
|
|
93
93
|
}
|
|
94
94
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "
|
|
2
|
+
import path from "path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
5
5
|
import { getConfig, getPaths, projectIsEsm } from "@cedarjs/project-config";
|
|
@@ -9,33 +9,12 @@ import { runScriptFunction } from "../lib/exec.js";
|
|
|
9
9
|
import { configureBabel } from "../lib/execBabel.js";
|
|
10
10
|
class PathParamError extends Error {
|
|
11
11
|
}
|
|
12
|
-
const hasPath = (route) => {
|
|
13
|
-
return typeof route.path === "string" && route.path.length > 0;
|
|
14
|
-
};
|
|
15
|
-
const normalizeRoute = (route) => {
|
|
16
|
-
const normalizedPath = route.path;
|
|
17
|
-
const normalizedName = typeof route.name === "string" ? route.name : normalizedPath;
|
|
18
|
-
const normalizedRoutePath = typeof route.routePath === "string" ? route.routePath : normalizedPath;
|
|
19
|
-
const normalizedFilePath = typeof route.filePath === "string" ? route.filePath : "";
|
|
20
|
-
return {
|
|
21
|
-
...route,
|
|
22
|
-
name: normalizedName,
|
|
23
|
-
path: normalizedPath,
|
|
24
|
-
routePath: normalizedRoutePath,
|
|
25
|
-
filePath: normalizedFilePath
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const getErrorMessage = (error) => {
|
|
29
|
-
return error instanceof Error ? error.message : String(error);
|
|
30
|
-
};
|
|
31
|
-
const getErrorStack = (error) => {
|
|
32
|
-
return error instanceof Error ? error.stack ?? error.message : String(error);
|
|
33
|
-
};
|
|
34
12
|
const mapRouterPathToHtml = (routerPath) => {
|
|
35
13
|
if (routerPath === "/") {
|
|
36
14
|
return "web/dist/index.html";
|
|
15
|
+
} else {
|
|
16
|
+
return `web/dist${routerPath}.html`;
|
|
37
17
|
}
|
|
38
|
-
return `web/dist${routerPath}.html`;
|
|
39
18
|
};
|
|
40
19
|
function getRouteHooksFilePath(routeFilePath) {
|
|
41
20
|
const routeHooksFilePathTs = routeFilePath.replace(
|
|
@@ -70,32 +49,28 @@ async function expandRouteParameters(route) {
|
|
|
70
49
|
filePath: route.filePath
|
|
71
50
|
}
|
|
72
51
|
});
|
|
73
|
-
if (
|
|
52
|
+
if (routeParameters) {
|
|
74
53
|
return routeParameters.map((pathParamValues) => {
|
|
75
54
|
let newPath = route.path;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
([
|
|
79
|
-
|
|
80
|
-
new RegExp(`{${paramName}:?[^}]*}`),
|
|
81
|
-
String(paramValue)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
55
|
+
Object.entries(pathParamValues).forEach(([paramName, paramValue]) => {
|
|
56
|
+
newPath = newPath.replace(
|
|
57
|
+
new RegExp(`{${paramName}:?[^}]*}`),
|
|
58
|
+
paramValue
|
|
84
59
|
);
|
|
85
|
-
}
|
|
60
|
+
});
|
|
86
61
|
return { ...route, path: newPath };
|
|
87
62
|
});
|
|
88
63
|
}
|
|
89
|
-
} catch (
|
|
90
|
-
console.error(c.error(
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error(c.error(e.stack));
|
|
91
66
|
return [route];
|
|
92
67
|
}
|
|
93
68
|
return [route];
|
|
94
69
|
}
|
|
95
70
|
const getTasks = async (dryrun, routerPathFilter = null) => {
|
|
96
71
|
const detector = projectIsEsm() ? await import("@cedarjs/prerender/detection") : await import("@cedarjs/prerender/cjs/detection");
|
|
97
|
-
const
|
|
98
|
-
const
|
|
72
|
+
const prerenderRoutes = detector.detectPrerenderRoutes().filter((route) => route.path);
|
|
73
|
+
const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
|
|
99
74
|
if (prerenderRoutes.length === 0) {
|
|
100
75
|
console.log("\nSkipping prerender...");
|
|
101
76
|
console.log(
|
|
@@ -105,7 +80,6 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
|
|
|
105
80
|
);
|
|
106
81
|
return [];
|
|
107
82
|
}
|
|
108
|
-
const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
|
|
109
83
|
if (!fs.existsSync(indexHtmlPath)) {
|
|
110
84
|
console.error(
|
|
111
85
|
"You must run `yarn cedar build web` before trying to prerender."
|
|
@@ -151,7 +125,7 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
|
|
|
151
125
|
}
|
|
152
126
|
];
|
|
153
127
|
}
|
|
154
|
-
return routesToPrerender.
|
|
128
|
+
return routesToPrerender.map((routeToPrerender) => {
|
|
155
129
|
if (routerPathFilter && routeToPrerender.path !== routerPathFilter) {
|
|
156
130
|
return [];
|
|
157
131
|
}
|
|
@@ -186,6 +160,12 @@ const diagnosticCheck = () => {
|
|
|
186
160
|
path.join(getPaths().web.base, "node_modules/react-dom")
|
|
187
161
|
)
|
|
188
162
|
},
|
|
163
|
+
{
|
|
164
|
+
message: "Duplicate core-js version found in web/node_modules",
|
|
165
|
+
failure: fs.existsSync(
|
|
166
|
+
path.join(getPaths().web.base, "node_modules/core-js")
|
|
167
|
+
)
|
|
168
|
+
},
|
|
189
169
|
{
|
|
190
170
|
message: "Duplicate @cedarjs/web version found in web/node_modules",
|
|
191
171
|
failure: fs.existsSync(
|
|
@@ -194,7 +174,7 @@ const diagnosticCheck = () => {
|
|
|
194
174
|
}
|
|
195
175
|
];
|
|
196
176
|
console.log("Running diagnostic checks");
|
|
197
|
-
if (checks.some((
|
|
177
|
+
if (checks.some((checks2) => checks2.failure)) {
|
|
198
178
|
console.error(c.error("node_modules are being duplicated in `./web` \n"));
|
|
199
179
|
console.log("\u26A0\uFE0F Issues found: ");
|
|
200
180
|
console.log("-".repeat(50));
|
|
@@ -216,11 +196,8 @@ const diagnosticCheck = () => {
|
|
|
216
196
|
console.log("\u2714 Diagnostics checks passed \n");
|
|
217
197
|
}
|
|
218
198
|
};
|
|
219
|
-
const hasUnexpandedPathParams = (routePath) => {
|
|
220
|
-
return /\{.*}/.test(routePath);
|
|
221
|
-
};
|
|
222
199
|
const prerenderRoute = async (prerenderer, queryCache, routeToPrerender, dryrun, outputHtmlPath) => {
|
|
223
|
-
if (
|
|
200
|
+
if (/\{.*}/.test(routeToPrerender.path)) {
|
|
224
201
|
throw new PathParamError(
|
|
225
202
|
`Could not retrieve route parameters for ${routeToPrerender.path}`
|
|
226
203
|
);
|
|
@@ -230,31 +207,25 @@ const prerenderRoute = async (prerenderer, queryCache, routeToPrerender, dryrun,
|
|
|
230
207
|
queryCache,
|
|
231
208
|
renderPath: routeToPrerender.path
|
|
232
209
|
});
|
|
233
|
-
if (!dryrun
|
|
210
|
+
if (!dryrun) {
|
|
234
211
|
prerenderer.writePrerenderedHtmlFile(outputHtmlPath, prerenderedHtml);
|
|
235
212
|
}
|
|
236
|
-
} catch (
|
|
213
|
+
} catch (e) {
|
|
237
214
|
console.log();
|
|
238
215
|
console.log(
|
|
239
216
|
c.warning("You can use `yarn cedar prerender --dry-run` to debug")
|
|
240
217
|
);
|
|
241
218
|
console.log();
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
errorTelemetry(
|
|
245
|
-
process.argv,
|
|
246
|
-
`Error prerendering: ${getErrorMessage(error)}`
|
|
219
|
+
console.log(
|
|
220
|
+
`${c.info("-".repeat(10))} Error rendering path "${routeToPrerender.path}" ${c.info("-".repeat(10))}`
|
|
247
221
|
);
|
|
248
|
-
|
|
222
|
+
errorTelemetry(process.argv, `Error prerendering: ${e.message}`);
|
|
223
|
+
console.error(c.error(e.stack));
|
|
249
224
|
console.log();
|
|
250
225
|
throw new Error(`Failed to render "${routeToPrerender.filePath}"`);
|
|
251
226
|
}
|
|
252
227
|
};
|
|
253
|
-
const handler = async ({
|
|
254
|
-
path: routerPath,
|
|
255
|
-
dryRun = false,
|
|
256
|
-
verbose = false
|
|
257
|
-
}) => {
|
|
228
|
+
const handler = async ({ path: routerPath, dryRun, verbose }) => {
|
|
258
229
|
if (getConfig().experimental?.streamingSsr?.enabled) {
|
|
259
230
|
console.log(
|
|
260
231
|
c.warning(
|
|
@@ -268,7 +239,7 @@ const handler = async ({
|
|
|
268
239
|
dryRun,
|
|
269
240
|
verbose
|
|
270
241
|
});
|
|
271
|
-
const listrTasks = await getTasks(dryRun, routerPath
|
|
242
|
+
const listrTasks = await getTasks(dryRun, routerPath);
|
|
272
243
|
const tasks = new Listr(listrTasks, {
|
|
273
244
|
renderer: verbose ? "verbose" : "default",
|
|
274
245
|
rendererOptions: { collapseSubtasks: false },
|
|
@@ -279,11 +250,11 @@ const handler = async ({
|
|
|
279
250
|
console.log(c.info("::: Dry run, not writing changes :::"));
|
|
280
251
|
}
|
|
281
252
|
await tasks.run();
|
|
282
|
-
} catch (
|
|
253
|
+
} catch (e) {
|
|
283
254
|
console.log();
|
|
284
|
-
diagnosticCheck();
|
|
255
|
+
await diagnosticCheck();
|
|
285
256
|
console.log(c.warning("Tips:"));
|
|
286
|
-
if (
|
|
257
|
+
if (e instanceof PathParamError) {
|
|
287
258
|
console.log(
|
|
288
259
|
c.info(
|
|
289
260
|
"- You most likely need to add or update a *.routeHooks.{js,ts} file next to the Page you're trying to prerender"
|
|
@@ -292,7 +263,7 @@ const handler = async ({
|
|
|
292
263
|
} else {
|
|
293
264
|
console.log(
|
|
294
265
|
c.info(
|
|
295
|
-
|
|
266
|
+
`- This could mean that a library you're using does not support SSR.`
|
|
296
267
|
)
|
|
297
268
|
);
|
|
298
269
|
console.log(
|
|
@@ -312,6 +283,5 @@ const handler = async ({
|
|
|
312
283
|
};
|
|
313
284
|
export {
|
|
314
285
|
getTasks,
|
|
315
|
-
handler
|
|
316
|
-
hasUnexpandedPathParams
|
|
286
|
+
handler
|
|
317
287
|
};
|
|
@@ -1,81 +1,58 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "
|
|
2
|
+
import path from "path";
|
|
3
3
|
import boxen from "boxen";
|
|
4
4
|
import execa from "execa";
|
|
5
5
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
6
6
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
7
|
import c from "../lib/colors.js";
|
|
8
8
|
import { getPaths } from "../lib/index.js";
|
|
9
|
-
const
|
|
10
|
-
return error instanceof Error ? error.message : String(error);
|
|
11
|
-
};
|
|
12
|
-
function getExitCode(value) {
|
|
13
|
-
if (!value || typeof value !== "object" || !("exitCode" in value) || typeof value.exitCode !== "number") {
|
|
14
|
-
return void 0;
|
|
15
|
-
}
|
|
16
|
-
return value.exitCode;
|
|
17
|
-
}
|
|
18
|
-
const handler = async ({
|
|
19
|
-
_: _positionals,
|
|
20
|
-
$0: _binName,
|
|
21
|
-
commands = [],
|
|
22
|
-
...options
|
|
23
|
-
}) => {
|
|
9
|
+
const handler = async ({ _, $0, commands = [], ...options }) => {
|
|
24
10
|
recordTelemetryAttributes({
|
|
25
11
|
command: "prisma"
|
|
26
12
|
});
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
(value) => typeof value === "string"
|
|
30
|
-
);
|
|
31
|
-
const helpIndex = args.indexOf("help");
|
|
13
|
+
const rwjsPaths = getPaths();
|
|
14
|
+
const helpIndex = commands.indexOf("help");
|
|
32
15
|
if (helpIndex !== -1) {
|
|
33
16
|
options.help = true;
|
|
34
|
-
|
|
17
|
+
commands.splice(helpIndex, 1);
|
|
35
18
|
}
|
|
36
19
|
const hasHelpOption = options.help || options.h;
|
|
37
20
|
if (!hasHelpOption) {
|
|
38
|
-
if (!fs.existsSync(
|
|
21
|
+
if (!fs.existsSync(rwjsPaths.api.prismaConfig)) {
|
|
39
22
|
console.error();
|
|
40
23
|
console.error(c.error("No Prisma config file found."));
|
|
41
|
-
console.error(`Cedar searched here '${
|
|
24
|
+
console.error(`Cedar searched here '${rwjsPaths.api.prismaConfig}'`);
|
|
42
25
|
console.error();
|
|
43
26
|
process.exit(1);
|
|
44
27
|
}
|
|
45
|
-
options.config = `${
|
|
28
|
+
options.config = `${rwjsPaths.api.prismaConfig}`;
|
|
46
29
|
}
|
|
30
|
+
const args = commands;
|
|
47
31
|
for (const [name, value] of Object.entries(options)) {
|
|
48
32
|
args.push(name.length > 1 ? `--${name}` : `-${name}`);
|
|
49
33
|
if (typeof value === "string") {
|
|
50
|
-
|
|
51
|
-
args.push(`"${value}"`);
|
|
52
|
-
} else {
|
|
53
|
-
args.push(value);
|
|
54
|
-
}
|
|
34
|
+
value.split(" ").length > 1 ? args.push(`"${value}"`) : args.push(value);
|
|
55
35
|
} else if (typeof value === "number") {
|
|
56
|
-
args.push(
|
|
36
|
+
args.push(value);
|
|
57
37
|
}
|
|
58
38
|
}
|
|
59
39
|
console.log();
|
|
60
40
|
console.log(c.note("Running Prisma CLI..."));
|
|
61
|
-
console.log(c.underline(
|
|
41
|
+
console.log(c.underline("$ yarn prisma " + args.join(" ")));
|
|
62
42
|
console.log();
|
|
63
43
|
try {
|
|
64
|
-
const prismaBin = path.join(
|
|
44
|
+
const prismaBin = path.join(rwjsPaths.base, "node_modules/.bin/prisma");
|
|
65
45
|
execa.sync(prismaBin, args, {
|
|
66
|
-
cwd:
|
|
46
|
+
cwd: rwjsPaths.base,
|
|
67
47
|
stdio: "inherit",
|
|
68
48
|
cleanup: true
|
|
69
49
|
});
|
|
70
|
-
if (hasHelpOption ||
|
|
50
|
+
if (hasHelpOption || commands.length === 0) {
|
|
71
51
|
printWrapInfo();
|
|
72
52
|
}
|
|
73
|
-
} catch (
|
|
74
|
-
errorTelemetry(
|
|
75
|
-
|
|
76
|
-
`Error generating prisma client: ${getErrorMessage(error)}`
|
|
77
|
-
);
|
|
78
|
-
process.exit(getExitCode(error) ?? 1);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
errorTelemetry(process.argv, `Error generating prisma client: ${e.message}`);
|
|
55
|
+
process.exit(e?.exitCode || 1);
|
|
79
56
|
}
|
|
80
57
|
};
|
|
81
58
|
const printWrapInfo = () => {
|
|
@@ -5,15 +5,15 @@ import { Listr } from "listr2";
|
|
|
5
5
|
import * as toml from "smol-toml";
|
|
6
6
|
import {
|
|
7
7
|
colors as c,
|
|
8
|
+
getPaths,
|
|
8
9
|
isTypeScriptProject,
|
|
9
10
|
getConfigPath
|
|
10
11
|
} from "@cedarjs/cli-helpers";
|
|
11
|
-
import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
|
|
12
12
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
13
13
|
import { printSetupNotes } from "../../../../lib/index.js";
|
|
14
14
|
import { serverFileExists } from "../../../../lib/project.js";
|
|
15
15
|
import { addFilesTask } from "../helpers/index.js";
|
|
16
|
-
const { getConfig } = prismaInternals;
|
|
16
|
+
const { getSchemaWithPath, getConfig } = prismaInternals;
|
|
17
17
|
const cedarPaths = getPaths();
|
|
18
18
|
const EXTENSION = isTypeScriptProject ? "ts" : "js";
|
|
19
19
|
async function handler({ force }) {
|
|
@@ -58,7 +58,7 @@ async function getAddCoherenceFilesTask(force) {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
async function getCoherenceConfigFileContent() {
|
|
61
|
-
const result = await
|
|
61
|
+
const result = await getSchemaWithPath(cedarPaths.api.dbSchema);
|
|
62
62
|
const prismaConfig = await getConfig({ datamodel: result.schemas });
|
|
63
63
|
let db = prismaConfig.datasources[0].activeProvider;
|
|
64
64
|
if (!SUPPORTED_DATABASES.includes(db)) {
|