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S/C,CAAC;IACE,CAAC;IAEL,6BAAC;AAAD,CArFA,AAqFC,IAAA;AArFY,wDAAsB","file":"MigrationCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nconst chalk = require(\"chalk\");\n\n/**\n * Creates a new migration file.\n */\nexport class MigrationCreateCommand implements yargs.CommandModule {\n\n    command = \"migration:create\";\n    describe = \"Creates a new migration file.\";\n    aliases = \"migrations:create\";\n\n    builder(args: yargs.Argv) {\n        return args\n            .option(\"c\", {\n                alias: \"connection\",\n                default: \"default\",\n                describe: \"Name of the connection on which run a query.\"\n            })\n            .option(\"n\", {\n                alias: \"name\",\n                describe: \"Name of the migration class.\",\n                demand: true\n            })\n            .option(\"d\", {\n                alias: \"dir\",\n                describe: \"Directory where migration should be created.\"\n            })\n            .option(\"f\", {\n                alias: \"config\",\n                default: \"ormconfig\",\n                describe: \"Name of the file with connection configuration.\"\n            });\n    }\n\n    async handler(args: yargs.Arguments) {\n        if (args._[0] === \"migrations:create\") {\n            console.log(\"'migrations:create' is deprecated, please use 'migration:create' instead\");\n        }\n\n        try {\n            const timestamp = new Date().getTime();\n            const fileContent = MigrationCreateCommand.getTemplate(args.name as any, timestamp);\n            const filename = timestamp + \"-\" + args.name + \".ts\";\n            let directory = args.dir;\n\n            // if directory is not set then try to open tsconfig and find default path there\n            if (!directory) {\n                try {\n                    const connectionOptionsReader = new ConnectionOptionsReader({\n                        root: process.cwd(),\n                        configName: args.config as any\n                    });\n                    const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n                    directory = connectionOptions.cli ? connectionOptions.cli.migrationsDir : undefined;\n                } catch (err) { }\n            }\n\n            const path = process.cwd() + \"/\" + (directory ? (directory + \"/\") : \"\") + filename;\n            await CommandUtils.createFile(path, fileContent);\n            console.log(`Migration ${chalk.blue(path)} has been generated successfully.`);\n\n        } catch (err) {\n            console.log(chalk.black.bgRed(\"Error during migration creation:\"));\n            console.error(err);\n            process.exit(1);\n        }\n    }\n\n    // -------------------------------------------------------------------------\n    // Protected Static Methods\n    // -------------------------------------------------------------------------\n\n    /**\n     * Gets contents of the migration file.\n     */\n    protected static getTemplate(name: string, timestamp: number): string {\n        return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${camelCase(name, true)}${timestamp} implements MigrationInterface {\n\n    public async up(queryRunner: QueryRunner): Promise<any> {\n    }\n\n    public async down(queryRunner: QueryRunner): Promise<any> {\n    }\n\n}\n`;\n    }\n\n}\n"],"sourceRoot":".."}