@cedarjs/cli 1.0.0-canary.13134 → 1.0.0-canary.13136

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,18 @@
1
+ import { argv } from "node:process";
2
+ import { getConfig } from "@cedarjs/project-config";
3
+ const defaultApiDebugPort = 18911;
4
+ function getApiDebugFlag(apiDebugPort) {
5
+ if (apiDebugPort) {
6
+ return `--debug-port ${apiDebugPort}`;
7
+ } else if (argv.includes("--apiDebugPort")) {
8
+ return `--debug-port ${defaultApiDebugPort}`;
9
+ }
10
+ const apiDebugPortInConfig = getConfig().api.debugPort;
11
+ if (apiDebugPortInConfig) {
12
+ return `--debug-port ${apiDebugPortInConfig}`;
13
+ }
14
+ return "";
15
+ }
16
+ export {
17
+ getApiDebugFlag
18
+ };
@@ -1,6 +1,5 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { argv } from "node:process";
4
3
  import concurrently from "concurrently";
5
4
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
6
5
  import { shutdownPort } from "@cedarjs/internal/dist/dev";
@@ -12,9 +11,10 @@ import { generatePrismaClient } from "../../lib/generatePrismaClient.js";
12
11
  import { getPaths } from "../../lib/index.js";
13
12
  import { getFreePort } from "../../lib/ports.js";
14
13
  import { serverFileExists } from "../../lib/project.js";
