import chalk from "chalk" import { Argv, CommandModule } from "yargs" import { loadConfigFile } from "../helpers/config" import { Creator } from "../migrator/creator" const command = "create " const describe = "Create SQLV migration files." export class CreateCommand implements CommandModule { public command = command public describe = chalk.gray(describe) public builder(options: Argv): Argv { return options .usage(`${chalk.bold("Usage: ")}$0 ${chalk.bold(command)} ${describe}`) .positional("name", { describe: chalk.gray("migration name"), }) .example(chalk.cyan("$ sqlv create create_users"), "") .example(chalk.cyan("$ sqlv create add_age_to_users"), "") } public async handler(options: any): Promise { const config = loadConfigFile(options.config) const { filenames } = await new Creator(config.migrations).create(options.name) console.log(chalk.gray(`generate up : ${filenames.up}`)) console.log(chalk.gray(`generate down : ${filenames.down}`)) console.log(chalk.green(`migration files are generated!`)) } }