@cedarjs/cli 1.0.0-canary.13112 → 1.0.0-canary.13113

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.
@@ -6,11 +6,9 @@ import { checkNodeVersion } from "../middleware/checkNodeVersion.js";
6
6
  const command = "build [workspace..]";
7
7
  const description = "Build for production";
8
8
  const builder = (yargs) => {
9
- const choices = workspaces();
10
9
  yargs.positional("workspace", {
11
- choices,
12
- default: choices,
13
- description: "What workspace(s) to build",
10
+ default: ["web", "api", "packages/*"],
11
+ description: "What workspace(s) to build. Valid values are: web, api, packages/*, <package-name>",
14
12
  type: "array"
15
13
  }).option("verbose", {
16
14
  alias: "v",
@@ -35,6 +33,22 @@ const builder = (yargs) => {
35
33
  message: `${c.error("Error")}: ${check.message}`,
36
34
  includeEpilogue: false
37
35
  });
36
+ }).check((argv) => {
37
+ const workspacesArg = argv.workspace;
38
+ if (!Array.isArray(workspacesArg)) {
39
+ return "Workspace must be an array";
40
+ }
41
+ const filtered = workspacesArg.filter(
42
+ (item) => item !== "api" && item !== "web" && item !== "packages/*"
43
+ );
44
+ if (filtered.length === 0) {
45
+ return true;
46
+ }
47
+ const workspaceNames = workspaces({ includePackages: true });
48
+ if (!workspacesArg.every((item) => workspaceNames.includes(item))) {
49
+ return c.error(`Unknown workspace(s) ${workspacesArg.join(" ")}`) + "\n\nValid values are: " + workspaceNames.join(", ");
50
+ }
51
+ return true;
38
52
  }).epilogue(
39
53
  `Also see the ${terminalLink(
40
54
  "CedarJS CLI Reference",
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
+ import concurrently from "concurrently";
4
5
  import execa from "execa";
5
6
  import { Listr } from "listr2";
6
7
  import { terminalLink } from "termi-link";
@@ -9,11 +10,12 @@ import { buildApi, cleanApiBuild } from "@cedarjs/internal/dist/build/api";
9
10
  import { generate } from "@cedarjs/internal/dist/generate/generate";
10
11
  import { loadAndValidateSdls } from "@cedarjs/internal/dist/validateSchema";
11
12
  import { detectPrerenderRoutes } from "@cedarjs/prerender/detection";
12
- import { timedTelemetry } from "@cedarjs/telemetry";
13
+ import { timedTelemetry, errorTelemetry } from "@cedarjs/telemetry";
14
+ import { exitWithError } from "../lib/exit.js";
13
15
  import { generatePrismaCommand } from "../lib/generatePrismaClient.js";
14
16
  import { getPaths, getConfig } from "../lib/index.js";
15
17
  const handler = async ({
16
- workspace = ["api", "web"],
18
+ workspace = ["api", "web", "packages/*"],
17
19
  verbose = false,
18
20
  prisma = true,
19
21
  prerender = true
@@ -32,6 +34,10 @@ const handler = async ({
32
34
  const prismaSchemaExists = fs.existsSync(cedarPaths.api.prismaConfig);
33
35
  const prerenderRoutes = prerender && workspace.includes("web") ? detectPrerenderRoutes() : [];
34
36
  const shouldGeneratePrismaClient = prisma && prismaSchemaExists && (workspace.includes("api") || prerenderRoutes.length > 0);
37
+ const packageJsonPath = path.join(cedarPaths.base, "package.json");
38
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
39
+ const packageJsonWorkspaces = packageJson.workspaces;
40
+ const restWorkspaces = Array.isArray(packageJsonWorkspaces) && packageJsonWorkspaces.length > 2 ? workspace.filter((w) => w !== "api" && w !== "web") : [];
35
41
  const gqlFeaturesTaskTitle = `Generating types needed for ${[
36
42
  useFragments && "GraphQL Fragments",
37
43
  useTrustedDocuments && "Trusted Documents"
@@ -47,6 +53,47 @@ const handler = async ({
47
53
  });
48
54
  }
49
55
  },
56
+ restWorkspaces.length > 0 && {
57
+ title: "Building Packages...",
58
+ task: async () => {
59
+ const globPattern = path.join(cedarPaths.packages, "*").replaceAll("\\", "/");
60
+ const allPackagePaths = await Array.fromAsync(
61
+ fs.promises.glob(globPattern)
62
+ );
63
+ const workspacePaths = restWorkspaces.some((w) => w === "packages/*") ? allPackagePaths : restWorkspaces.map((w) => {
64
+ const workspacePath = path.join(
65
+ cedarPaths.packages,
66
+ w.split("/").at(-1)
67
+ );
68
+ if (!fs.existsSync(workspacePath)) {
69
+ throw new Error(`Workspace not found: ${workspacePath}`);
70
+ }
71
+ return workspacePath;
72
+ });
73
+ const { result } = concurrently(
74
+ workspacePaths.map((workspacePath) => {
75
+ return {
76
+ command: `yarn build`,
77
+ name: workspacePath.split("/").at(-1),
78
+ cwd: workspacePath
79
+ };
80
+ }),
81
+ {
82
+ prefix: "{name} |",
83
+ timestampFormat: "HH:mm:ss"
84
+ }
85
+ );
86
+ await result.catch((e) => {
87
+ if (e?.message) {
88
+ errorTelemetry(
89
+ process.argv,
90
+ `Error concurrently building sides: ${e.message}`
91
+ );
92
+ exitWithError(e);
93
+ }
94
+ });
95
+ }
96
+ },
50
97
  // If using GraphQL Fragments or Trusted Documents, then we need to use
51
98
  // codegen to generate the types needed for possible types and the trusted
52
99
  // document store hashes
@@ -5,17 +5,31 @@ const isTypeScriptProject = () => {
5
5
  const paths = getPaths();
6
6
  return fs.existsSync(path.join(paths.web.base, "tsconfig.json")) || fs.existsSync(path.join(paths.api.base, "tsconfig.json"));
7
7
  };
8
- const workspaces = () => {
9
- const paths = getPaths();
8
+ function workspaces({ includePackages = false } = {}) {
9
+ const cedarPaths = getPaths();
10
10
  let workspaces2 = [];
11
- if (fs.existsSync(path.join(paths.web.base, "package.json"))) {
11
+ if (fs.existsSync(path.join(cedarPaths.web.base, "package.json"))) {
12
12
  workspaces2 = [...workspaces2, "web"];
13
13
  }
14
- if (fs.existsSync(path.join(paths.api.base, "package.json"))) {
14
+ if (fs.existsSync(path.join(cedarPaths.api.base, "package.json"))) {
15
15
  workspaces2 = [...workspaces2, "api"];
16
16
  }
17
+ if (includePackages) {
18
+ const globPattern = path.join(cedarPaths.packages, "*").replaceAll("\\", "/");
19
+ const allPackagePaths = fs.globSync(globPattern);
20
+ workspaces2 = [
21
+ ...workspaces2,
22
+ "packages/*",
23
+ ...allPackagePaths.map((p) => p.split("/").at(-1)),
24
+ ...allPackagePaths.map((p) => p.split("/").slice(-2).join("/")),
25
+ ...allPackagePaths.map((p) => {
26
+ const packageJsonPath = path.join(p, "package.json");
27
+ return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).name;
28
+ })
29
+ ];
30
+ }
17
31
  return workspaces2;
18
- };
32
+ }
19
33
  const serverFileExists = () => {
20
34
  const serverFilePath = path.join(
21
35
  getPaths().api.src,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "1.0.0-canary.13112+0d25e39c5",
3
+ "version": "1.0.0-canary.13113+fd8038658",
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.13112",
36
- "@cedarjs/cli-helpers": "1.0.0-canary.13112",
37
- "@cedarjs/fastify-web": "1.0.0-canary.13112",
38
- "@cedarjs/internal": "1.0.0-canary.13112",
39
- "@cedarjs/prerender": "1.0.0-canary.13112",
40
- "@cedarjs/project-config": "1.0.0-canary.13112",
41
- "@cedarjs/structure": "1.0.0-canary.13112",
42
- "@cedarjs/telemetry": "1.0.0-canary.13112",
43
- "@cedarjs/web-server": "1.0.0-canary.13112",
35
+ "@cedarjs/api-server": "1.0.0-canary.13113",
36
+ "@cedarjs/cli-helpers": "1.0.0-canary.13113",
37
+ "@cedarjs/fastify-web": "1.0.0-canary.13113",
38
+ "@cedarjs/internal": "1.0.0-canary.13113",
39
+ "@cedarjs/prerender": "1.0.0-canary.13113",
40
+ "@cedarjs/project-config": "1.0.0-canary.13113",
41
+ "@cedarjs/structure": "1.0.0-canary.13113",
42
+ "@cedarjs/telemetry": "1.0.0-canary.13113",
43
+ "@cedarjs/web-server": "1.0.0-canary.13113",
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": "0d25e39c56d22b027dc3851262aa05c1b775d059"
105
+ "gitHead": "fd8038658b10f1f7cc7c6d9b5ea5e1e6f47350f8"
106
106
  }