@cedarjs/cli 4.0.0-canary.13781 → 4.0.0-canary.13783

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.
@@ -1,8 +1,9 @@
1
1
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
- const command = "live-queries";
2
+ import { getEpilogue } from "../util.js";
3
+ const command = "setup-live-queries";
3
4
  const description = "Setup live query invalidation with Postgres notifications";
4
5
  function builder(yargs) {
5
- yargs.option("force", {
6
+ return yargs.option("force", {
6
7
  alias: "f",
7
8
  default: false,
8
9
  description: "Overwrite existing configuration",
@@ -12,11 +13,11 @@ function builder(yargs) {
12
13
  default: false,
13
14
  description: "Print more logs",
14
15
  type: "boolean"
15
- });
16
+ }).epilogue(getEpilogue(command, description));
16
17
  }
17
18
  async function handler(options) {
18
19
  recordTelemetryAttributes({
19
- command: "setup live-queries",
20
+ command: `experimental ${command}`,
20
21
  force: options.force,
21
22
  verbose: options.verbose
22
23
  });
@@ -2,7 +2,11 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { Listr } from "listr2";
4
4
  import { addApiPackages, colors as c } from "@cedarjs/cli-helpers";
5
- import { getMigrationsPath, getSchemaPath } from "@cedarjs/project-config";
5
+ import {
6
+ getConfigPath,
7
+ getMigrationsPath,
8
+ getSchemaPath
9
+ } from "@cedarjs/project-config";
6
10
  import { errorTelemetry } from "@cedarjs/telemetry";
7
11
  import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
8
12
  import { isTypeScriptProject } from "../../../lib/project.js";
@@ -28,10 +32,10 @@ async function getPrismaProvider() {
28
32
  let stat;
29
33
  try {
30
34
  stat = fs.statSync(schemaPath);
31
- } catch (e) {
35
+ } catch {
32
36
  stat = void 0;
33
37
  }
34
- if (stat && stat.isDirectory()) {
38
+ if (stat?.isDirectory()) {
35
39
  const candidate = path.join(schemaPath, "schema.prisma");
36
40
  if (fs.existsSync(candidate)) {
37
41
  schemaPath = candidate;
@@ -44,7 +48,7 @@ async function getPrismaProvider() {
44
48
  }
45
49
  const content = fs.readFileSync(schemaPath, "utf-8");
46
50
  const match = content.match(/^\s*provider\s*=\s*["']([^"']+)["']/im);
47
- if (match && match[1]) {
51
+ if (match?.[1]) {
48
52
  return match[1].toLowerCase();
49
53
  }
50
54
  return void 0;
@@ -52,7 +56,7 @@ async function getPrismaProvider() {
52
56
  return void 0;
53
57
  }
54
58
  }
55
- function findExistingLiveQueryMigration({ migrationsDirectoryPath }) {
59
+ function findExistingLiveQueryMigration(migrationsDirectoryPath) {
56
60
  if (!fs.existsSync(migrationsDirectoryPath)) {
57
61
  return void 0;
58
62
  }
@@ -143,7 +147,7 @@ function addLiveQueryListenerToGraphqlHandler({ force }) {
143
147
  skipped: false
144
148
  };
145
149
  }
146
- async function handler({ force }) {
150
+ async function handler({ force, verbose }) {
147
151
  const projectIsTypescript = isTypeScriptProject();
148
152
  const apiPackageJson = getApiPackageJson();
149
153
  const migrationsPath = await getMigrationsPath(getPaths().api.prismaConfig);
@@ -160,9 +164,7 @@ async function handler({ force }) {
160
164
  "templates",
161
165
  "liveQueriesListener.ts.template"
162
166
  );
163
- const existingMigrationPath = findExistingLiveQueryMigration({
164
- migrationsDirectoryPath: migrationsPath
165
- });
167
+ const existingMigrationPath = findExistingLiveQueryMigration(migrationsPath);
166
168
  const migrationDirPath = path.join(
167
169
  migrationsPath,
168
170
  generateMigrationFolderName()
@@ -202,6 +204,44 @@ async function handler({ force }) {
202
204
  }
203
205
  }
204
206
  },
207
+ {
208
+ title: "Adding [experimental.gqlorm] config...",
209
+ task: (_ctx, task) => {
210
+ const configTomlPath = getConfigPath();
211
+ const configFileName = path.basename(configTomlPath);
212
+ const configContent = fs.readFileSync(configTomlPath, "utf-8");
213
+ if (!configContent.includes("[experimental.gqlorm]")) {
214
+ writeFile(
215
+ configTomlPath,
216
+ configContent.concat(
217
+ "\n\n[experimental.gqlorm]\n enabled = true\n"
218
+ ),
219
+ {
220
+ overwriteExisting: true
221
+ }
222
+ );
223
+ } else {
224
+ if (force) {
225
+ task.output = `Overwriting config in ${configFileName}`;
226
+ writeFile(
227
+ configTomlPath,
228
+ configContent.replace(
229
+ "\n[experimental.gqlorm]\n enabled = false\n",
230
+ "\n[experimental.gqlorm]\n enabled = true\n"
231
+ ),
232
+ {
233
+ overwriteExisting: true
234
+ }
235
+ );
236
+ } else {
237
+ task.skip(
238
+ `The [experimental.gqlorm] config block already exists in ${configFileName}.`
239
+ );
240
+ }
241
+ }
242
+ },
243
+ rendererOptions: { persistentOutput: true }
244
+ },
205
245
  {
206
246
  ...addApiPackages(["pg@^8.18.0"]),
207
247
  title: "Adding pg dependency to your api side...",
@@ -209,6 +249,7 @@ async function handler({ force }) {
209
249
  if (hasPgDependency) {
210
250
  return "pg is already installed";
211
251
  }
252
+ return false;
212
253
  }
213
254
  },
214
255
  {
@@ -231,6 +272,7 @@ async function handler({ force }) {
231
272
  );
232
273
  return `Existing live query migration found: ${migrationPath2}`;
233
274
  }
275
+ return false;
234
276
  }
235
277
  },
236
278
  {
@@ -272,17 +314,29 @@ async function handler({ force }) {
272
314
  }
273
315
  ],
274
316
  {
275
- rendererOptions: { collapseSubtasks: false }
317
+ rendererOptions: { collapseSubtasks: false },
318
+ renderer: verbose ? "verbose" : "default"
276
319
  }
277
320
  );
278
321
  try {
279
322
  await tasks.run();
280
323
  } catch (e) {
281
- errorTelemetry(process.argv, e.message);
282
- console.error(c.error(e.message));
283
- process.exit(e?.exitCode || 1);
324
+ if (isObject(e) && "message" in e) {
325
+ errorTelemetry(process.argv, e.message);
326
+ console.error(c.error(e.message));
327
+ } else {
328
+ errorTelemetry(process.argv, e);
329
+ console.error(c.error(e));
330
+ }
331
+ process.exit(isObjectWithExitCode(e) ? e.exitCode : 1);
284
332
  }
285
333
  }
334
+ function isObject(value) {
335
+ return !!value && typeof value === "object" && !Array.isArray(value);
336
+ }
337
+ function isObjectWithExitCode(value) {
338
+ return isObject(value) && typeof value.exitCode === "number";
339
+ }
286
340
  export {
287
341
  handler
288
342
  };
@@ -4,39 +4,40 @@ import ansis from "ansis";
4
4
  import { terminalLink } from "termi-link";
5
5
  import { getPaths } from "../../lib/index.js";
6
6
  import { isTypeScriptProject, serverFileExists } from "../../lib/project.js";
7
- const link = (topicId, isTerminal = false) => {
7
+ function link(topicId, isTerminal = false) {
8
8
  const communityLink = `https://community.redwoodjs.com/t/${topicId}`;
9
9
  if (isTerminal) {
10
10
  return terminalLink(communityLink, communityLink);
11
11
  } else {
12
12
  return communityLink;
13
13
  }
14
- };
15
- const getEpilogue = (command, description, topicId, isTerminal = false) => `This is an experimental feature to: ${description}.
14
+ }
15
+ function getEpilogue(command, description, topicId, isTerminal = false) {
16
+ let epilogue = `This is an experimental feature to: ${description}.
17
+
18
+ If you need help with ${command}, please join our Discord community.
19
+ -> ${terminalLink("", "https://cedarjs.com/discord")}`;
20
+ if (topicId) {
21
+ epilogue += `
16
22
 
17
- Please find documentation and links to provide feedback for ${command} at:
18
- -> ${link(
19
- topicId,
20
- isTerminal
21
- )}`;
22
- const printTaskEpilogue = (command, description, topicId) => {
23
+ You might also be able to find some information at:
24
+ -> ${link(topicId, isTerminal)}`;
25
+ }
26
+ return epilogue;
27
+ }
28
+ function printTaskEpilogue(command, description, topicId) {
29
+ const orangeLine = ansis.hex("#ff845e")("-".repeat(64));
23
30
  console.log(
24
- `${ansis.hex("#ff845e")(
25
- `------------------------------------------------------------------
26
- \u{1F9EA} ${ansis.green(
27
- "Experimental Feature"
28
- )} \u{1F9EA}
29
- ------------------------------------------------------------------`
30
- )}`
31
+ [
32
+ orangeLine,
33
+ `\u{1F9EA} ${ansis.green("Experimental Feature")} \u{1F9EA}`,
34
+ orangeLine
35
+ ].join("\n")
31
36
  );
32
37
  console.log(getEpilogue(command, description, topicId, false));
33
- console.log(
34
- `${ansis.hex("#ff845e")(
35
- "------------------------------------------------------------------"
36
- )}
37
- `
38
- );
39
- };
38
+ console.log(`${orangeLine}
39
+ `);
40
+ }
40
41
  const isServerFileSetup = () => {
41
42
  if (!serverFileExists()) {
42
43
  throw new Error(
@@ -1,5 +1,6 @@
1
1
  import { terminalLink } from "termi-link";
2
2
  import { detectCedarVersion } from "../middleware/detectProjectCedarVersion.js";
3
+ import * as experimentalLiveQueries from "./experimental/live-queries/liveQueries.js";
3
4
  import * as experimentalInngest from "./experimental/setupInngest.js";
4
5
  import * as experimentalOpenTelemetry from "./experimental/setupOpentelemetry.js";
5
6
  import * as experimentalReactCompiler from "./experimental/setupReactCompiler.js";
@@ -8,7 +9,7 @@ import * as experimentalStreamingSsr from "./experimental/setupStreamingSsr.js";
8
9
  const command = "experimental <command>";
9
10
  const aliases = ["exp"];
10
11
  const description = "Run or setup experimental features";
11
- const builder = (yargs) => yargs.command(experimentalInngest).command(experimentalOpenTelemetry).command(experimentalReactCompiler).command(experimentalRsc).command(experimentalStreamingSsr).demandCommand().middleware(detectCedarVersion).epilogue(
12
+ const builder = (yargs) => yargs.command(experimentalInngest).command(experimentalLiveQueries).command(experimentalOpenTelemetry).command(experimentalReactCompiler).command(experimentalRsc).command(experimentalStreamingSsr).demandCommand().middleware(detectCedarVersion).epilogue(
12
13
  `Also see the ${terminalLink(
13
14
  "CedarJS CLI Reference",
14
15
  "https://cedarjs.com/docs/cli-commands#experimental"
@@ -8,7 +8,6 @@ import * as setupGenerator from "./setup/generator/generator.js";
8
8
  import * as setupGraphql from "./setup/graphql/graphql.js";
9
9
  import * as setupI18n from "./setup/i18n/i18n.js";
10
10
  import * as setupJobs from "./setup/jobs/jobs.js";
11
- import * as setupLiveQueries from "./setup/live-queries/liveQueries.js";
12
11
  import * as setupMailer from "./setup/mailer/mailer.js";
13
12
  import * as setupMiddleware from "./setup/middleware/middleware.js";
14
13
  import * as setupMonitoring from "./setup/monitoring/monitoring.js";
@@ -21,7 +20,7 @@ import * as setupUploads from "./setup/uploads/uploads.js";
21
20
  import * as setupVite from "./setup/vite/vite.js";
22
21
  const command = "setup <command>";
23
22
  const description = "Initialize project config and install packages";
24
- const builder = (yargs) => yargs.command(setupAuth).command(setupCache).command(setupDeploy).command(setupDocker).command(setupGenerator).command(setupGraphql).command(setupI18n).command(setupJobs).command(setupLiveQueries).command(setupMailer).command(setupMiddleware).command(setupMonitoring).command(setupPackage).command(setupRealtime).command(setupServerFile).command(setupTsconfig).command(setupUi).command(setupUploads).command(setupVite).demandCommand().middleware(detectCedarVersion).epilogue(
23
+ const builder = (yargs) => yargs.command(setupAuth).command(setupCache).command(setupDeploy).command(setupDocker).command(setupGenerator).command(setupGraphql).command(setupI18n).command(setupJobs).command(setupMailer).command(setupMiddleware).command(setupMonitoring).command(setupPackage).command(setupRealtime).command(setupServerFile).command(setupTsconfig).command(setupUi).command(setupUploads).command(setupVite).demandCommand().middleware(detectCedarVersion).epilogue(
25
24
  `Also see the ${terminalLink(
26
25
  "CedarJS CLI Reference",
27
26
  "https://cedarjs.com/docs/cli-commands#setup"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "4.0.0-canary.13781+ef38e3e5bf",
3
+ "version": "4.0.0-canary.13783+5cdfb268a3",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,16 +33,16 @@
33
33
  "dependencies": {
34
34
  "@babel/parser": "7.29.2",
35
35
  "@babel/preset-typescript": "7.28.5",
36
- "@cedarjs/api-server": "4.0.0-canary.13781",
37
- "@cedarjs/cli-helpers": "4.0.0-canary.13781",
38
- "@cedarjs/fastify-web": "4.0.0-canary.13781",
39
- "@cedarjs/internal": "4.0.0-canary.13781",
40
- "@cedarjs/prerender": "4.0.0-canary.13781",
41
- "@cedarjs/project-config": "4.0.0-canary.13781",
42
- "@cedarjs/structure": "4.0.0-canary.13781",
43
- "@cedarjs/telemetry": "4.0.0-canary.13781",
44
- "@cedarjs/utils": "4.0.0-canary.13781",
45
- "@cedarjs/web-server": "4.0.0-canary.13781",
36
+ "@cedarjs/api-server": "4.0.0-canary.13783",
37
+ "@cedarjs/cli-helpers": "4.0.0-canary.13783",
38
+ "@cedarjs/fastify-web": "4.0.0-canary.13783",
39
+ "@cedarjs/internal": "4.0.0-canary.13783",
40
+ "@cedarjs/prerender": "4.0.0-canary.13783",
41
+ "@cedarjs/project-config": "4.0.0-canary.13783",
42
+ "@cedarjs/structure": "4.0.0-canary.13783",
43
+ "@cedarjs/telemetry": "4.0.0-canary.13783",
44
+ "@cedarjs/utils": "4.0.0-canary.13783",
45
+ "@cedarjs/web-server": "4.0.0-canary.13783",
46
46
  "@listr2/prompt-adapter-enquirer": "4.2.1",
47
47
  "@opentelemetry/api": "1.9.0",
48
48
  "@opentelemetry/core": "1.30.1",
@@ -108,5 +108,5 @@
108
108
  "publishConfig": {
109
109
  "access": "public"
110
110
  },
111
- "gitHead": "ef38e3e5bfe2db2f78a3faa0df19b725cfd2c9f4"
111
+ "gitHead": "5cdfb268a33cc83c22f6e923186dbe61d0b4eb03"
112
112
  }