@cedarjs/cli 3.0.0-canary.13465 → 3.0.0-canary.13469

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,12 +1,16 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
2
  import { paramCase } from "change-case";
4
3
  import { Listr } from "listr2";
5
4
  import { terminalLink } from "termi-link";
6
5
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
6
+ import { dbReexportsPrismaClient } from "@cedarjs/internal/dist/project";
7
7
  import { getDataMigrationsPath } from "@cedarjs/project-config";
8
8
  import c from "../../../lib/colors.js";
9
- import { getPaths, writeFilesTask } from "../../../lib/index.js";
9
+ import {
10
+ generateTemplate,
11
+ getPaths,
12
+ writeFilesTask
13
+ } from "../../../lib/index.js";
10
14
  import { prepareForRollback } from "../../../lib/rollback.js";
11
15
  import { validateName } from "../helpers.js";
12
16
  import { getYargsDefaults } from "../yargsCommandHelpers.js";
@@ -40,8 +44,12 @@ const files = async ({ name, typescript }) => {
40
44
  getPaths().api.prismaConfig
41
45
  );
42
46
  const outputPath = path.join(dataMigrationsPath, outputFilename);
47
+ const prismaImportSource = dbReexportsPrismaClient() ? "src/lib/db" : "@prisma/client";
43
48
  return {
44
- [outputPath]: fs.readFileSync(TEMPLATE_PATHS[extension]).toString()
49
+ [outputPath]: await generateTemplate(TEMPLATE_PATHS[extension], {
50
+ name,
51
+ prismaImportSource
52
+ })
45
53
  };
46
54
  };
47
55
  const command = "data-migration <name>";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef { import("@prisma/client").PrismaClient } PrismaClient
2
+ * @typedef { import("${prismaImportSource}").PrismaClient } PrismaClient
3
3
  * @param {{db: PrismaClient}} db
4
4
  */
