bun-mariadb/dist/commands/typedef.js

30 lines
1.2 KiB
JavaScript

import { Command } from "commander";
import dbSchemaToTypeDef from "../lib/mariadb/schema-to-typedef";
import path from "path";
import grabDirNames from "../data/grab-dir-names";
import appendDefaultFieldsToDbSchema from "../utils/append-default-fields-to-db-schema";
import chalk from "chalk";
export default function () {
return new Command("typedef")
.description("Generate TypeScript type definitions from the schema")
.action(async () => {
console.log(`Creating Type Definition From DB Schema ...`);
const config = global.CONFIG;
const dbSchema = global.DB_SCHEMA;
const { ROOT_DIR } = grabDirNames();
const finaldbSchema = appendDefaultFieldsToDbSchema({ dbSchema });
if (!config.typedef_file_path) {
console.error(`\`typedef_file_path\` is required in bun-mariadb.config.ts to generate types.`);
process.exit(1);
}
const out_file = path.resolve(ROOT_DIR, config.typedef_file_path);
dbSchemaToTypeDef({
dbSchema: finaldbSchema,
dst_file: out_file,
config,
});
console.log(`${chalk.bold(chalk.green(`Typedef gen success!`))}`);
process.exit(0);
});
}