@zenstackhq/cli 3.0.0-alpha.26 → 3.0.0-alpha.28

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.
@@ -40,14 +40,14 @@ describe('CLI validate command test', () => {
40
40
  const workDir = createProject(validModel);
41
41
 
42
42
  // Should not throw an error
43
- expect(() => runCli('validate', workDir)).not.toThrow();
43
+ expect(() => runCli('check', workDir)).not.toThrow();
44
44
  });
45
45
 
46
46
  it('should fail validation for invalid schema', () => {
47
47
  const workDir = createProject(invalidModel);
48
48
 
49
49
  // Should throw an error due to validation failure
50
- expect(() => runCli('validate', workDir)).toThrow();
50
+ expect(() => runCli('check', workDir)).toThrow();
51
51
  });
52
52
 
53
53
  it('should respect custom schema location', () => {
@@ -55,14 +55,14 @@ describe('CLI validate command test', () => {
55
55
  fs.renameSync(path.join(workDir, 'zenstack/schema.zmodel'), path.join(workDir, 'zenstack/custom.zmodel'));
56
56
 
57
57
  // Should not throw an error when using custom schema path
58
- expect(() => runCli('validate --schema ./zenstack/custom.zmodel', workDir)).not.toThrow();
58
+ expect(() => runCli('check --schema ./zenstack/custom.zmodel', workDir)).not.toThrow();
59
59
  });
60
60
 
61
61
  it('should fail when schema file does not exist', () => {
62
62
  const workDir = createProject(validModel);
63
63
 
64
64
  // Should throw an error when schema file doesn't exist
65
- expect(() => runCli('validate --schema ./nonexistent.zmodel', workDir)).toThrow();
65
+ expect(() => runCli('check --schema ./nonexistent.zmodel', workDir)).toThrow();
66
66
  });
67
67
 
68
68
  it('should respect package.json config', () => {
@@ -78,7 +78,7 @@ describe('CLI validate command test', () => {
78
78
  fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
79
79
 
80
80
  // Should not throw an error when using package.json config
81
- expect(() => runCli('validate', workDir)).not.toThrow();
81
+ expect(() => runCli('check', workDir)).not.toThrow();
82
82
  });
83
83
 
84
84
  it('should validate schema with syntax errors', () => {
@@ -96,6 +96,6 @@ model User {
96
96
  const workDir = createProject(modelWithSyntaxError, false);
97
97
 
98
98
  // Should throw an error due to syntax error
99
- expect(() => runCli('validate', workDir)).toThrow();
99
+ expect(() => runCli('check', workDir)).toThrow();
100
100
  });
101
101
  });
@@ -30,18 +30,6 @@ describe('CLI generate command test', () => {
30
30
  expect(fs.existsSync(path.join(workDir, 'zenstack/schema.ts'))).toBe(true);
31
31
  });
32
32
 
33
- it('should respect save prisma schema option', () => {
34
- const workDir = createProject(model);
35
- runCli('generate --save-prisma-schema', workDir);
36
- expect(fs.existsSync(path.join(workDir, 'zenstack/schema.prisma'))).toBe(true);
37
- });
38
-
39
- it('should respect save prisma schema custom path option', () => {
40
- const workDir = createProject(model);
41
- runCli('generate --save-prisma-schema "../prisma/schema.prisma"', workDir);
42
- expect(fs.existsSync(path.join(workDir, 'prisma/schema.prisma'))).toBe(true);
43
- });
44
-
45
33
  it('should respect package.json config', () => {
46
34
  const workDir = createProject(model);
47
35
  fs.mkdirSync(path.join(workDir, 'foo'));
@@ -0,0 +1,50 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { createProject, runCli } from '../utils';
5
+ import { execSync } from 'node:child_process';
6
+
7
+ describe('Custom plugins tests', () => {
8
+ it('runs custom plugin generator', () => {
9
+ const workDir = createProject(`
10
+ plugin custom {
11
+ provider = '../my-plugin.js'
12
+ output = '../custom-output'
13
+ }
14
+
15
+ model User {
16
+ id String @id @default(cuid())
17
+ }
18
+ `);
19
+
20
+ fs.writeFileSync(
21
+ path.join(workDir, 'my-plugin.ts'),
22
+ `
23
+ import type { CliPlugin } from '@zenstackhq/sdk';
24
+ import fs from 'node:fs';
25
+ import path from 'node:path';
26
+
27
+ const plugin: CliPlugin = {
28
+ name: 'Custom Generator',
29
+ statusText: 'Generating foo.txt',
30
+ async generate({ model, defaultOutputPath, pluginOptions }) {
31
+ let outDir = defaultOutputPath;
32
+ if (typeof pluginOptions['output'] === 'string') {
33
+ outDir = path.resolve(defaultOutputPath, pluginOptions['output']);
34
+ if (!fs.existsSync(outDir)) {
35
+ fs.mkdirSync(outDir, { recursive: true });
36
+ }
37
+ }
38
+ fs.writeFileSync(path.join(outDir, 'foo.txt'), 'from my plugin');
39
+ },
40
+ };
41
+
42
+ export default plugin;
43
+ `,
44
+ );
45
+
46
+ execSync('npx tsc', { cwd: workDir });
47
+ runCli('generate', workDir);
48
+ expect(fs.existsSync(path.join(workDir, 'custom-output/foo.txt'))).toBe(true);
49
+ });
50
+ });
@@ -0,0 +1,60 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { createProject, runCli } from '../utils';
5
+
6
+ describe('Core plugins tests', () => {
7
+ it('can automatically generate a TypeScript schema with default output', () => {
8
+ const workDir = createProject(`
9
+ model User {
10
+ id String @id @default(cuid())
11
+ }
12
+ `);
13
+ runCli('generate', workDir);
14
+ expect(fs.existsSync(path.join(workDir, 'zenstack/schema.ts'))).toBe(true);
15
+ });
16
+
17
+ it('can automatically generate a TypeScript schema with custom output', () => {
18
+ const workDir = createProject(`
19
+ plugin typescript {
20
+ provider = '@core/typescript'
21
+ output = '../generated-schema'
22
+ }
23
+
24
+ model User {
25
+ id String @id @default(cuid())
26
+ }
27
+ `);
28
+ runCli('generate', workDir);
29
+ expect(fs.existsSync(path.join(workDir, 'generated-schema/schema.ts'))).toBe(true);
30
+ });
31
+
32
+ it('can generate a Prisma schema with default output', () => {
33
+ const workDir = createProject(`
34
+ plugin prisma {
35
+ provider = '@core/prisma'
36
+ }
37
+
38
+ model User {
39
+ id String @id @default(cuid())
40
+ }
41
+ `);
42
+ runCli('generate', workDir);
43
+ expect(fs.existsSync(path.join(workDir, 'zenstack/schema.prisma'))).toBe(true);
44
+ });
45
+
46
+ it('can generate a Prisma schema with custom output', () => {
47
+ const workDir = createProject(`
48
+ plugin prisma {
49
+ provider = '@core/prisma'
50
+ output = './prisma'
51
+ }
52
+
53
+ model User {
54
+ id String @id @default(cuid())
55
+ }
56
+ `);
57
+ runCli('generate', workDir);
58
+ expect(fs.existsSync(path.join(workDir, 'zenstack/prisma/schema.prisma'))).toBe(true);
59
+ });
60
+ });
package/tsconfig.json CHANGED
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "extends": "@zenstackhq/typescript-config/base.json",
3
- "compilerOptions": {
4
- "baseUrl": "."
5
- },
6
3
  "include": ["src/**/*.ts"]
7
4
  }