5
5
  export default async ({ db }) => {
@@ -1,4 +1,4 @@
1
- import type { PrismaClient } from '@prisma/client'
1
+ import type { PrismaClient } from '${prismaImportSource}'
2
2
 
3
3
  export default async ({ db }: { db: PrismaClient }) => {
4
4
  // Migration here...
@@ -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 "../../../lib/cedarPluralize.js";
4
5
  import { transformTSToJS } from "../../../lib/index.js";
5
6
  import { getSchema, verifyModelName } from "../../../lib/schemaHelpers.js";
@@ -222,6 +223,7 @@ const files = async ({
222
223
  const componentName = camelcase(pluralize(name));
223
224
  const model = name;
224
225
  const idName = await getIdName(model);
226
+ const prismaImportSource = dbReexportsPrismaClient() ? "src/lib/db" : "@prisma/client";
225
227
  const modelRelations = relations || relationsForModel(await getSchema(model));
226
228
  const serviceFile = await templateForFile({
227
229
  name,
@@ -230,7 +232,12 @@ const files = async ({
230
232
  generator: "service",
231
233
  outputPath: path.join(componentName, componentName + ".ts"),
232
234
  templatePath: "service.ts.template",
233
- templateVars: { relations: modelRelations, idName, ...rest }
235
+ templateVars: {
236
+ relations: modelRelations,
237
+ idName,
238
+ prismaImportSource,
239
+ ...rest
240
+ }
234
241
  });
235
242
  const testFile = await templateForFile({
236
243
  name,
@@ -249,6 +256,7 @@ const files = async ({
249
256
  ),
250
257
  prismaModel: model,
251
258
  idName,
259
+ prismaImportSource,
252
260
  ...rest
253
261
  }
254
262
  });
@@ -265,6 +273,7 @@ const files = async ({
265
273
  prismaModel: model,
266
274
  idName,
267
275
  relations: modelRelations,
276
+ prismaImportSource,
268
277
  ...rest
269
278
  }
270
279
  });
@@ -1,6 +1,8 @@
1
- import type { Prisma, ${prismaModel} } from '@prisma/client'
1
+ <% if (prismaImportSource === 'src/lib/db') { %>import type { ScenarioData } from '@cedarjs/testing/api'
2
2
 
3
- import type { ScenarioData } from '@cedarjs/testing/api'
3
+ import type { Prisma, ${prismaModel} } from '${prismaImportSource}'<% } else { %>import type { Prisma, ${prismaModel} } from '${prismaImportSource}'
4
+
5
+ import type { ScenarioData } from '@cedarjs/testing/api'<% } %>
4
6
 
5
7
  export const standard = defineScenario<Prisma.${prismaModel}CreateArgs>(${stringifiedScenario})
6
8
 
@@ -31,7 +31,7 @@
31
31
  // Not all values can be represented as JSON, like function invocations
32
32
  return jsonString.replace(/"new Uint8Array\(([^)]+)\)"/g, 'new Uint8Array($1)')
33
33
  } %>
34
- <% if (prismaImport) { %>import { Prisma, ${prismaModel} } from '@prisma/client'<% } else { %>import type { ${prismaModel} } from '@prisma/client'<% } %>
34
+ <% if (prismaImport) { %>import { Prisma, ${prismaModel} } from '${prismaImportSource}'<% } else { %>import type { ${prismaModel} } from '${prismaImportSource}'<% } %>
35
35
 
36
36
  import { ${pluralCamelName}<% if (crud) { %>,${singularCamelName}, create${singularPascalName}, update${singularPascalName}, delete${singularPascalName}<% } %> } from './${pluralCamelName}.js'
37
37
  import type { StandardScenario } from './${pluralCamelName}.scenarios.js'
package/dist/lib/test.js CHANGED
@@ -26,6 +26,7 @@ vi.mock("@cedarjs/project-config", async (importOriginal) => {
26
26
  ),
27
27
  dataMigrations: path.join(BASE_PATH, "./api/dataMigrations"),
28
28
  src: path.join(BASE_PATH, "./api/src"),
29
+ lib: path.join(BASE_PATH, "./api/src/lib"),
29
30
  jobs: path.join(BASE_PATH, "./api/src/jobs"),
30
31
  services: path.join(BASE_PATH, "./api/src/services"),
31
32
  directives: path.join(BASE_PATH, "./api/src/directives"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "3.0.0-canary.13465+4edd2ae3e",
3
+ "version": "3.0.0-canary.13469+0a2f4b095",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,15 +34,15 @@
34
34
  "@babel/parser": "7.29.0",
35
35
  "@babel/preset-typescript": "7.28.5",
36
36
  "@babel/runtime-corejs3": "7.29.0",
37
- "@cedarjs/api-server": "3.0.0-canary.13465",
38
- "@cedarjs/cli-helpers": "3.0.0-canary.13465",
39
- "@cedarjs/fastify-web": "3.0.0-canary.13465",
40
- "@cedarjs/internal": "3.0.0-canary.13465",
41
- "@cedarjs/prerender": "3.0.0-canary.13465",
42
- "@cedarjs/project-config": "3.0.0-canary.13465",
43
- "@cedarjs/structure": "3.0.0-canary.13465",
44
- "@cedarjs/telemetry": "3.0.0-canary.13465",
45
- "@cedarjs/web-server": "3.0.0-canary.13465",
37
+ "@cedarjs/api-server": "3.0.0-canary.13469",
38
+ "@cedarjs/cli-helpers": "3.0.0-canary.13469",
39
+ "@cedarjs/fastify-web": "3.0.0-canary.13469",
40
+ "@cedarjs/internal": "3.0.0-canary.13469",
41
+ "@cedarjs/prerender": "3.0.0-canary.13469",
42
+ "@cedarjs/project-config": "3.0.0-canary.13469",
43
+ "@cedarjs/structure": "3.0.0-canary.13469",
44
+ "@cedarjs/telemetry": "3.0.0-canary.13469",
45
+ "@cedarjs/web-server": "3.0.0-canary.13469",
46
46
  "@listr2/prompt-adapter-enquirer": "2.0.16",
47
47
  "@opentelemetry/api": "1.9.0",
48
48
  "@opentelemetry/core": "1.30.1",
@@ -106,5 +106,5 @@
106
106
  "publishConfig": {
107
107
  "access": "public"
108
108
  },
109
- "gitHead": "4edd2ae3ed2cf81559af27caa0411081c4fbcf91"
109
+ "gitHead": "0a2f4b095ba8dc19b7838c99e4f1115e214a4dd0"
110
110
  }