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AA;YAE9D,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ;gBAC7B,CAAC,CAAC,sBAAsB,CAAC,qBAAqB,CACxC,QAAQ,EACR,SAAS,CACZ;gBACH,CAAC,CAAC,sBAAsB,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;YAE7D,MAAM,2BAAY,CAAC,UAAU,CACzB,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,EAC1C,WAAW,CACd,CAAA;YACD,OAAO,CAAC,GAAG,CACP,aAAa,eAAK,CAAC,IAAI,CACnB,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAC7C,mCAAmC,CACvC,CAAA;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,6BAAa,CAAC,SAAS,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAA;YAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,2BAA2B;IAC3B,4EAA4E;IAE5E;;OAEG;IACO,MAAM,CAAC,WAAW,CAAC,IAAY,EAAE,SAAiB;QACxD,OAAO;;eAEA,IAAA,uBAAS,EACZ,IAAI,EACJ,IAAI,CACP,GAAG,SAAS;;;;;;;;;CASpB,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,qBAAqB,CAClC,IAAY,EACZ,SAAiB;QAEjB,OAAO;;yBAEU,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS;;;;;;;;;CASzD,CAAA;IACG,CAAC;CACJ;AAvGD,wDAuGC","file":"MigrationCreateCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport { camelCase } from \"../util/StringUtils\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\n\n/**\n * Creates a new migration file.\n */\nexport class MigrationCreateCommand implements yargs.CommandModule {\n command = \"migration:create \"\n describe = \"Creates a new migration file.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"path\", {\n type: \"string\",\n describe: \"Path of the migration file\",\n demandOption: true,\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const inputPath = args.path.startsWith(\"/\")\n ? args.path\n : path.resolve(process.cwd(), args.path)\n const filename = path.basename(inputPath)\n const fullPath =\n path.dirname(inputPath) + \"/\" + timestamp + \"-\" + filename\n\n const fileContent = args.outputJs\n ? MigrationCreateCommand.getJavascriptTemplate(\n filename,\n timestamp,\n )\n : MigrationCreateCommand.getTemplate(filename, timestamp)\n\n await CommandUtils.createFile(\n fullPath + (args.outputJs ? \".js\" : \".ts\"),\n fileContent,\n )\n console.log(\n `Migration ${chalk.blue(\n fullPath + (args.outputJs ? \".js\" : \".ts\"),\n )} has been generated successfully.`,\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration creation:\", 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(\n name,\n true,\n )}${timestamp} implements MigrationInterface {\n\n public async up(queryRunner: QueryRunner): Promise {\n }\n\n public async down(queryRunner: QueryRunner): Promise {\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n ): string {\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${camelCase(name, true)}${timestamp} {\n\n async up(queryRunner) {\n }\n\n async down(queryRunner) {\n }\n\n}\n`\n }\n}\n"],"sourceRoot":".."}