UNPKG

mikro-orm-interactive-generator

Version:

MikroORM + knexJS interactive migration generator

37 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const commander_1 = require("commander"); const inquirer = (0, tslib_1.__importStar)(require("inquirer")); const command_bus_1 = require("../src/bus/command-bus"); const commands_1 = require("../src/command/commands"); const create_migration_file_handler_1 = require("../src/handler/create-migration-file.handler"); const create_migration_definition_question_flow_1 = require("../src/flow/create-migration-definition.question-flow"); const create_migration_file_command_1 = require("../src/command/create-migration-file.command"); const mysql_types_1 = require("../src/type/mysql.types"); const bootstrap = () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { // 2 base arguments, path to node and path to this script, so therefore there are no flag arguments if (process.argv.length === 2) { commander_1.program.help(); return; } const CLICommand = new commander_1.Command(); CLICommand.option('-c --create', 'Create new migration with current timestamp'); CLICommand.parse(process.argv); inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')); const commandBus = new command_bus_1.CommandBus([new create_migration_file_handler_1.CreateMigrationFileHandler()]); for (const CLICommandKey of Object.keys(CLICommand.opts())) { switch (CLICommandKey) { case commands_1.RegisteredCommands.create: //TODO: Support more types based on some kind of config const flowResult = yield (new create_migration_definition_question_flow_1.CreateMigrationDefinitionQuestionFlow).execute({ types: mysql_types_1.MySQLType.types, autoincrementKey: mysql_types_1.MySQLType.autoincrementKey }); const createMigrationFileCommand = new create_migration_file_command_1.CreateMigrationFileCommand(`Migration${new Date().getTime().toString()}`, flowResult.tableName, flowResult.fields); yield commandBus.dispatch(createMigrationFileCommand); } } }); bootstrap(); //# sourceMappingURL=migration.js.map