@deessejs/cli 0.6.9 → 0.6.10

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.
@@ -3,12 +3,15 @@
3
3
  *
4
4
  * Since auth is mandatory in DeesseJS, db:generate and db:push
5
5
  * must also generate the auth schema tables.
6
+ *
7
+ * Uses the programmatic API (generateDrizzleSchema from auth/api)
8
+ * instead of spawning npx auth@latest generate.
6
9
  */
7
10
  /**
8
- * Generate the better-auth schema using the CLI
11
+ * Generate the better-auth schema using the programmatic API
9
12
  *
10
- * This runs `npx auth generate --adapter drizzle --dialect postgresql`
11
- * to generate the auth tables (user, session, account, verification).
13
+ * This calls generateDrizzleSchema() directly to generate the auth tables
14
+ * (user, session, account, verification) without needing a config file.
12
15
  */
13
16
  export declare function generateAuthSchema(cwd?: string): Promise<void>;
14
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"auth-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/db/auth-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBnF;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQpF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAErE"}
1
+ {"version":3,"file":"auth-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/db/auth-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA8DH;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0CnF;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQpF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAErE"}
@@ -3,29 +3,81 @@
3
3
  *
4
4
  * Since auth is mandatory in DeesseJS, db:generate and db:push
5
5
  * must also generate the auth schema tables.
6
+ *
7
+ * Uses the programmatic API (generateDrizzleSchema from auth/api)
8
+ * instead of spawning npx auth@latest generate.
6
9
  */
7
- import { execSync } from 'node:child_process';
8
- import * as fs from 'node:fs/promises';
10
+ import { writeFile, access, mkdir } from 'node:fs/promises';
11
+ import { existsSync } from 'node:fs';
9
12
  import * as path from 'node:path';
10
13
  const AUTH_SCHEMA_OUTPUT = './auth-schema.ts';
14
+ async function generateDrizzleSchemaInternal(
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ opts) {
17
+ // Dynamic import to get the generator
18
+ const { generateDrizzleSchema } = await import('auth/api');
19
+ return generateDrizzleSchema(opts);
20
+ }
21
+ /**
22
+ * Create a mock adapter for schema generation
23
+ */
24
+ function createMockAdapter(dialect) {
25
+ // Map postgresql to pg for drizzle
26
+ const provider = dialect === 'postgresql' ? 'pg' : dialect;
27
+ return {
28
+ id: 'drizzle',
29
+ options: {
30
+ adapterConfig: {
31
+ adapterId: 'drizzle',
32
+ },
33
+ provider,
34
+ },
35
+ };
36
+ }
11
37
  /**
12
- * Generate the better-auth schema using the CLI
38
+ * Ensure a directory exists
39
+ */
40
+ async function ensureDir(dirPath) {
41
+ if (!existsSync(dirPath)) {
42
+ await mkdir(dirPath, { recursive: true });
43
+ }
44
+ }
45
+ /**
46
+ * Generate the better-auth schema using the programmatic API
13
47
  *
14
- * This runs `npx auth generate --adapter drizzle --dialect postgresql`
15
- * to generate the auth tables (user, session, account, verification).
48
+ * This calls generateDrizzleSchema() directly to generate the auth tables
49
+ * (user, session, account, verification) without needing a config file.
16
50
  */
17
51
  export async function generateAuthSchema(cwd = process.cwd()) {
18
52
  const outputPath = path.resolve(cwd, AUTH_SCHEMA_OUTPUT);
19
53
  console.warn('Generating better-auth schema...');
20
54
  try {
21
- execSync(`npx auth@latest generate --adapter drizzle --dialect postgresql --output "${outputPath}" --yes`, {
22
- cwd,
23
- stdio: 'inherit',
55
+ // Create mock adapter for drizzle with postgresql dialect
56
+ const adapter = createMockAdapter('postgresql');
57
+ // Generate the schema using the programmatic API
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ const schema = await generateDrizzleSchemaInternal({
60
+ file: outputPath,
61
+ adapter,
62
+ options: {
63
+ database: {},
64
+ plugins: [],
65
+ },
24
66
  });
67
+ if (!schema.code) {
68
+ console.warn('Auth schema is already up to date.');
69
+ return;
70
+ }
71
+ // Ensure parent directory exists
72
+ const parentDir = path.dirname(outputPath);
73
+ await ensureDir(parentDir);
74
+ // Write the generated schema to file
75
+ await writeFile(outputPath, schema.code, 'utf-8');
76
+ console.warn(`Auth schema generated: ${outputPath}`);
25
77
  }
26
78
  catch (error) {
27
79
  if (error.code === 'ENOENT') {
28
- throw new Error('better-auth CLI not found. Please ensure better-auth is installed:\n' +
80
+ throw new Error('better-auth schema generation failed. Please ensure better-auth is installed:\n' +
29
81
  ' npm install better-auth');
30
82
  }
31
83
  throw error;
@@ -37,7 +89,7 @@ export async function generateAuthSchema(cwd = process.cwd()) {
37
89
  export async function authSchemaExists(cwd = process.cwd()) {
38
90
  const outputPath = path.resolve(cwd, AUTH_SCHEMA_OUTPUT);
39
91
  try {
40
- await fs.access(outputPath);
92
+ await access(outputPath);
41
93
  return true;
42
94
  }
43
95
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"auth-schema.js","sourceRoot":"","sources":["../../../src/lib/db/auth-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;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1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/cli",
3
- "version": "0.6.9",
3
+ "version": "0.6.10",
4
4
  "description": "DeesseJS CLI for managing DeesseJS projects",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,6 +34,7 @@
34
34
  "dependencies": {
35
35
  "@better-auth/drizzle-adapter": "^1.0.0",
36
36
  "@clack/prompts": "^0.8.2",
37
+ "auth": "^1.6.0",
37
38
  "better-auth": "^1.0.0",
38
39
  "dotenv": "^17.3.1",
39
40
  "drizzle-orm": "^0.38.0",