@cedarjs/cli 1.0.0-canary.13121 → 1.0.0-canary.13124
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.
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import execa from "execa";
|
|
5
|
+
import { Listr } from "listr2";
|
|
6
|
+
import { terminalLink } from "termi-link";
|
|
7
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
8
|
+
import { buildApi, cleanApiBuild } from "@cedarjs/internal/dist/build/api";
|
|
9
|
+
import { generate } from "@cedarjs/internal/dist/generate/generate";
|
|
10
|
+
import { loadAndValidateSdls } from "@cedarjs/internal/dist/validateSchema";
|
|
11
|
+
import { detectPrerenderRoutes } from "@cedarjs/prerender/detection";
|
|
12
|
+
import { timedTelemetry } from "@cedarjs/telemetry";
|
|
13
|
+
import { generatePrismaCommand } from "../../lib/generatePrismaClient.js";
|
|
14
|
+
import { getPaths, getConfig } from "../../lib/index.js";
|
|
15
|
+
import { buildPackagesTask } from "./buildPackagesTask.js";
|
|
16
|
+
const handler = async ({
|
|
17
|
+
workspace = ["api", "web", "packages/*"],
|
|
18
|
+
verbose = false,
|
|
19
|
+
prisma = true,
|
|
20
|
+
prerender = true
|
|
21
|
+
}) => {
|
|
22
|
+
recordTelemetryAttributes({
|
|
23
|
+
command: "build",
|
|
24
|
+
workspace: JSON.stringify(workspace),
|
|
25
|
+
verbose,
|
|
26
|
+
prisma,
|
|
27
|
+
prerender
|
|
28
|
+
});
|
|
29
|
+
const cedarPaths = getPaths();
|
|
30
|
+
const cedarConfig = getConfig();
|
|
31
|
+
const useFragments = cedarConfig.graphql?.fragments;
|
|
32
|
+
const useTrustedDocuments = cedarConfig.graphql?.trustedDocuments;
|
|
33
|
+
const prismaSchemaExists = fs.existsSync(cedarPaths.api.prismaConfig);
|
|
34
|
+
const prerenderRoutes = prerender && workspace.includes("web") ? detectPrerenderRoutes() : [];
|
|
35
|
+
const shouldGeneratePrismaClient = prisma && prismaSchemaExists && (workspace.includes("api") || prerenderRoutes.length > 0);
|
|
36
|
+
const packageJsonPath = path.join(cedarPaths.base, "package.json");
|
|
37
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
38
|
+
const packageJsonWorkspaces = packageJson.workspaces;
|
|
39
|
+
const nonApiWebWorkspaces = Array.isArray(packageJsonWorkspaces) && packageJsonWorkspaces.length > 2 ? workspace.filter((w) => w !== "api" && w !== "web") : [];
|
|
40
|
+
const gqlFeaturesTaskTitle = `Generating types needed for ${[
|
|
41
|
+
useFragments && "GraphQL Fragments",
|
|
42
|
+
useTrustedDocuments && "Trusted Documents"
|
|
43
|
+
].filter(Boolean).join(" and ")} support...`;
|
|
44
|
+
const tasks = [
|
|
45
|
+
shouldGeneratePrismaClient && {
|
|
46
|
+
title: "Generating Prisma Client...",
|
|
47
|
+
task: async () => {
|
|
48
|
+
const { cmd, args } = await generatePrismaCommand();
|
|
49
|
+
return execa(cmd, args, {
|
|
50
|
+
stdio: verbose ? "inherit" : "pipe",
|
|
51
|
+
cwd: cedarPaths.api.base
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
nonApiWebWorkspaces.length > 0 && {
|
|
56
|
+
title: "Building Packages...",
|
|
57
|
+
task: () => buildPackagesTask(nonApiWebWorkspaces)
|
|
58
|
+
},
|
|
59
|
+
// If using GraphQL Fragments or Trusted Documents, then we need to use
|
|
60
|
+
// codegen to generate the types needed for possible types and the trusted
|
|
61
|
+
// document store hashes
|
|
62
|
+
(useFragments || useTrustedDocuments) && {
|
|
63
|
+
title: gqlFeaturesTaskTitle,
|
|
64
|
+
task: generate
|
|
65
|
+
},
|
|
66
|
+
workspace.includes("api") && {
|
|
67
|
+
title: "Verifying graphql schema...",
|
|
68
|
+
task: loadAndValidateSdls
|
|
69
|
+
},
|
|
70
|
+
workspace.includes("api") && {
|
|
71
|
+
title: "Building API...",
|
|
72
|
+
task: async () => {
|
|
73
|
+
await cleanApiBuild();
|
|
74
|
+
const { errors, warnings } = await buildApi();
|
|
75
|
+
if (errors.length) {
|
|
76
|
+
console.error(errors);
|
|
77
|
+
}
|
|
78
|
+
if (warnings.length) {
|
|
79
|
+
console.warn(warnings);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
workspace.includes("web") && {
|
|
84
|
+
title: "Building Web...",
|
|
85
|
+
task: async () => {
|
|
86
|
+
process.env.VITE_CJS_IGNORE_WARNING = "true";
|
|
87
|
+
const createdRequire = createRequire(import.meta.url);
|
|
88
|
+
const buildBinPath = createdRequire.resolve(
|
|
89
|
+
"@cedarjs/vite/bins/rw-vite-build.mjs"
|
|
90
|
+
);
|
|
91
|
+
await execa(
|
|
92
|
+
`node ${buildBinPath} --webDir="${cedarPaths.web.base}" --verbose=${verbose}`,
|
|
93
|
+
{
|
|
94
|
+
stdio: verbose ? "inherit" : "pipe",
|
|
95
|
+
shell: true,
|
|
96
|
+
// `cwd` is needed for yarn to find the rw-vite-build binary
|
|
97
|
+
// It won't change process.cwd for anything else here, in this
|
|
98
|
+
// process
|
|
99
|
+
cwd: cedarPaths.web.base
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
if (!getConfig().experimental?.streamingSsr?.enabled) {
|
|
103
|
+
console.log("Creating 200.html...");
|
|
104
|
+
const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
|
|
105
|
+
fs.copyFileSync(
|
|
106
|
+
indexHtmlPath,
|
|
107
|
+
path.join(getPaths().web.dist, "200.html")
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
].filter(Boolean);
|
|
113
|
+
const triggerPrerender = async () => {
|
|
114
|
+
console.log("Starting prerendering...");
|
|
115
|
+
if (prerenderRoutes.length === 0) {
|
|
116
|
+
console.log(
|
|
117
|
+
`You have not marked any routes to "prerender" in your ${terminalLink(
|
|
118
|
+
"Routes",
|
|
119
|
+
"file://" + cedarPaths.web.routes
|
|
120
|
+
)}.`
|
|
121
|
+
);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await execa("yarn cedar prerender", {
|
|
125
|
+
stdio: "inherit",
|
|
126
|
+
shell: true,
|
|
127
|
+
cwd: cedarPaths.web.base
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const jobs = new Listr(tasks, {
|
|
131
|
+
renderer: verbose ? "verbose" : void 0
|
|
132
|
+
});
|
|
133
|
+
await timedTelemetry(process.argv, { type: "build" }, async () => {
|
|
134
|
+
await jobs.run();
|
|
135
|
+
if (workspace.includes("web") && prerender && prismaSchemaExists) {
|
|
136
|
+
await triggerPrerender();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
export {
|
|
141
|
+
handler
|
|
142
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import concurrently from "concurrently";
|
|
4
|
+
import { importStatementPath } from "@cedarjs/project-config";
|
|
5
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
6
|
+
import { exitWithError } from "../../lib/exit.js";
|
|
7
|
+
import { getPaths } from "../../lib/index.js";
|
|
8
|
+
async function buildPackagesTask(nonApiWebWorkspaces) {
|
|
9
|
+
const cedarPaths = getPaths();
|
|
10
|
+
const globPattern = path.join(cedarPaths.packages, "*").replaceAll("\\", "/");
|
|
11
|
+
const workspacePaths = nonApiWebWorkspaces.some((w) => w === "packages/*") ? await Array.fromAsync(fs.promises.glob(globPattern)) : nonApiWebWorkspaces.map((w) => {
|
|
12
|
+
const workspacePath = path.join(
|
|
13
|
+
cedarPaths.packages,
|
|
14
|
+
w.split("/").at(-1)
|
|
15
|
+
);
|
|
16
|
+
if (!fs.existsSync(workspacePath)) {
|
|
17
|
+
throw new Error(`Workspace not found: ${workspacePath}`);
|
|
18
|
+
}
|
|
19
|
+
return importStatementPath(workspacePath);
|
|
20
|
+
});
|
|
21
|
+
const { result } = concurrently(
|
|
22
|
+
workspacePaths.map((workspacePath) => {
|
|
23
|
+
return {
|
|
24
|
+
command: `yarn build`,
|
|
25
|
+
name: workspacePath.split("/").at(-1),
|
|
26
|
+
cwd: workspacePath
|
|
27
|
+
};
|
|
28
|
+
}),
|
|
29
|
+
{
|
|
30
|
+
prefix: "{name} |",
|
|
31
|
+
timestampFormat: "HH:mm:ss"
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
await result.catch((e) => {
|
|
35
|
+
if (e?.message) {
|
|
36
|
+
errorTelemetry(
|
|
37
|
+
process.argv,
|
|
38
|
+
`Error concurrently building sides: ${e.message}`
|
|
39
|
+
);
|
|
40
|
+
exitWithError(e);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
buildPackagesTask
|
|
46
|
+
};
|
package/dist/commands/build.js
CHANGED
|
@@ -57,7 +57,7 @@ const builder = (yargs) => {
|
|
|
57
57
|
);
|
|
58
58
|
};
|
|
59
59
|
const handler = async (options) => {
|
|
60
|
-
const { handler: handler2 } = await import("./buildHandler.js");
|
|
60
|
+
const { handler: handler2 } = await import("./build/buildHandler.js");
|
|
61
61
|
return handler2(options);
|
|
62
62
|
};
|
|
63
63
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.13124+fb77feb5a",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/preset-typescript": "7.28.5",
|
|
34
34
|
"@babel/runtime-corejs3": "7.28.4",
|
|
35
|
-
"@cedarjs/api-server": "1.0.0-canary.
|
|
36
|
-
"@cedarjs/cli-helpers": "1.0.0-canary.
|
|
37
|
-
"@cedarjs/fastify-web": "1.0.0-canary.
|
|
38
|
-
"@cedarjs/internal": "1.0.0-canary.
|
|
39
|
-
"@cedarjs/prerender": "1.0.0-canary.
|
|
40
|
-
"@cedarjs/project-config": "1.0.0-canary.
|
|
41
|
-
"@cedarjs/structure": "1.0.0-canary.
|
|
42
|
-
"@cedarjs/telemetry": "1.0.0-canary.
|
|
43
|
-
"@cedarjs/web-server": "1.0.0-canary.
|
|
35
|
+
"@cedarjs/api-server": "1.0.0-canary.13124",
|
|
36
|
+
"@cedarjs/cli-helpers": "1.0.0-canary.13124",
|
|
37
|
+
"@cedarjs/fastify-web": "1.0.0-canary.13124",
|
|
38
|
+
"@cedarjs/internal": "1.0.0-canary.13124",
|
|
39
|
+
"@cedarjs/prerender": "1.0.0-canary.13124",
|
|
40
|
+
"@cedarjs/project-config": "1.0.0-canary.13124",
|
|
41
|
+
"@cedarjs/structure": "1.0.0-canary.13124",
|
|
42
|
+
"@cedarjs/telemetry": "1.0.0-canary.13124",
|
|
43
|
+
"@cedarjs/web-server": "1.0.0-canary.13124",
|
|
44
44
|
"@listr2/prompt-adapter-enquirer": "2.0.16",
|
|
45
45
|
"@opentelemetry/api": "1.8.0",
|
|
46
46
|
"@opentelemetry/core": "1.22.0",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"access": "public"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "fb77feb5a1719a126002bf5e4fb63d3bf670bea9"
|
|
106
106
|
}
|