15
- const defaultApiDebugPort = 18911;
14
+ import { getApiDebugFlag } from "./apiDebugFlag.js";
15
+ import { getPackageWatchCommands } from "./packageWatchCommands.js";
16
16
  const handler = async ({
17
- workspace = ["api", "web"],
17
+ workspace = ["api", "web", "packages/*"],
18
18
  forward = "",
19
19
  generate = true,
20
20
  apiDebugPort
@@ -114,18 +114,6 @@ const handler = async ({
114
114
  );
115
115
  }
116
116
  }
117
- const getApiDebugFlag = () => {
118
- if (apiDebugPort) {
119
- return `--debug-port ${apiDebugPort}`;
120
- } else if (argv.includes("--apiDebugPort")) {
121
- return `--debug-port ${defaultApiDebugPort}`;
122
- }
123
- const apiDebugPortInToml = getConfig().api.debugPort;
124
- if (apiDebugPortInToml) {
125
- return `--debug-port ${apiDebugPortInToml}`;
126
- }
127
- return "";
128
- };
129
117
  const cedarConfigPath = getConfigPath();
130
118
  const streamingSsrEnabled = getConfig().experimental?.streamingSsr?.enabled;
131
119
  process.env.VITE_CJS_IGNORE_WARNING = "true";
@@ -133,13 +121,15 @@ const handler = async ({
133
121
  if (streamingSsrEnabled) {
134
122
  webCommand = `yarn cross-env NODE_ENV=development rw-dev-fe ${forward}`;
135
123
  }
124
+ const rootPackageJsonPath = path.join(cedarPaths.base, "package.json");
136
125
  const rootPackageJson = JSON.parse(
137
- fs.readFileSync(path.join(cedarPaths.base, "package.json"), "utf8")
126
+ fs.readFileSync(rootPackageJsonPath, "utf8")
138
127
  );
139
128
  const isEsm = rootPackageJson.type === "module";
140
129
  const serverWatchCommand = isEsm ? `cedarjs-api-server-watch` : `rw-api-server-watch`;
141
- const jobs = {
142
- api: {
130
+ const jobs = [];
131
+ if (workspace.includes("api")) {
132
+ jobs.push({
143
133
  name: "api",
144
134
  command: [
145
135
  "yarn nodemon",
@@ -147,7 +137,7 @@ const handler = async ({
147
137
  ` --watch "${cedarConfigPath}"`,
148
138
  ` --exec "yarn ${serverWatchCommand}`,
149
139
  ` --port ${apiAvailablePort}`,
150
- ` ${getApiDebugFlag()}`,
140
+ ` ${getApiDebugFlag(apiDebugPort)}`,
151
141
  ' | rw-log-formatter"'
152
142
  ].join(" ").replace(/\s+/g, " "),
153
143
  env: {
@@ -156,39 +146,42 @@ const handler = async ({
156
146
  },
157
147
  prefixColor: "cyan",
158
148
  runWhen: () => fs.existsSync(cedarPaths.api.src)
159
- },
160
- web: {
149
+ });
150
+ }
151
+ if (workspace.includes("web")) {
152
+ jobs.push({
161
153
  name: "web",
162
154
  command: webCommand,
163
155
  prefixColor: "blue",
164
156
  cwd: cedarPaths.web.base,
165
157
  runWhen: () => fs.existsSync(cedarPaths.web.src)
166
- },
167
- gen: {
158
+ });
159
+ }
160
+ if (generate) {
161
+ jobs.push({
168
162
  name: "gen",
169
163
  command: "yarn rw-gen-watch",
170
- prefixColor: "green",
171
- runWhen: () => generate
172
- }
173
- };
174
- const mappedJobs = Object.keys(jobs).map((job) => {
175
- if (workspace.includes(job) || job === "gen") {
176
- return jobs[job];
164
+ prefixColor: "green"
165
+ });
166
+ }
167
+ const packageWorkspaces = workspace.filter(
168
+ (w) => w !== "api" && w !== "web" && w !== "gen"
169
+ );
170
+ if (packageWorkspaces.length > 0) {
171
+ const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some(
172
+ (workspace2) => workspace2.startsWith("packages/")
173
+ );
174
+ if (hasPackageJsonWorkspaces && fs.existsSync(cedarPaths.packages)) {
175
+ const pkgCommands = await getPackageWatchCommands(packageWorkspaces);
176
+ jobs.push(...pkgCommands);
177
177
  }
178
- return {
179
- name: "",
180
- command: "",
181
- runWhen: () => false
182
- };
178
+ }
179
+ const filteredJobs = jobs.filter((job) => !job.runWhen || job.runWhen());
180
+ const { result } = concurrently(filteredJobs, {
181
+ prefix: "{name} |",
182
+ timestampFormat: "HH:mm:ss",
183
+ handleInput: true
183
184
  });
184
- const { result } = concurrently(
185
- mappedJobs.filter((job) => job.runWhen()),
186
- {
187
- prefix: "{name} |",
188
- timestampFormat: "HH:mm:ss",
189
- handleInput: true
190
- }
191
- );
192
185
  result.catch((e) => {
193
186
  if (e?.message) {
194
187
  errorTelemetry(
@@ -0,0 +1,54 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { importStatementPath } from "@cedarjs/project-config";
4
+ import c from "../../lib/colors.js";
5
+ import { getPaths } from "../../lib/index.js";
6
+ async function getPackageWatchCommands(packageWorkspaces) {
7
+ const cedarPaths = getPaths();
8
+ const globPattern = path.join(cedarPaths.packages, "*").replaceAll("\\", "/");
9
+ const workspacePaths = packageWorkspaces.some((w) => w === "packages/*") ? await Array.fromAsync(fs.promises.glob(globPattern)) : packageWorkspaces.map((w) => {
10
+ const packageFolderName = w.split("/").at(-1);
11
+ if (!packageFolderName) {
12
+ throw new Error(`Invalid package workspace: ${w}`);
13
+ }
14
+ const workspacePath = path.join(cedarPaths.packages, packageFolderName);
15
+ if (!fs.existsSync(workspacePath)) {
16
+ throw new Error(`Workspace not found: ${workspacePath}`);
17
+ }
18
+ return importStatementPath(workspacePath);
19
+ });
20
+ const watchablePackages = [];
21
+ const packagesWithoutWatch = [];
22
+ for (const workspacePath of workspacePaths) {
23
+ const packageJsonPath = path.join(workspacePath, "package.json");
24
+ if (!fs.existsSync(packageJsonPath)) {
25
+ continue;
26
+ }
27
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
28
+ const packageName = workspacePath.split("/").at(-1);
29
+ if (packageJson.scripts?.watch) {
30
+ watchablePackages.push(workspacePath);
31
+ } else {
32
+ packagesWithoutWatch.push(packageName);
33
+ }
34
+ }
35
+ if (packagesWithoutWatch.length > 0) {
36
+ console.warn(
37
+ `${c.warning("Warning: ")} The following package(s) do not have a "watch" script and will be skipped: ` + packagesWithoutWatch.join(", ")
38
+ );
39
+ }
40
+ return watchablePackages.map((workspacePath) => {
41
+ const name = workspacePath.split("/").at(-1);
42
+ if (!name) {
43
+ throw new Error(`Invalid package path: ${workspacePath}`);
44
+ }
45
+ return {
46
+ name,
47
+ command: "yarn watch",
48
+ cwd: workspacePath
49
+ };
50
+ });
51
+ }
52
+ export {
53
+ getPackageWatchCommands
54
+ };
@@ -1,13 +1,13 @@
1
1
  import { terminalLink } from "termi-link";
2
2
  import c from "../lib/colors.js";
3
+ import { workspaces } from "../lib/project.js";
3
4
  import { checkNodeVersion } from "../middleware/checkNodeVersion.js";
4
5
  const command = "dev [workspace..]";
5
- const description = "Start development servers for api, and web";
6
+ const description = "Start development servers for api, web, and packages";
6
7
  const builder = (yargs) => {
7
8
  yargs.positional("workspace", {
8
- choices: ["api", "web"],
9
- default: ["api", "web"],
10
- description: "Which dev server(s) to start",
9
+ default: ["api", "web", "packages/*"],
10
+ description: "Which dev server(s) to start. Valid values: api, web, packages/*, <package-name>",
11
11
  type: "string",
12
12
  array: true
13
13
  }).option("forward", {
@@ -31,6 +31,22 @@ const builder = (yargs) => {
31
31
  }
32
32
  console.warn(`${c.warning("Warning")}: ${check.message}
33
33
  `);
34
+ }).check((argv) => {
35
+ const workspaceArg = argv.workspace;
36
+ if (!Array.isArray(workspaceArg)) {
37
+ return "Workspace must be an array";
38
+ }
39
+ const filtered = workspaceArg.filter(
40
+ (item) => item !== "api" && item !== "web" && item !== "packages/*"
41
+ );
42
+ if (filtered.length === 0) {
43
+ return true;
44
+ }
45
+ const workspaceNames = workspaces({ includePackages: true });
46
+ if (!filtered.every((item) => workspaceNames.includes(item))) {
47
+ return c.error(`Unknown workspace(s) ${filtered.join(" ")}`) + "\n\nValid values are: " + workspaceNames.join(", ");
48
+ }
49
+ return true;
34
50
  }).epilogue(
35
51
  `Also see the ${terminalLink(
36
52
  "CedarJS CLI Reference",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "1.0.0-canary.13134+7e7f5cf31",
3
+ "version": "1.0.0-canary.13136+34a904f10",
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.13134",
36
- "@cedarjs/cli-helpers": "1.0.0-canary.13134",
37
- "@cedarjs/fastify-web": "1.0.0-canary.13134",
38
- "@cedarjs/internal": "1.0.0-canary.13134",
39
- "@cedarjs/prerender": "1.0.0-canary.13134",
40
- "@cedarjs/project-config": "1.0.0-canary.13134",
41
- "@cedarjs/structure": "1.0.0-canary.13134",
42
- "@cedarjs/telemetry": "1.0.0-canary.13134",
43
- "@cedarjs/web-server": "1.0.0-canary.13134",
35
+ "@cedarjs/api-server": "1.0.0-canary.13136",
36
+ "@cedarjs/cli-helpers": "1.0.0-canary.13136",
37
+ "@cedarjs/fastify-web": "1.0.0-canary.13136",
38
+ "@cedarjs/internal": "1.0.0-canary.13136",
39
+ "@cedarjs/prerender": "1.0.0-canary.13136",
40
+ "@cedarjs/project-config": "1.0.0-canary.13136",
41
+ "@cedarjs/structure": "1.0.0-canary.13136",
42
+ "@cedarjs/telemetry": "1.0.0-canary.13136",
43
+ "@cedarjs/web-server": "1.0.0-canary.13136",
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": "7e7f5cf31b29fd812e0eee4a44512d1525ccf8dd"
105
+ "gitHead": "34a904f109f3c42ded3b22a768f7e768c66ef504"
106
106
  }