fix: generate should take output

This commit is contained in:
Bereket Engida
2024-09-30 18:40:21 +03:00
parent 5493051533
commit d633ac7e97
2 changed files with 5 additions and 5 deletions

View File

@@ -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;

View File

@@ -20,14 +20,14 @@ export const generate = new Command("generate")
"--config <config>",
"the path to the configuration file. defaults to the first configuration file found.",
)
.option("--out <output>", "the file to output to the generated schema")
.option("--output <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);
});