From d633ac7e975fcc187137c972738abc605f63e7ab Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Mon, 30 Sep 2024 18:40:21 +0300 Subject: [PATCH] fix: generate should take output --- .../better-auth/src/adapters/drizzle-adapter/index.ts | 2 +- packages/better-auth/src/cli/commands/generate.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/better-auth/src/adapters/drizzle-adapter/index.ts b/packages/better-auth/src/adapters/drizzle-adapter/index.ts index e8f3301217..38659b3d26 100644 --- a/packages/better-auth/src/adapters/drizzle-adapter/index.ts +++ b/packages/better-auth/src/adapters/drizzle-adapter/index.ts @@ -141,7 +141,7 @@ export const drizzleAdapter = ( `; const fileExist = existsSync(filePath); - let fileContent = await fs.readFile(filePath, "utf-8"); + let fileContent = fileExist ? await fs.readFile(filePath, "utf-8") : ""; for (const table in tables) { const tableName = tables[table].tableName; diff --git a/packages/better-auth/src/cli/commands/generate.ts b/packages/better-auth/src/cli/commands/generate.ts index a4a98c5474..8686fe99b0 100644 --- a/packages/better-auth/src/cli/commands/generate.ts +++ b/packages/better-auth/src/cli/commands/generate.ts @@ -20,14 +20,14 @@ export const generate = new Command("generate") "--config ", "the path to the configuration file. defaults to the first configuration file found.", ) - .option("--out ", "the file to output to the generated schema") + .option("--output ", "the file to output to the generated schema") .option("--y", "") .action(async (opts) => { const options = z .object({ cwd: z.string(), config: z.string().optional(), - out: z.string().optional(), + output: z.string().optional(), }) .parse(opts); const cwd = path.resolve(options.cwd); @@ -57,7 +57,7 @@ export const generate = new Command("generate") const spinner = ora("preparing schema...").start(); const { code, fileName, append } = await adapter.createSchema( config, - options.out, + options.output, ); spinner.stop(); if (!code) { @@ -100,7 +100,7 @@ export const generate = new Command("generate") recursive: true, }); } - await fs.writeFile(options.out || path.join(cwd, fileName), code); + await fs.writeFile(options.output || path.join(cwd, fileName), code); logger.success(`🚀 schema was generated successfully!`); process.exit(0); });