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AiB,GAAG,SAAyD;wBACnF,SAAS,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;;;;;;wBAIpF,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;wBAChE,qBAAM,2BAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAA;;wBAAhD,UAAU,GAAG,SAAmC;wBACtD,IAAI,UAAU,EAAE;4BACZ,MAAM,UAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAiB,CAAC;yBACnD;wBACD,qBAAM,2BAAY,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,EAAA;;wBAAhD,SAAgD,CAAC;wBACjD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,YAAU,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAiC,CAAC,CAAC,CAAC;;;;wBAGtF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;wBAChE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IAED,4EAA4E;IAC5E,2BAA2B;IAC3B,4EAA4E;IAE5E;;OAEG;IACc,+BAAW,GAA5B,UAA6B,IAAY;QACrC,OAAO,kEAGA,IAAI,cAGlB,CAAC;IACE,CAAC;IAEL,0BAAC;AAAD,CA7EA,AA6EC,IAAA;AA7EY,kDAAmB","file":"EntityCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport * as yargs from \"yargs\";\nconst chalk = require(\"chalk\");\n\n/**\n * Generates a new entity.\n */\nexport class EntityCreateCommand implements yargs.CommandModule {\n command = \"entity:create\";\n describe = \"Generates a new entity.\";\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 to run a query\"\n })\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the entity class.\",\n demand: true\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where entity 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 try {\n const fileContent = EntityCreateCommand.getTemplate(args.name as any);\n const filename = 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.entitiesDir : undefined;\n } catch (err) { }\n }\n\n const path = process.cwd() + \"/\" + (directory ? (directory + \"/\") : \"\") + filename;\n const fileExists = await CommandUtils.fileExists(path);\n if (fileExists) {\n throw `File ${chalk.blue(path)} already exists`;\n }\n await CommandUtils.createFile(path, fileContent);\n console.log(chalk.green(`Entity ${chalk.blue(path)} has been created successfully.`));\n\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during entity 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 entity file.\n */\n protected static getTemplate(name: string): string {\n return `import {Entity} from \"typeorm\";\n\n@Entity()\nexport class ${name} {\n\n}\n`;\n }\n\n}\n"],"sourceRoot":".."}
|