typeorm 0.2.42-dev.f224f24 → 0.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/browser/common/DeepPartial.d.ts +3 -3
  2. package/browser/common/DeepPartial.js.map +1 -1
  3. package/browser/connection/BaseConnectionOptions.js.map +1 -1
  4. package/browser/connection/Connection.js +33 -24
  5. package/browser/connection/Connection.js.map +1 -1
  6. package/browser/connection/ConnectionOptionsReader.js +3 -1
  7. package/browser/connection/ConnectionOptionsReader.js.map +1 -1
  8. package/browser/decorator/listeners/AfterRecover.d.ts +4 -0
  9. package/browser/decorator/listeners/AfterRecover.js +16 -0
  10. package/browser/decorator/listeners/AfterRecover.js.map +1 -0
  11. package/browser/decorator/listeners/AfterSoftRemove.d.ts +4 -0
  12. package/browser/decorator/listeners/AfterSoftRemove.js +16 -0
  13. package/browser/decorator/listeners/AfterSoftRemove.js.map +1 -0
  14. package/browser/decorator/listeners/BeforeRecover.d.ts +4 -0
  15. package/browser/decorator/listeners/BeforeRecover.js +16 -0
  16. package/browser/decorator/listeners/BeforeRecover.js.map +1 -0
  17. package/browser/decorator/listeners/BeforeSoftRemove.d.ts +4 -0
  18. package/browser/decorator/listeners/BeforeSoftRemove.js +16 -0
  19. package/browser/decorator/listeners/BeforeSoftRemove.js.map +1 -0
  20. package/browser/driver/aurora-data-api/AuroraDataApiQueryRunner.js +1 -1
  21. package/browser/driver/aurora-data-api/AuroraDataApiQueryRunner.js.map +1 -1
  22. package/browser/driver/better-sqlite3/BetterSqlite3Driver.d.ts +14 -1
  23. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +87 -4
  24. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  25. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.d.ts +10 -0
  26. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js +64 -1
  27. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
  28. package/browser/driver/capacitor/CapacitorQueryRunner.d.ts +8 -0
  29. package/browser/driver/capacitor/CapacitorQueryRunner.js +30 -0
  30. package/browser/driver/capacitor/CapacitorQueryRunner.js.map +1 -1
  31. package/browser/driver/cordova/CordovaQueryRunner.d.ts +8 -0
  32. package/browser/driver/cordova/CordovaQueryRunner.js +30 -0
  33. package/browser/driver/cordova/CordovaQueryRunner.js.map +1 -1
  34. package/browser/driver/expo/ExpoQueryRunner.d.ts +8 -0
  35. package/browser/driver/expo/ExpoQueryRunner.js +30 -0
  36. package/browser/driver/expo/ExpoQueryRunner.js.map +1 -1
  37. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +1 -1
  38. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  39. package/browser/driver/mongodb/MongoQueryRunner.d.ts +8 -0
  40. package/browser/driver/mongodb/MongoQueryRunner.js +20 -0
  41. package/browser/driver/mongodb/MongoQueryRunner.js.map +1 -1
  42. package/browser/driver/nativescript/NativescriptQueryRunner.d.ts +8 -0
  43. package/browser/driver/nativescript/NativescriptQueryRunner.js +30 -0
  44. package/browser/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
  45. package/browser/driver/react-native/ReactNativeQueryRunner.d.ts +8 -0
  46. package/browser/driver/react-native/ReactNativeQueryRunner.js +30 -0
  47. package/browser/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
  48. package/browser/driver/sqlite/SqliteDriver.d.ts +13 -0
  49. package/browser/driver/sqlite/SqliteDriver.js +84 -1
  50. package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
  51. package/browser/driver/sqlite/SqliteQueryRunner.d.ts +8 -0
  52. package/browser/driver/sqlite/SqliteQueryRunner.js +30 -0
  53. package/browser/driver/sqlite/SqliteQueryRunner.js.map +1 -1
  54. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +13 -0
  55. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +25 -2
  56. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  57. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.d.ts +11 -1
  58. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +118 -57
  59. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  60. package/browser/driver/sqljs/SqljsQueryRunner.d.ts +8 -0
  61. package/browser/driver/sqljs/SqljsQueryRunner.js +30 -0
  62. package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  63. package/browser/entity-manager/EntityManager.js +1 -11
  64. package/browser/entity-manager/EntityManager.js.map +1 -1
  65. package/browser/entity-manager/MongoEntityManager.d.ts +2 -0
  66. package/browser/entity-manager/MongoEntityManager.js +35 -4
  67. package/browser/entity-manager/MongoEntityManager.js.map +1 -1
  68. package/browser/index.d.ts +4 -0
  69. package/browser/index.js +4 -0
  70. package/browser/index.js.map +1 -1
  71. package/browser/metadata/EntityMetadata.d.ts +16 -0
  72. package/browser/metadata/EntityMetadata.js +16 -0
  73. package/browser/metadata/EntityMetadata.js.map +1 -1
  74. package/browser/metadata/types/EventListenerTypes.d.ts +5 -1
  75. package/browser/metadata/types/EventListenerTypes.js +4 -0
  76. package/browser/metadata/types/EventListenerTypes.js.map +1 -1
  77. package/browser/metadata-builder/EntityMetadataBuilder.js +4 -0
  78. package/browser/metadata-builder/EntityMetadataBuilder.js.map +1 -1
  79. package/browser/metadata-builder/EntityMetadataValidator.js +1 -1
  80. package/browser/metadata-builder/EntityMetadataValidator.js.map +1 -1
  81. package/browser/migration/MigrationExecutor.js +37 -25
  82. package/browser/migration/MigrationExecutor.js.map +1 -1
  83. package/browser/persistence/SubjectExecutor.d.ts +4 -2
  84. package/browser/persistence/SubjectExecutor.js +105 -13
  85. package/browser/persistence/SubjectExecutor.js.map +1 -1
  86. package/browser/persistence/tree/MaterializedPathSubjectExecutor.js +1 -1
  87. package/browser/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
  88. package/browser/platform/PlatformTools.d.ts +1 -0
  89. package/browser/platform/PlatformTools.js +5 -0
  90. package/browser/platform/PlatformTools.js.map +1 -1
  91. package/browser/query-builder/InsertQueryBuilder.js +11 -2
  92. package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
  93. package/browser/query-builder/SoftDeleteQueryBuilder.js +44 -30
  94. package/browser/query-builder/SoftDeleteQueryBuilder.js.map +1 -1
  95. package/browser/query-builder/relation-id/RelationIdLoader.js +9 -9
  96. package/browser/query-builder/relation-id/RelationIdLoader.js.map +1 -1
  97. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.d.ts +13 -0
  98. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +94 -50
  99. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  100. package/browser/query-runner/BaseQueryRunner.d.ts +8 -0
  101. package/browser/query-runner/BaseQueryRunner.js +20 -0
  102. package/browser/query-runner/BaseQueryRunner.js.map +1 -1
  103. package/browser/query-runner/QueryRunner.d.ts +8 -0
  104. package/browser/query-runner/QueryRunner.js.map +1 -1
  105. package/browser/repository/TreeRepository.js +2 -1
  106. package/browser/repository/TreeRepository.js.map +1 -1
  107. package/browser/schema-builder/RdbmsSchemaBuilder.js +36 -30
  108. package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  109. package/browser/subscriber/Broadcaster.d.ts +40 -0
  110. package/browser/subscriber/Broadcaster.js +191 -31
  111. package/browser/subscriber/Broadcaster.js.map +1 -1
  112. package/browser/subscriber/EntitySubscriberInterface.d.ts +18 -0
  113. package/browser/subscriber/EntitySubscriberInterface.js.map +1 -1
  114. package/browser/subscriber/event/RecoverEvent.d.ts +6 -0
  115. package/browser/subscriber/event/RecoverEvent.js +3 -0
  116. package/browser/subscriber/event/RecoverEvent.js.map +1 -0
  117. package/browser/subscriber/event/SoftRemoveEvent.d.ts +6 -0
  118. package/browser/subscriber/event/SoftRemoveEvent.js +3 -0
  119. package/browser/subscriber/event/SoftRemoveEvent.js.map +1 -0
  120. package/browser/util/PathUtils.d.ts +10 -0
  121. package/browser/util/PathUtils.js +28 -0
  122. package/browser/util/PathUtils.js.map +1 -0
  123. package/browser/util/RandomGenerator.d.ts +0 -4
  124. package/browser/util/RandomGenerator.js +0 -9
  125. package/browser/util/RandomGenerator.js.map +1 -1
  126. package/cli.js +0 -0
  127. package/commands/CacheClearCommand.js +3 -3
  128. package/commands/CacheClearCommand.js.map +1 -1
  129. package/commands/EntityCreateCommand.js +2 -2
  130. package/commands/EntityCreateCommand.js.map +1 -1
  131. package/commands/InitCommand.js +2 -2
  132. package/commands/InitCommand.js.map +1 -1
  133. package/commands/MigrationCreateCommand.js +2 -2
  134. package/commands/MigrationCreateCommand.js.map +1 -1
  135. package/commands/MigrationGenerateCommand.js +2 -2
  136. package/commands/MigrationGenerateCommand.js.map +1 -1
  137. package/commands/MigrationRevertCommand.js +2 -3
  138. package/commands/MigrationRevertCommand.js.map +1 -1
  139. package/commands/MigrationRunCommand.js +2 -3
  140. package/commands/MigrationRunCommand.js.map +1 -1
  141. package/commands/MigrationShowCommand.js +5 -7
  142. package/commands/MigrationShowCommand.js.map +1 -1
  143. package/commands/QueryCommand.js +1 -2
  144. package/commands/QueryCommand.js.map +1 -1
  145. package/commands/SchemaDropCommand.js +2 -2
  146. package/commands/SchemaDropCommand.js.map +1 -1
  147. package/commands/SchemaLogCommand.js +2 -2
  148. package/commands/SchemaLogCommand.js.map +1 -1
  149. package/commands/SchemaSyncCommand.js +2 -2
  150. package/commands/SchemaSyncCommand.js.map +1 -1
  151. package/commands/SubscriberCreateCommand.js +3 -3
  152. package/commands/SubscriberCreateCommand.js.map +1 -1
  153. package/common/DeepPartial.d.ts +3 -3
  154. package/common/DeepPartial.js.map +1 -1
  155. package/connection/BaseConnectionOptions.js.map +1 -1
  156. package/connection/Connection.js +33 -24
  157. package/connection/Connection.js.map +1 -1
  158. package/connection/ConnectionOptionsReader.js +3 -1
  159. package/connection/ConnectionOptionsReader.js.map +1 -1
  160. package/decorator/listeners/AfterRecover.d.ts +4 -0
  161. package/decorator/listeners/AfterRecover.js +20 -0
  162. package/decorator/listeners/AfterRecover.js.map +1 -0
  163. package/decorator/listeners/AfterSoftRemove.d.ts +4 -0
  164. package/decorator/listeners/AfterSoftRemove.js +20 -0
  165. package/decorator/listeners/AfterSoftRemove.js.map +1 -0
  166. package/decorator/listeners/BeforeRecover.d.ts +4 -0
  167. package/decorator/listeners/BeforeRecover.js +20 -0
  168. package/decorator/listeners/BeforeRecover.js.map +1 -0
  169. package/decorator/listeners/BeforeSoftRemove.d.ts +4 -0
  170. package/decorator/listeners/BeforeSoftRemove.js +20 -0
  171. package/decorator/listeners/BeforeSoftRemove.js.map +1 -0
  172. package/driver/aurora-data-api/AuroraDataApiQueryRunner.js +1 -1
  173. package/driver/aurora-data-api/AuroraDataApiQueryRunner.js.map +1 -1
  174. package/driver/better-sqlite3/BetterSqlite3Driver.d.ts +14 -1
  175. package/driver/better-sqlite3/BetterSqlite3Driver.js +86 -3
  176. package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  177. package/driver/better-sqlite3/BetterSqlite3QueryRunner.d.ts +10 -0
  178. package/driver/better-sqlite3/BetterSqlite3QueryRunner.js +63 -0
  179. package/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
  180. package/driver/capacitor/CapacitorQueryRunner.d.ts +8 -0
  181. package/driver/capacitor/CapacitorQueryRunner.js +30 -0
  182. package/driver/capacitor/CapacitorQueryRunner.js.map +1 -1
  183. package/driver/cordova/CordovaQueryRunner.d.ts +8 -0
  184. package/driver/cordova/CordovaQueryRunner.js +30 -0
  185. package/driver/cordova/CordovaQueryRunner.js.map +1 -1
  186. package/driver/expo/ExpoQueryRunner.d.ts +8 -0
  187. package/driver/expo/ExpoQueryRunner.js +30 -0
  188. package/driver/expo/ExpoQueryRunner.js.map +1 -1
  189. package/driver/mongodb/MongoConnectionOptions.d.ts +1 -1
  190. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  191. package/driver/mongodb/MongoQueryRunner.d.ts +8 -0
  192. package/driver/mongodb/MongoQueryRunner.js +20 -0
  193. package/driver/mongodb/MongoQueryRunner.js.map +1 -1
  194. package/driver/nativescript/NativescriptQueryRunner.d.ts +8 -0
  195. package/driver/nativescript/NativescriptQueryRunner.js +30 -0
  196. package/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
  197. package/driver/react-native/ReactNativeQueryRunner.d.ts +8 -0
  198. package/driver/react-native/ReactNativeQueryRunner.js +30 -0
  199. package/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
  200. package/driver/sqlite/SqliteDriver.d.ts +13 -0
  201. package/driver/sqlite/SqliteDriver.js +83 -0
  202. package/driver/sqlite/SqliteDriver.js.map +1 -1
  203. package/driver/sqlite/SqliteQueryRunner.d.ts +8 -0
  204. package/driver/sqlite/SqliteQueryRunner.js +30 -0
  205. package/driver/sqlite/SqliteQueryRunner.js.map +1 -1
  206. package/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +13 -0
  207. package/driver/sqlite-abstract/AbstractSqliteDriver.js +25 -2
  208. package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  209. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.d.ts +11 -1
  210. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +118 -57
  211. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  212. package/driver/sqljs/SqljsQueryRunner.d.ts +8 -0
  213. package/driver/sqljs/SqljsQueryRunner.js +30 -0
  214. package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  215. package/entity-manager/EntityManager.js +1 -11
  216. package/entity-manager/EntityManager.js.map +1 -1
  217. package/entity-manager/MongoEntityManager.d.ts +2 -0
  218. package/entity-manager/MongoEntityManager.js +35 -4
  219. package/entity-manager/MongoEntityManager.js.map +1 -1
  220. package/index.d.ts +4 -0
  221. package/index.js +4 -0
  222. package/index.js.map +1 -1
  223. package/index.mjs +8 -0
  224. package/metadata/EntityMetadata.d.ts +16 -0
  225. package/metadata/EntityMetadata.js +16 -0
  226. package/metadata/EntityMetadata.js.map +1 -1
  227. package/metadata/types/EventListenerTypes.d.ts +5 -1
  228. package/metadata/types/EventListenerTypes.js +4 -0
  229. package/metadata/types/EventListenerTypes.js.map +1 -1
  230. package/metadata-builder/EntityMetadataBuilder.js +4 -0
  231. package/metadata-builder/EntityMetadataBuilder.js.map +1 -1
  232. package/metadata-builder/EntityMetadataValidator.js +1 -1
  233. package/metadata-builder/EntityMetadataValidator.js.map +1 -1
  234. package/migration/MigrationExecutor.js +37 -25
  235. package/migration/MigrationExecutor.js.map +1 -1
  236. package/package.json +248 -1
  237. package/persistence/SubjectExecutor.d.ts +4 -2
  238. package/persistence/SubjectExecutor.js +105 -13
  239. package/persistence/SubjectExecutor.js.map +1 -1
  240. package/persistence/tree/MaterializedPathSubjectExecutor.js +1 -1
  241. package/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
  242. package/platform/PlatformTools.d.ts +1 -0
  243. package/platform/PlatformTools.js +5 -0
  244. package/platform/PlatformTools.js.map +1 -1
  245. package/query-builder/InsertQueryBuilder.js +11 -2
  246. package/query-builder/InsertQueryBuilder.js.map +1 -1
  247. package/query-builder/SoftDeleteQueryBuilder.js +44 -30
  248. package/query-builder/SoftDeleteQueryBuilder.js.map +1 -1
  249. package/query-builder/relation-id/RelationIdLoader.js +9 -9
  250. package/query-builder/relation-id/RelationIdLoader.js.map +1 -1
  251. package/query-builder/transformer/RawSqlResultsToEntityTransformer.d.ts +13 -0
  252. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +94 -50
  253. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  254. package/query-runner/BaseQueryRunner.d.ts +8 -0
  255. package/query-runner/BaseQueryRunner.js +20 -0
  256. package/query-runner/BaseQueryRunner.js.map +1 -1
  257. package/query-runner/QueryRunner.d.ts +8 -0
  258. package/query-runner/QueryRunner.js.map +1 -1
  259. package/repository/TreeRepository.js +2 -1
  260. package/repository/TreeRepository.js.map +1 -1
  261. package/schema-builder/RdbmsSchemaBuilder.js +36 -30
  262. package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  263. package/subscriber/Broadcaster.d.ts +40 -0
  264. package/subscriber/Broadcaster.js +191 -31
  265. package/subscriber/Broadcaster.js.map +1 -1
  266. package/subscriber/EntitySubscriberInterface.d.ts +18 -0
  267. package/subscriber/EntitySubscriberInterface.js.map +1 -1
  268. package/subscriber/event/RecoverEvent.d.ts +6 -0
  269. package/subscriber/event/RecoverEvent.js +4 -0
  270. package/subscriber/event/RecoverEvent.js.map +1 -0
  271. package/subscriber/event/SoftRemoveEvent.d.ts +6 -0
  272. package/subscriber/event/SoftRemoveEvent.js +4 -0
  273. package/subscriber/event/SoftRemoveEvent.js.map +1 -0
  274. package/typeorm-class-transformer-shim.js +20 -0
  275. package/typeorm-model-shim.js +20 -0
  276. package/util/PathUtils.d.ts +10 -0
  277. package/util/PathUtils.js +34 -0
  278. package/util/PathUtils.js.map +1 -0
  279. package/util/RandomGenerator.d.ts +0 -4
  280. package/util/RandomGenerator.js +0 -9
  281. package/util/RandomGenerator.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/util/RandomGenerator.ts"],"names":[],"mappings":"AAAA;IAAA;IA2JA,CAAC;IAzJG;;;;;;;;;;;OAWG;IACI,oBAAI,GAAX,UAAY,GAAW;QAEnB,IAAI,QAAQ,GAAG,UAAS,CAAM,EAAE,CAAM;YAClC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;YACrC,OAAO,EAAE,CAAC;QACd,CAAC,CAAC;QAEF,IAAI,OAAO,GAAG,UAAS,GAAQ;YAC3B,IAAI,GAAG,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,CAAC;YACN,IAAI,CAAC,CAAC;YAEN,KAAK,C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AAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;SAC/B;QAED,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,qBAAK,GAAZ;QACI,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAC,CAAC;YAC7D,IAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;YACtE,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC;IAEL,sBAAC;AAAD,CA3JA,AA2JC,IAAA","file":"RandomGenerator.js","sourcesContent":["export class RandomGenerator {\n\n /**\n * discuss at: http://locutus.io/php/sha1/\n * original by: Webtoolkit.info (http://www.webtoolkit.info/)\n * improved by: Michael White (http://getsprink.com)\n * improved by: Kevin van Zonneveld (http://kvz.io)\n * input by: Brett Zamir (http://brett-zamir.me)\n * note 1: Keep in mind that in accordance with PHP, the whole string is buffered and then\n * note 1: hashed. If available, we'd recommend using Node's native crypto modules directly\n * note 1: in a steaming fashion for faster and more efficient hashing\n * example 1: sha1('Kevin van Zonneveld')\n * returns 1: '54916d2e62f65b3afa6e192e6a601cdbe5cb5897'\n */\n static sha1(str: string) {\n\n let _rotLeft = function(n: any, s: any) {\n let t4 = (n << s) | (n >>> (32 - s));\n return t4;\n };\n\n let _cvtHex = function(val: any) {\n let str = \"\";\n let i;\n let v;\n\n for (i = 7; i >= 0; i--) {\n v = (val >>> (i * 4)) & 0x0f;\n str += v.toString(16);\n }\n return str;\n };\n\n let blockstart;\n let i, j;\n let W = new Array(80);\n let H0 = 0x67452301;\n let H1 = 0xEFCDAB89;\n let H2 = 0x98BADCFE;\n let H3 = 0x10325476;\n let H4 = 0xC3D2E1F0;\n let A, B, C, D, E;\n let temp;\n\n // utf8_encode\n str = /*unescape*/(encodeURIComponent(str));\n let strLen = str.length;\n\n let wordArray = [];\n for (i = 0; i < strLen - 3; i += 4) {\n j = str.charCodeAt(i) << 24 |\n str.charCodeAt(i + 1) << 16 |\n str.charCodeAt(i + 2) << 8 |\n str.charCodeAt(i + 3);\n wordArray.push(j);\n }\n\n switch (strLen % 4) {\n case 0:\n i = 0x080000000;\n break;\n case 1:\n i = str.charCodeAt(strLen - 1) << 24 | 0x0800000;\n break;\n case 2:\n i = str.charCodeAt(strLen - 2) << 24 | str.charCodeAt(strLen - 1) << 16 | 0x08000;\n break;\n case 3:\n i = str.charCodeAt(strLen - 3) << 24 |\n str.charCodeAt(strLen - 2) << 16 |\n str.charCodeAt(strLen - 1) <<\n 8 | 0x80;\n break;\n }\n\n wordArray.push(i);\n\n while ((wordArray.length % 16) !== 14) {\n wordArray.push(0);\n }\n\n wordArray.push(strLen >>> 29);\n wordArray.push((strLen << 3) & 0x0ffffffff);\n\n for (blockstart = 0; blockstart < wordArray.length; blockstart += 16) {\n for (i = 0; i < 16; i++) {\n W[i] = wordArray[blockstart + i];\n }\n for (i = 16; i <= 79; i++) {\n W[i] = _rotLeft(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);\n }\n\n A = H0;\n B = H1;\n C = H2;\n D = H3;\n E = H4;\n\n for (i = 0; i <= 19; i++) {\n temp = (_rotLeft(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n for (i = 20; i <= 39; i++) {\n temp = (_rotLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n for (i = 40; i <= 59; i++) {\n temp = (_rotLeft(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n for (i = 60; i <= 79; i++) {\n temp = (_rotLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n H0 = (H0 + A) & 0x0ffffffff;\n H1 = (H1 + B) & 0x0ffffffff;\n H2 = (H2 + C) & 0x0ffffffff;\n H3 = (H3 + D) & 0x0ffffffff;\n H4 = (H4 + E) & 0x0ffffffff;\n }\n\n temp = _cvtHex(H0) + _cvtHex(H1) + _cvtHex(H2) + _cvtHex(H3) + _cvtHex(H4);\n return temp.toLowerCase();\n }\n\n /**\n * RFC4122 compliant UUID v4 generator.\n */\n static uuid4(): string {\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0, v = c === \"x\" ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n }\n\n}"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/util/RandomGenerator.ts"],"names":[],"mappings":"AAAA;IAAA;IAgJ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AAC,EAAE,EAAE;gBACvB,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,WAAW,CAAC;gBAC5E,CAAC,GAAG,CAAC,CAAC;gBACN,CAAC,GAAG,CAAC,CAAC;gBACN,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACpB,CAAC,GAAG,CAAC,CAAC;gBACN,CAAC,GAAG,IAAI,CAAC;aACZ;YAED,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;YAC5B,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;SAC/B;QAED,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;IACL,sBAAC;AAAD,CAhJA,AAgJC,IAAA","file":"RandomGenerator.js","sourcesContent":["export class RandomGenerator {\n\n /**\n * discuss at: http://locutus.io/php/sha1/\n * original by: Webtoolkit.info (http://www.webtoolkit.info/)\n * improved by: Michael White (http://getsprink.com)\n * improved by: Kevin van Zonneveld (http://kvz.io)\n * input by: Brett Zamir (http://brett-zamir.me)\n * note 1: Keep in mind that in accordance with PHP, the whole string is buffered and then\n * note 1: hashed. If available, we'd recommend using Node's native crypto modules directly\n * note 1: in a steaming fashion for faster and more efficient hashing\n * example 1: sha1('Kevin van Zonneveld')\n * returns 1: '54916d2e62f65b3afa6e192e6a601cdbe5cb5897'\n */\n static sha1(str: string) {\n\n let _rotLeft = function(n: any, s: any) {\n let t4 = (n << s) | (n >>> (32 - s));\n return t4;\n };\n\n let _cvtHex = function(val: any) {\n let str = \"\";\n let i;\n let v;\n\n for (i = 7; i >= 0; i--) {\n v = (val >>> (i * 4)) & 0x0f;\n str += v.toString(16);\n }\n return str;\n };\n\n let blockstart;\n let i, j;\n let W = new Array(80);\n let H0 = 0x67452301;\n let H1 = 0xEFCDAB89;\n let H2 = 0x98BADCFE;\n let H3 = 0x10325476;\n let H4 = 0xC3D2E1F0;\n let A, B, C, D, E;\n let temp;\n\n // utf8_encode\n str = /*unescape*/(encodeURIComponent(str));\n let strLen = str.length;\n\n let wordArray = [];\n for (i = 0; i < strLen - 3; i += 4) {\n j = str.charCodeAt(i) << 24 |\n str.charCodeAt(i + 1) << 16 |\n str.charCodeAt(i + 2) << 8 |\n str.charCodeAt(i + 3);\n wordArray.push(j);\n }\n\n switch (strLen % 4) {\n case 0:\n i = 0x080000000;\n break;\n case 1:\n i = str.charCodeAt(strLen - 1) << 24 | 0x0800000;\n break;\n case 2:\n i = str.charCodeAt(strLen - 2) << 24 | str.charCodeAt(strLen - 1) << 16 | 0x08000;\n break;\n case 3:\n i = str.charCodeAt(strLen - 3) << 24 |\n str.charCodeAt(strLen - 2) << 16 |\n str.charCodeAt(strLen - 1) <<\n 8 | 0x80;\n break;\n }\n\n wordArray.push(i);\n\n while ((wordArray.length % 16) !== 14) {\n wordArray.push(0);\n }\n\n wordArray.push(strLen >>> 29);\n wordArray.push((strLen << 3) & 0x0ffffffff);\n\n for (blockstart = 0; blockstart < wordArray.length; blockstart += 16) {\n for (i = 0; i < 16; i++) {\n W[i] = wordArray[blockstart + i];\n }\n for (i = 16; i <= 79; i++) {\n W[i] = _rotLeft(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);\n }\n\n A = H0;\n B = H1;\n C = H2;\n D = H3;\n E = H4;\n\n for (i = 0; i <= 19; i++) {\n temp = (_rotLeft(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n for (i = 20; i <= 39; i++) {\n temp = (_rotLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n for (i = 40; i <= 59; i++) {\n temp = (_rotLeft(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n for (i = 60; i <= 79; i++) {\n temp = (_rotLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;\n E = D;\n D = C;\n C = _rotLeft(B, 30);\n B = A;\n A = temp;\n }\n\n H0 = (H0 + A) & 0x0ffffffff;\n H1 = (H1 + B) & 0x0ffffffff;\n H2 = (H2 + C) & 0x0ffffffff;\n H3 = (H3 + D) & 0x0ffffffff;\n H4 = (H4 + E) & 0x0ffffffff;\n }\n\n temp = _cvtHex(H0) + _cvtHex(H1) + _cvtHex(H2) + _cvtHex(H3) + _cvtHex(H4);\n return temp.toLowerCase();\n }\n}\n"],"sourceRoot":".."}
package/cli.js CHANGED
File without changes
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var globals_1 = require("../globals");
6
6
  var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader");
7
7
  var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
+ var PlatformTools_1 = require("../platform/PlatformTools");
8
9
  /**
9
10
  * Clear cache command.
10
11
  */
@@ -54,7 +55,7 @@ var CacheClearCommand = /** @class */ (function () {
54
55
  case 3:
55
56
  connection = _a.sent();
56
57
  if (!connection.queryResultCache) {
57
- console.log(chalk_1.default.black.bgRed("Cache is not enabled. To use cache enable it in connection configuration."));
58
+ PlatformTools_1.PlatformTools.logCmdErr("Cache is not enabled. To use cache enable it in connection configuration.");
58
59
  return [2 /*return*/];
59
60
  }
60
61
  return [4 /*yield*/, connection.queryResultCache.clear()];
@@ -75,8 +76,7 @@ var CacheClearCommand = /** @class */ (function () {
75
76
  _a.sent();
76
77
  _a.label = 9;
77
78
  case 9:
78
- console.log(chalk_1.default.black.bgRed("Error during cache clear:"));
79
- console.error(err_1);
79
+ PlatformTools_1.PlatformTools.logCmdErr("Error during cache clear.", err_1);
80
80
  process.exit(1);
81
81
  return [3 /*break*/, 10];
82
82
  case 10: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/CacheClearCommand.ts"],"names":[],"mappings":";;;;AAAA,sCAA4C;AAC5C,iFAA8E;AAG9E,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,aAAa,CAAC;QACxB,aAAQ,GAAG,+CAA+C,CAAC;IAqD/D,CAAC;IAnDG,mCAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,WAAW;YACpB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC,CAAC;IACX,CAAC;IAEK,mCAAO,GAAb,UAAc,IAAqB;;;;;;wBAE3B,UAAU,GAAyB,SAAS,CAAC;;;;wBAEvC,uBAAuB,GAAG,IAAI,iDAAuB,CAAC;4BACxD,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE;4BACnB,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iB","file":"CacheClearCommand.js","sourcesContent":["import {createConnection} from \"../globals\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\n\n/**\n * Clear cache command.\n */\nexport class CacheClearCommand implements yargs.CommandModule {\n\n command = \"cache:clear\";\n describe = \"Clears all data stored in query runner cache.\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"connection\", {\n alias: \"c\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"config\", {\n alias: \"f\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n\n let connection: Connection|undefined = undefined;\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 Object.assign(connectionOptions, {\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"schema\"]\n });\n connection = await createConnection(connectionOptions);\n\n if (!connection.queryResultCache) {\n console.log(chalk.black.bgRed(\"Cache is not enabled. To use cache enable it in connection configuration.\"));\n return;\n }\n\n await connection.queryResultCache.clear();\n console.log(chalk.green(\"Cache was successfully cleared\"));\n\n if (connection) await connection.close();\n\n } catch (err) {\n if (connection) await (connection as Connection).close();\n\n console.log(chalk.black.bgRed(\"Error during cache clear:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/CacheClearCommand.ts"],"names":[],"mappings":";;;;AAAA,sCAA4C;AAC5C,iFAA8E;AAG9E,6DAA0B;AAC1B,2DAA0D;AAE1D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,aAAa,CAAC;QACxB,aAAQ,GAAG,+CAA+C,CAAC;IAqD/D,CAAC;IAnDG,mCAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,I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AAxB,SAAwB,CAAC;;;;;6BAGrC,UAAU,EAAV,wBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,6BAAa,CAAC,SAAS,CAAC,2BAA2B,EAAE,KAAG,CAAC,CAAC;wBAE1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IAEL,wBAAC;AAAD,CAxDA,AAwDC,IAAA;AAxDY,8CAAiB","file":"CacheClearCommand.js","sourcesContent":["import {createConnection} from \"../globals\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { PlatformTools } from \"../platform/PlatformTools\";\n\n/**\n * Clear cache command.\n */\nexport class CacheClearCommand implements yargs.CommandModule {\n\n command = \"cache:clear\";\n describe = \"Clears all data stored in query runner cache.\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"connection\", {\n alias: \"c\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"config\", {\n alias: \"f\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n\n let connection: Connection|undefined = undefined;\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 Object.assign(connectionOptions, {\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"schema\"]\n });\n connection = await createConnection(connectionOptions);\n\n if (!connection.queryResultCache) {\n PlatformTools.logCmdErr(\"Cache is not enabled. To use cache enable it in connection configuration.\");\n return;\n }\n\n await connection.queryResultCache.clear();\n console.log(chalk.green(\"Cache was successfully cleared\"));\n\n if (connection) await connection.close();\n\n } catch (err) {\n if (connection) await (connection as Connection).close();\n\n PlatformTools.logCmdErr(\"Error during cache clear.\", err);\n\n process.exit(1);\n }\n }\n\n}\n"],"sourceRoot":".."}
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader");
6
6
  var CommandUtils_1 = require("./CommandUtils");
7
7
  var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
+ var PlatformTools_1 = require("../platform/PlatformTools");
8
9
  /**
9
10
  * Generates a new entity.
10
11
  */
@@ -79,8 +80,7 @@ var EntityCreateCommand = /** @class */ (function () {
79
80
  return [3 /*break*/, 8];
80
81
  case 7:
81
82
  err_2 = _a.sent();
82
- console.log(chalk_1.default.black.bgRed("Error during entity creation:"));
83
- console.error(err_2);
83
+ PlatformTools_1.PlatformTools.logCmdErr("Error during entity creation:", err_2);
84
84
  process.exit(1);
85
85
  return [3 /*break*/, 8];
86
86
  case 8: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/EntityCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAE5C,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QACI,YAAO,GAAG,eAAe,CAAC;QAC1B,aAAQ,GAAG,yBAAyB,CAAC;IA8EzC,CAAC;IA5EG,qCAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,gDAAgD;SAC7D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,2BAA2B;YACrC,MAAM,EAAE,IAAI;SACf,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,WAAW;YACp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AAW,CAAC,EAAA;;wBAAhD,SAAgD,CAAC;wBACjD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,YAAU,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAiC,CAAC,CAAC,CAAC;;;;wBAGtF,OAAO,CAAC,GAAG,CAAC,eAAK,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,CAhFA,AAgFC,IAAA;AAhFY,kDAAmB","file":"EntityCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"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 as string | undefined;\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 || \"\") : \"\";\n } catch (err) { }\n }\n\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (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":".."}
1
+ {"version":3,"sources":["../../src/commands/EntityCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAE5C,6DAA0B;AAC1B,2DAA0D;AAE1D;;GAEG;AACH;IAAA;QACI,YAAO,GAAG,eAAe,CAAC;QAC1B,aAAQ,GAAG,yBAAyB,CAAC;IA6EzC,CAAC;IA3EG,qCAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,gDAAgD;SAC7D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,2BAA2B;YACrC,MAAM,EAAE,IAAI;SACf,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,2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,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,eAAK,CAAC,KAAK,CAAC,YAAU,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAiC,CAAC,CAAC,CAAC;;;;wBAGtF,6BAAa,CAAC,SAAS,CAAC,+BAA+B,EAAE,KAAG,CAAC,CAAC;wBAC9D,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,CA/EA,AA+EC,IAAA;AA/EY,kDAAmB","file":"EntityCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { PlatformTools } from \"../platform/PlatformTools\";\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 as string | undefined;\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 || \"\") : \"\";\n } catch (err) { }\n }\n\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (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 PlatformTools.logCmdErr(\"Error during entity creation:\", 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":".."}
@@ -7,6 +7,7 @@ var path = (0, tslib_1.__importStar)(require("path"));
7
7
  var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
8
  var child_process_1 = require("child_process");
9
9
  var TypeORMError_1 = require("../error/TypeORMError");
10
+ var PlatformTools_1 = require("../platform/PlatformTools");
10
11
  /**
11
12
  * Generates a new project with TypeORM.
12
13
  */
@@ -126,8 +127,7 @@ var InitCommand = /** @class */ (function () {
126
127
  case 19: return [3 /*break*/, 21];
127
128
  case 20:
128
129
  err_1 = _a.sent();
129
- console.log(chalk_1.default.black.bgRed("Error during project initialization:"));
130
- console.error(err_1);
130
+ PlatformTools_1.PlatformTools.logCmdErr("Error during project initialization:", err_1);
131
131
  process.exit(1);
132
132
  return [3 /*break*/, 21];
133
133
  case 21: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/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WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAA,sBAAsB;gBAC3E,OAAO,EAAE,+DAA+D;aAC3E,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAEL,kBAAC;AAAD,CArnBA,AAqnBC,IAAA;AArnBY,kCAAW","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\";\nimport { ObjectLiteral } from \"../common/ObjectLiteral\";\nimport * as path from \"path\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { exec } from \"child_process\";\nimport { TypeORMError } from \"../error/TypeORMError\";\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\";\n describe = \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\";\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 project directory.\"\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\"\n })\n .option(\"express\", {\n describe: \"Indicates if express should be included in the project.\"\n })\n .option(\"docker\", {\n describe: \"Set to true if docker-compose must be generated as well. False by default.\"\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\"\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe: \"Module system to use for project, expected values are commonjs or esm.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = args.database as any || \"mysql\";\n const isExpress = args.express !== undefined ? true : false;\n const isDocker = args.docker !== undefined ? true : false;\n const basePath = process.cwd() + (args.name ? (\"/\" + args.name) : \"\");\n const projectName = args.name ? path.basename(args.name as any) : undefined;\n const installNpm = args.pm === \"yarn\" ? false : true;\n const projectIsEsm = args.ms === \"esm\";\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.getPackageJsonTemplate(projectName, projectIsEsm), false);\n if (isDocker)\n await CommandUtils.createFile(basePath + \"/docker-compose.yml\", InitCommand.getDockerComposeTemplate(database), false);\n await CommandUtils.createFile(basePath + \"/.gitignore\", InitCommand.getGitIgnoreFile());\n await CommandUtils.createFile(basePath + \"/README.md\", InitCommand.getReadmeTemplate({ docker: isDocker }), false);\n await CommandUtils.createFile(basePath + \"/tsconfig.json\", InitCommand.getTsConfigTemplate(projectIsEsm));\n await CommandUtils.createFile(basePath + \"/ormconfig.json\", InitCommand.getOrmConfigTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/entity/User.ts\", InitCommand.getUserEntityTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/index.ts\", InitCommand.getAppIndexTemplate(isExpress, projectIsEsm));\n await CommandUtils.createDirectories(basePath + \"/src/migration\");\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(basePath + \"/src/routes.ts\", InitCommand.getRoutesTemplate(projectIsEsm));\n await CommandUtils.createFile(basePath + \"/src/controller/UserController.ts\", InitCommand.getControllerTemplate(projectIsEsm));\n }\n\n const packageJsonContents = await CommandUtils.readFile(basePath + \"/package.json\");\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.appendPackageJson(packageJsonContents, database, isExpress, projectIsEsm));\n\n if (args.name) {\n console.log(chalk.green(`Project created inside ${chalk.blue(basePath)} directory.`));\n\n } else {\n console.log(chalk.green(`Project created inside current directory.`));\n }\n\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath);\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath);\n }\n\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during project initialization:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, {cwd}, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout);\n if (stderr) return fail(stderr);\n if (error) return fail(error);\n ok(\"\");\n });\n });\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getOrmConfigTemplate(database: string): string {\n const options: ObjectLiteral = {};\n switch (database) {\n case \"mysql\":\n Object.assign(options, {\n type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"mariadb\":\n Object.assign(options, {\n type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"sqlite\":\n Object.assign(options, {\n type: \"sqlite\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"better-sqlite3\":\n Object.assign(options, {\n type: \"better-sqlite3\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"postgres\":\n Object.assign(options, {\n \"type\": \"postgres\",\n \"host\": \"localhost\",\n \"port\": 5432,\n \"username\": \"test\",\n \"password\": \"test\",\n \"database\": \"test\",\n });\n break;\n case \"cockroachdb\":\n Object.assign(options, {\n \"type\": \"cockroachdb\",\n \"host\": \"localhost\",\n \"port\": 26257,\n \"username\": \"root\",\n \"password\": \"\",\n \"database\": \"defaultdb\",\n });\n break;\n case \"mssql\":\n Object.assign(options, {\n \"type\": \"mssql\",\n \"host\": \"localhost\",\n \"username\": \"sa\",\n \"password\": \"Admin12345\",\n \"database\": \"tempdb\",\n });\n break;\n case \"oracle\":\n Object.assign(options, {\n \"type\": \"oracle\",\n \"host\": \"localhost\",\n \"username\": \"system\",\n \"password\": \"oracle\",\n \"port\": 1521,\n \"sid\": \"xe.oracle.docker\",\n });\n break;\n case \"mongodb\":\n Object.assign(options, {\n \"type\": \"mongodb\",\n \"database\": \"test\",\n });\n break;\n }\n Object.assign(options, {\n synchronize: true,\n logging: false,\n entities: [\n \"src/entity/**/*.ts\"\n ],\n migrations: [\n \"src/migration/**/*.ts\"\n ],\n subscribers: [\n \"src/subscriber/**/*.ts\"\n ],\n cli: {\n entitiesDir: \"src/entity\",\n migrationsDir: \"src/migration\",\n subscribersDir: \"src/subscriber\"\n }\n });\n return JSON.stringify(options, undefined, 3);\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify({\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true\n }\n }\n , undefined, 3);\n else\n return JSON.stringify({\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true\n }\n }\n , undefined, 3);\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`;\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import {Entity, ${ database === \"mongodb\" ? \"ObjectIdColumn, ObjectID\" : \"PrimaryGeneratedColumn\" }, Column} from \"typeorm\";\n\n@Entity()\nexport class User {\n\n ${ database === \"mongodb\" ? \"@ObjectIdColumn()\" : \"@PrimaryGeneratedColumn()\" }\n id: ${ database === \"mongodb\" ? \"ObjectID\" : \"number\" };\n\n @Column()\n firstName: string;\n\n @Column()\n lastName: string;\n\n @Column()\n age: number;\n\n}\n`;\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import {UserController} from \"./controller/UserController${isEsm ? \".js\" : \"\"}\";\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}];`;\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import {getRepository} from \"typeorm\";\nimport {NextFunction, Request, Response} from \"express\";\nimport {User} from \"../entity/User${isEsm ? \".js\" : \"\"}\";\n\nexport class UserController {\n\n private userRepository = getRepository(User);\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find();\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id);\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body);\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOne(request.params.id);\n await this.userRepository.remove(userToRemove);\n }\n\n}`;\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(express: boolean, isEsm: boolean): string {\n if (express) {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport ${!isEsm ? \"* as \" : \"\"}express from \"express\";\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\";\nimport {Request, Response} from \"express\";\nimport {Routes} from \"./routes${isEsm ? \".js\" : \"\"}\";\nimport {User} from \"./entity/User${isEsm ? \".js\" : \"\"}\";\n\ncreateConnection().then(async connection => {\n\n // create express app\n const app = express();\n app.use(bodyParser.json());\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next);\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined);\n\n } else if (result !== null && result !== undefined) {\n res.json(result);\n }\n });\n });\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000);\n\n // insert new users for test\n await connection.manager.save(connection.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n }));\n await connection.manager.save(connection.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n }));\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\");\n\n}).catch(error => console.log(error));\n`;\n\n } else {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport {User} from \"./entity/User${isEsm ? \".js\" : \"\"}\";\n\ncreateConnection().then(async connection => {\n\n console.log(\"Inserting a new user into the database...\");\n const user = new User();\n user.firstName = \"Timber\";\n user.lastName = \"Saw\";\n user.age = 25;\n await connection.manager.save(user);\n console.log(\"Saved a new user with id: \" + user.id);\n\n console.log(\"Loading users from the database...\");\n const users = await connection.manager.find(User);\n console.log(\"Loaded users: \", users);\n\n console.log(\"Here you can setup and run express/koa/any other framework.\");\n\n}).catch(error => console.log(error));\n`;\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(projectName?: string, projectIsEsm?: boolean): string {\n return JSON.stringify({\n name: projectName || \"new-typeorm-project\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {\n },\n dependencies: {\n },\n scripts: {\n }\n }, undefined, 3);\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`;\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`;\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`;\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`;\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`;\n case \"oracle\":\n throw new TypeORMError(`You cannot initialize a project with docker for Oracle driver yet.`); // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`;\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`;\n }\n return \"\";\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`;\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`;\n } else {\n template += `2. Setup database settings inside \\`ormconfig.json\\` file\n`;\n }\n\n template += `3. Run \\`npm start\\` command\n`;\n return template;\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(packageJsonContents: string, database: string, express: boolean, projectIsEsm: boolean /*, docker: boolean*/): string {\n const packageJson = JSON.parse(packageJsonContents);\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {};\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.4.0\",\n \"@types/node\": \"^16.11.10\",\n \"typescript\": \"4.5.2\"\n });\n\n if (!packageJson.dependencies) packageJson.dependencies = {};\n Object.assign(packageJson.dependencies, {\n \"typeorm\": require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\"\n });\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\";\n break;\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\";\n break;\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^4.0.3\";\n break;\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\";\n break;\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\";\n break;\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\";\n break;\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\";\n break;\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\";\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\";\n }\n\n if (!packageJson.scripts) packageJson.scripts = {};\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */\"node --loader ts-node/esm src/index.ts\",\n typeorm: \"node --loader ts-node/esm ./node_modules/typeorm/cli.js\"\n });\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */\"ts-node src/index.ts\",\n typeorm: \"node --require ts-node/register ./node_modules/typeorm/cli.js\"\n });\n\n return JSON.stringify(packageJson, undefined, 3);\n }\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,+CAA8C;AAE9C,sD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;QAEP,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAEL,kBAAC;AAAD,CApnBA,AAonBC,IAAA;AApnBY,kCAAW","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\";\nimport { ObjectLiteral } from \"../common/ObjectLiteral\";\nimport * as path from \"path\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { exec } from \"child_process\";\nimport { TypeORMError } from \"../error/TypeORMError\";\nimport { PlatformTools } from \"../platform/PlatformTools\";\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\";\n describe = \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\";\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 project directory.\"\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\"\n })\n .option(\"express\", {\n describe: \"Indicates if express should be included in the project.\"\n })\n .option(\"docker\", {\n describe: \"Set to true if docker-compose must be generated as well. False by default.\"\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\"\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe: \"Module system to use for project, expected values are commonjs or esm.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = args.database as any || \"mysql\";\n const isExpress = args.express !== undefined ? true : false;\n const isDocker = args.docker !== undefined ? true : false;\n const basePath = process.cwd() + (args.name ? (\"/\" + args.name) : \"\");\n const projectName = args.name ? path.basename(args.name as any) : undefined;\n const installNpm = args.pm === \"yarn\" ? false : true;\n const projectIsEsm = args.ms === \"esm\";\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.getPackageJsonTemplate(projectName, projectIsEsm), false);\n if (isDocker)\n await CommandUtils.createFile(basePath + \"/docker-compose.yml\", InitCommand.getDockerComposeTemplate(database), false);\n await CommandUtils.createFile(basePath + \"/.gitignore\", InitCommand.getGitIgnoreFile());\n await CommandUtils.createFile(basePath + \"/README.md\", InitCommand.getReadmeTemplate({ docker: isDocker }), false);\n await CommandUtils.createFile(basePath + \"/tsconfig.json\", InitCommand.getTsConfigTemplate(projectIsEsm));\n await CommandUtils.createFile(basePath + \"/ormconfig.json\", InitCommand.getOrmConfigTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/entity/User.ts\", InitCommand.getUserEntityTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/index.ts\", InitCommand.getAppIndexTemplate(isExpress, projectIsEsm));\n await CommandUtils.createDirectories(basePath + \"/src/migration\");\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(basePath + \"/src/routes.ts\", InitCommand.getRoutesTemplate(projectIsEsm));\n await CommandUtils.createFile(basePath + \"/src/controller/UserController.ts\", InitCommand.getControllerTemplate(projectIsEsm));\n }\n\n const packageJsonContents = await CommandUtils.readFile(basePath + \"/package.json\");\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.appendPackageJson(packageJsonContents, database, isExpress, projectIsEsm));\n\n if (args.name) {\n console.log(chalk.green(`Project created inside ${chalk.blue(basePath)} directory.`));\n\n } else {\n console.log(chalk.green(`Project created inside current directory.`));\n }\n\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath);\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath);\n }\n\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, {cwd}, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout);\n if (stderr) return fail(stderr);\n if (error) return fail(error);\n ok(\"\");\n });\n });\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getOrmConfigTemplate(database: string): string {\n const options: ObjectLiteral = {};\n switch (database) {\n case \"mysql\":\n Object.assign(options, {\n type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"mariadb\":\n Object.assign(options, {\n type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"sqlite\":\n Object.assign(options, {\n type: \"sqlite\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"better-sqlite3\":\n Object.assign(options, {\n type: \"better-sqlite3\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"postgres\":\n Object.assign(options, {\n \"type\": \"postgres\",\n \"host\": \"localhost\",\n \"port\": 5432,\n \"username\": \"test\",\n \"password\": \"test\",\n \"database\": \"test\",\n });\n break;\n case \"cockroachdb\":\n Object.assign(options, {\n \"type\": \"cockroachdb\",\n \"host\": \"localhost\",\n \"port\": 26257,\n \"username\": \"root\",\n \"password\": \"\",\n \"database\": \"defaultdb\",\n });\n break;\n case \"mssql\":\n Object.assign(options, {\n \"type\": \"mssql\",\n \"host\": \"localhost\",\n \"username\": \"sa\",\n \"password\": \"Admin12345\",\n \"database\": \"tempdb\",\n });\n break;\n case \"oracle\":\n Object.assign(options, {\n \"type\": \"oracle\",\n \"host\": \"localhost\",\n \"username\": \"system\",\n \"password\": \"oracle\",\n \"port\": 1521,\n \"sid\": \"xe.oracle.docker\",\n });\n break;\n case \"mongodb\":\n Object.assign(options, {\n \"type\": \"mongodb\",\n \"database\": \"test\",\n });\n break;\n }\n Object.assign(options, {\n synchronize: true,\n logging: false,\n entities: [\n \"src/entity/**/*.ts\"\n ],\n migrations: [\n \"src/migration/**/*.ts\"\n ],\n subscribers: [\n \"src/subscriber/**/*.ts\"\n ],\n cli: {\n entitiesDir: \"src/entity\",\n migrationsDir: \"src/migration\",\n subscribersDir: \"src/subscriber\"\n }\n });\n return JSON.stringify(options, undefined, 3);\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify({\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true\n }\n }\n , undefined, 3);\n else\n return JSON.stringify({\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true\n }\n }\n , undefined, 3);\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`;\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import {Entity, ${ database === \"mongodb\" ? \"ObjectIdColumn, ObjectID\" : \"PrimaryGeneratedColumn\" }, Column} from \"typeorm\";\n\n@Entity()\nexport class User {\n\n ${ database === \"mongodb\" ? \"@ObjectIdColumn()\" : \"@PrimaryGeneratedColumn()\" }\n id: ${ database === \"mongodb\" ? \"ObjectID\" : \"number\" };\n\n @Column()\n firstName: string;\n\n @Column()\n lastName: string;\n\n @Column()\n age: number;\n\n}\n`;\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import {UserController} from \"./controller/UserController${isEsm ? \".js\" : \"\"}\";\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}];`;\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import {getRepository} from \"typeorm\";\nimport {NextFunction, Request, Response} from \"express\";\nimport {User} from \"../entity/User${isEsm ? \".js\" : \"\"}\";\n\nexport class UserController {\n\n private userRepository = getRepository(User);\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find();\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id);\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body);\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOne(request.params.id);\n await this.userRepository.remove(userToRemove);\n }\n\n}`;\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(express: boolean, isEsm: boolean): string {\n if (express) {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport ${!isEsm ? \"* as \" : \"\"}express from \"express\";\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\";\nimport {Request, Response} from \"express\";\nimport {Routes} from \"./routes${isEsm ? \".js\" : \"\"}\";\nimport {User} from \"./entity/User${isEsm ? \".js\" : \"\"}\";\n\ncreateConnection().then(async connection => {\n\n // create express app\n const app = express();\n app.use(bodyParser.json());\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next);\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined);\n\n } else if (result !== null && result !== undefined) {\n res.json(result);\n }\n });\n });\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000);\n\n // insert new users for test\n await connection.manager.save(connection.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n }));\n await connection.manager.save(connection.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n }));\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\");\n\n}).catch(error => console.log(error));\n`;\n\n } else {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport {User} from \"./entity/User${isEsm ? \".js\" : \"\"}\";\n\ncreateConnection().then(async connection => {\n\n console.log(\"Inserting a new user into the database...\");\n const user = new User();\n user.firstName = \"Timber\";\n user.lastName = \"Saw\";\n user.age = 25;\n await connection.manager.save(user);\n console.log(\"Saved a new user with id: \" + user.id);\n\n console.log(\"Loading users from the database...\");\n const users = await connection.manager.find(User);\n console.log(\"Loaded users: \", users);\n\n console.log(\"Here you can setup and run express/koa/any other framework.\");\n\n}).catch(error => console.log(error));\n`;\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(projectName?: string, projectIsEsm?: boolean): string {\n return JSON.stringify({\n name: projectName || \"new-typeorm-project\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {\n },\n dependencies: {\n },\n scripts: {\n }\n }, undefined, 3);\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`;\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`;\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`;\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`;\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`;\n case \"oracle\":\n throw new TypeORMError(`You cannot initialize a project with docker for Oracle driver yet.`); // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`;\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`;\n }\n return \"\";\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`;\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`;\n } else {\n template += `2. Setup database settings inside \\`ormconfig.json\\` file\n`;\n }\n\n template += `3. Run \\`npm start\\` command\n`;\n return template;\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(packageJsonContents: string, database: string, express: boolean, projectIsEsm: boolean /*, docker: boolean*/): string {\n const packageJson = JSON.parse(packageJsonContents);\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {};\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.4.0\",\n \"@types/node\": \"^16.11.10\",\n \"typescript\": \"4.5.2\"\n });\n\n if (!packageJson.dependencies) packageJson.dependencies = {};\n Object.assign(packageJson.dependencies, {\n \"typeorm\": require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\"\n });\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\";\n break;\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\";\n break;\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^4.0.3\";\n break;\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\";\n break;\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\";\n break;\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\";\n break;\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\";\n break;\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\";\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\";\n }\n\n if (!packageJson.scripts) packageJson.scripts = {};\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */\"node --loader ts-node/esm src/index.ts\",\n typeorm: \"node --loader ts-node/esm ./node_modules/typeorm/cli.js\"\n });\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */\"ts-node src/index.ts\",\n typeorm: \"node --require ts-node/register ./node_modules/typeorm/cli.js\"\n });\n\n return JSON.stringify(packageJson, undefined, 3);\n }\n\n}\n"],"sourceRoot":".."}
@@ -6,6 +6,7 @@ var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader")
6
6
  var CommandUtils_1 = require("./CommandUtils");
7
7
  var StringUtils_1 = require("../util/StringUtils");
8
8
  var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
9
+ var PlatformTools_1 = require("../platform/PlatformTools");
9
10
  /**
10
11
  * Creates a new migration file.
11
12
  */
@@ -96,8 +97,7 @@ var MigrationCreateCommand = /** @class */ (function () {
96
97
  return [3 /*break*/, 8];
97
98
  case 7:
98
99
  err_2 = _a.sent();
99
- console.log(chalk_1.default.black.bgRed("Error during migration creation:"));
100
- console.error(err_2);
100
+ PlatformTools_1.PlatformTools.logCmdErr("Error during migration creation:", err_2);
101
101
  process.exit(1);
102
102
  return [3 /*break*/, 8];
103
103
  case 8: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,kBAAkB,CAAC;QAC7B,aAAQ,GAAG,+BAA+B,CAAC;QAC3C,YAAO,GAAG,mBAAmB,CAAC;IAmHlC,CAAC;IAjHG,wCAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,8BAA8B;YACxC,MAAM,EAAE,IAAI;SACf,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,WAAW;YACpB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,+DAA+D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} from \"./CommandUtils\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"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 .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"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 if (args._[0] === \"migrations:create\") {\n console.log(\"'migrations:create' is deprecated, please use 'migration:create' instead\");\n }\n\n try {\n const timestamp = CommandUtils.getTimestamp(args.timestamp);\n const fileContent = args.outputJs ?\n MigrationCreateCommand.getJavascriptTemplate(args.name as any, timestamp)\n : MigrationCreateCommand.getTemplate(args.name as any, timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\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 || \"\") : \"\";\n } catch (err) { }\n }\n\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (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<void> {\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number): 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"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAC1B,2DAA0D;AAE1D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,kBAAkB,CAAC;QAC7B,aAAQ,GAAG,+BAA+B,CAAC;QAC3C,YAAO,GAAG,mBAAmB,CAAC;IAkHlC,CAAC;IAhHG,wCAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,8BAA8B;YACxC,MAAM,EAAE,IAAI;SACf,CAAC;aACD,MAAM,CA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AiB;QAClE,OAAO,iGAEU,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,kGAQjD,CAAC;IACN,CAAC;IACL,6BAAC;AAAD,CAtHA,AAsHC,IAAA;AAtHY,wDAAsB","file":"MigrationCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { PlatformTools } from \"../platform/PlatformTools\";\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 .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"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 if (args._[0] === \"migrations:create\") {\n console.log(\"'migrations:create' is deprecated, please use 'migration:create' instead\");\n }\n\n try {\n const timestamp = CommandUtils.getTimestamp(args.timestamp);\n const fileContent = args.outputJs ?\n MigrationCreateCommand.getJavascriptTemplate(args.name as any, timestamp)\n : MigrationCreateCommand.getTemplate(args.name as any, timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\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 || \"\") : \"\";\n } catch (err) { }\n }\n\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (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 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(name, true)}${timestamp} implements MigrationInterface {\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number): 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"],"sourceRoot":".."}
@@ -8,6 +8,7 @@ var globals_1 = require("../globals");
8
8
  var StringUtils_1 = require("../util/StringUtils");
9
9
  var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
10
10
  var sqlFormatter_1 = require("@sqltools/formatter/lib/sqlFormatter");
11
+ var PlatformTools_1 = require("../platform/PlatformTools");
11
12
  /**
12
13
  * Generates a new migration file with sql needs to be executed to update schema.
13
14
  */
@@ -180,8 +181,7 @@ var MigrationGenerateCommand = /** @class */ (function () {
180
181
  case 14: return [3 /*break*/, 16];
181
182
  case 15:
182
183
  err_2 = _a.sent();
183
- console.log(chalk_1.default.black.bgRed("Error during migration generation:"));
184
- console.error(err_2);
184
+ PlatformTools_1.PlatformTools.logCmdErr("Error during migration generation:", err_2);
185
185
  process.exit(1);
186
186
  return [3 /*break*/, 16];
187
187
  case 16: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,sCAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAC1B,qEAA8D;AAE9D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,oBAAoB,CAAC;QAC/B,aAAQ,GAAG,gFAAgF,CAAC;QAC5F,YAAO,GAAG,qBAAqB,CAAC;IAmOpC,CAAC;IAjOG,0CAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,8BAA8B;YACxC,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,QAAQ;SACjB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,4BAA4B;SACzC,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,WAAW;YACpB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;Y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AAO,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CAAC;IAC/E,CAAC;IACL,+BAAC;AAAD,CAvOA,AAuOC,IAAA;AAvOY,4DAAwB","file":"MigrationGenerateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {createConnection} from \"../globals\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\";\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n\n command = \"migration:generate\";\n describe = \"Generates a new migration file with sql needs to be executed to update schema.\";\n aliases = \"migrations:generate\";\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 type: \"string\"\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where migration should be created.\"\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe: \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe: \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\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 if (args._[0] === \"migrations:generate\") {\n console.log(\"'migrations:generate' is deprecated, please use 'migration:generate' instead\");\n }\n\n const timestamp = CommandUtils.getTimestamp(args.timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\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 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 Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n\n const upSqls: string[] = [], downSqls: string[] = [];\n\n const connection = await createConnection(connectionOptions);\n try {\n const sqlInMemory = await connection.driver.createSchemaBuilder().log();\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach(upQuery => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(upQuery.query);\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downQuery.query = MigrationGenerateCommand.prettifyQuery(downQuery.query);\n });\n }\n\n sqlInMemory.upQueries.forEach(upQuery => {\n upSqls.push(\" await queryRunner.query(`\" + upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(upQuery.parameters) + \");\");\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downSqls.push(\" await queryRunner.query(`\" + downQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(downQuery.parameters) + \");\");\n });\n } finally {\n await connection.close();\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(chalk.green(`No changes in database schema were found`));\n process.exit(0);\n } else {\n console.log(chalk.yellow(`No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`));\n process.exit(1);\n }\n } else if (!args.name) {\n console.log(chalk.yellow(\"Please specify a migration name using the `-n` argument\"));\n process.exit(1);\n }\n\n const fileContent = args.outputJs ?\n MigrationGenerateCommand.getJavascriptTemplate(args.name as any, timestamp, upSqls, downSqls.reverse()) :\n MigrationGenerateCommand.getTemplate(args.name as any, timestamp, upSqls, downSqls.reverse());\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (directory ? (directory + \"/\") : \"\") + filename;\n\n if (args.check) {\n console.log(chalk.yellow(`Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(fileContent)}`));\n process.exit(1);\n }\n\n if (args.dryrun) {\n console.log(chalk.green(`Migration ${chalk.blue(path)} has content:\\n\\n${chalk.white(fileContent)}`));\n } else {\n await CommandUtils.createFile(path, fileContent);\n\n console.log(chalk.green(`Migration ${chalk.blue(path)} has been generated successfully.`));\n }\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during migration generation:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\";\n }\n\n return `, ${JSON.stringify(parameters)}`;\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`;\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" });\n return \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \";\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,sCAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAC1B,qEAA8D;AAC9D,2DAA0D;AAE1D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,oBAAoB,CAAC;QAC/B,aAAQ,GAAG,gFAAgF,CAAC;QAC5F,YAAO,GAAG,qBAAqB,CAAC;IAkOpC,CAAC;IAhOG,0CAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,8BAA8B;YACxC,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,QAAQ;SACjB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,8CAA8C;SAC3D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,IAAI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CAAC;IACE,CAAC;IAED;;OAEG;IACc,sCAAa,GAA9B,UAA+B,KAAa;QACxC,IAAM,cAAc,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACzD,OAAO,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CAAC;IAC/E,CAAC;IACL,+BAAC;AAAD,CAtOA,AAsOC,IAAA;AAtOY,4DAAwB","file":"MigrationGenerateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {createConnection} from \"../globals\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\";\nimport { PlatformTools } from \"../platform/PlatformTools\";\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n\n command = \"migration:generate\";\n describe = \"Generates a new migration file with sql needs to be executed to update schema.\";\n aliases = \"migrations:generate\";\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 type: \"string\"\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where migration should be created.\"\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe: \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe: \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\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 if (args._[0] === \"migrations:generate\") {\n console.log(\"'migrations:generate' is deprecated, please use 'migration:generate' instead\");\n }\n\n const timestamp = CommandUtils.getTimestamp(args.timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\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 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 Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n\n const upSqls: string[] = [], downSqls: string[] = [];\n\n const connection = await createConnection(connectionOptions);\n try {\n const sqlInMemory = await connection.driver.createSchemaBuilder().log();\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach(upQuery => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(upQuery.query);\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downQuery.query = MigrationGenerateCommand.prettifyQuery(downQuery.query);\n });\n }\n\n sqlInMemory.upQueries.forEach(upQuery => {\n upSqls.push(\" await queryRunner.query(`\" + upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(upQuery.parameters) + \");\");\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downSqls.push(\" await queryRunner.query(`\" + downQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(downQuery.parameters) + \");\");\n });\n } finally {\n await connection.close();\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(chalk.green(`No changes in database schema were found`));\n process.exit(0);\n } else {\n console.log(chalk.yellow(`No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`));\n process.exit(1);\n }\n } else if (!args.name) {\n console.log(chalk.yellow(\"Please specify a migration name using the `-n` argument\"));\n process.exit(1);\n }\n\n const fileContent = args.outputJs ?\n MigrationGenerateCommand.getJavascriptTemplate(args.name as any, timestamp, upSqls, downSqls.reverse()) :\n MigrationGenerateCommand.getTemplate(args.name as any, timestamp, upSqls, downSqls.reverse());\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (directory ? (directory + \"/\") : \"\") + filename;\n\n if (args.check) {\n console.log(chalk.yellow(`Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(fileContent)}`));\n process.exit(1);\n }\n\n if (args.dryrun) {\n console.log(chalk.green(`Migration ${chalk.blue(path)} has content:\\n\\n${chalk.white(fileContent)}`));\n } else {\n await CommandUtils.createFile(path, fileContent);\n\n console.log(chalk.green(`Migration ${chalk.blue(path)} has been generated successfully.`));\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\";\n }\n\n return `, ${JSON.stringify(parameters)}`;\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`;\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" });\n return \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \";\n }\n}\n"],"sourceRoot":".."}
@@ -4,7 +4,7 @@ exports.MigrationRevertCommand = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var globals_1 = require("../globals");
6
6
  var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader");
7
- var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
7
+ var PlatformTools_1 = require("../platform/PlatformTools");
8
8
  /**
9
9
  * Reverts last migration command.
10
10
  */
@@ -95,8 +95,7 @@ var MigrationRevertCommand = /** @class */ (function () {
95
95
  _b.sent();
96
96
  _b.label = 8;
97
97
  case 8:
98
- console.log(chalk_1.default.black.bgRed("Error during migration revert:"));
99
- console.error(err_1);
98
+ PlatformTools_1.PlatformTools.logCmdErr("Error during migration revert:", err_1);
100
99
  process.exit(1);
101
100
  return [3 /*break*/, 9];
102
101
  case 9: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAAA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AAE,OAAO,EAAE,QAAQ,CAAC;yBACxC,CAAC,CAAC;wBACU,qBAAM,IAAA,0BAAgB,EAAC,iBAAiB,CAAC,EAAA;;wBAAtD,UAAU,GAAG,SAAyC,CAAC;wBAEjD,OAAO,GAAG;4BACZ,WAAW,EAAE,MAAA,iBAAiB,CAAC,yBAAyB,mCAAI,KAAgC;yBAC/F,CAAC;wBAEF,QAAQ,IAAI,CAAC,CAAC,EAAE;4BACZ,KAAK,KAAK;gCACN,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC;gCAC5B,MAAM;4BACV,KAAK,MAAM,CAAC;4BACZ,KAAK,OAAO;gCACR,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC;gCAC7B,MAAM;4BACV,KAAK,MAAM;gCACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC;gCAC7B,MAAM;4BACV,QAAQ;4BACJ,OAAO;yBACd;wBAED,qBAAM,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;;wBAA3C,SAA2C,CAAC;wBAC5C,qBAAM,UAAU,CAAC,KAAK,EAAE,EAAA;;wBAAxB,SAAwB,CAAC;;;;6BAGrB,UAAU,EAAV,wBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;wBACjE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IAEL,6BAAC;AAAD,CA7EA,AA6EC,IAAA;AA7EY,wDAAsB","file":"MigrationRevertCommand.js","sourcesContent":["import {createConnection} from \"../globals\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n\n command = \"migration:revert\";\n describe = \"Reverts last executed migration.\";\n aliases = \"migrations:revert\";\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(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe: \"Indicates if transaction should be used or not for migration revert. Enabled by default.\"\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:revert\") {\n console.log(\"'migrations:revert' is deprecated, please use 'migration:revert' instead\");\n }\n\n let connection: Connection|undefined = undefined;\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 Object.assign(connectionOptions, {\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"]\n });\n connection = await createConnection(connectionOptions);\n\n const options = {\n transaction: connectionOptions.migrationsTransactionMode ?? \"all\" as \"all\" | \"none\" | \"each\",\n };\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\";\n break;\n case \"none\":\n case \"false\":\n options.transaction = \"none\";\n break;\n case \"each\":\n options.transaction = \"each\";\n break;\n default:\n // noop\n }\n\n await connection.undoLastMigration(options);\n await connection.close();\n\n } catch (err) {\n if (connection) await (connection as Connection).close();\n\n console.log(chalk.black.bgRed(\"Error during migration revert:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAAA,sCAA4C;AAC5C,iFAA8E;AAG9E,2DAA0D;AAE1D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,kBAAkB,CAAC;QAC7B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wBAAtD,UAAU,GAAG,SAAyC,CAAC;wBAEjD,OAAO,GAAG;4BACZ,WAAW,EAAE,MAAA,iBAAiB,CAAC,yBAAyB,mCAAI,KAAgC;yBAC/F,CAAC;wBAEF,QAAQ,IAAI,CAAC,CAAC,EAAE;4BACZ,KAAK,KAAK;gCACN,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC;gCAC5B,MAAM;4BACV,KAAK,MAAM,CAAC;4BACZ,KAAK,OAAO;gCACR,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC;gCAC7B,MAAM;4BACV,KAAK,MAAM;gCACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC;gCAC7B,MAAM;4BACV,QAAQ;4BACJ,OAAO;yBACd;wBAED,qBAAM,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;;wBAA3C,SAA2C,CAAC;wBAC5C,qBAAM,UAAU,CAAC,KAAK,EAAE,EAAA;;wBAAxB,SAAwB,CAAC;;;;6BAGrB,UAAU,EAAV,wBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,6BAAa,CAAC,SAAS,CAAC,gCAAgC,EAAE,KAAG,CAAC,CAAC;wBAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IAEL,6BAAC;AAAD,CA5EA,AA4EC,IAAA;AA5EY,wDAAsB","file":"MigrationRevertCommand.js","sourcesContent":["import {createConnection} from \"../globals\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport * as yargs from \"yargs\";\nimport { PlatformTools } from \"../platform/PlatformTools\";\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n\n command = \"migration:revert\";\n describe = \"Reverts last executed migration.\";\n aliases = \"migrations:revert\";\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(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe: \"Indicates if transaction should be used or not for migration revert. Enabled by default.\"\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:revert\") {\n console.log(\"'migrations:revert' is deprecated, please use 'migration:revert' instead\");\n }\n\n let connection: Connection|undefined = undefined;\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 Object.assign(connectionOptions, {\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"]\n });\n connection = await createConnection(connectionOptions);\n\n const options = {\n transaction: connectionOptions.migrationsTransactionMode ?? \"all\" as \"all\" | \"none\" | \"each\",\n };\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\";\n break;\n case \"none\":\n case \"false\":\n options.transaction = \"none\";\n break;\n case \"each\":\n options.transaction = \"each\";\n break;\n default:\n // noop\n }\n\n await connection.undoLastMigration(options);\n await connection.close();\n\n } catch (err) {\n if (connection) await (connection as Connection).close();\n\n PlatformTools.logCmdErr(\"Error during migration revert:\", err);\n process.exit(1);\n }\n }\n\n}\n"],"sourceRoot":".."}
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var globals_1 = require("../globals");
6
6
  var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader");
7
7
  var process = (0, tslib_1.__importStar)(require("process"));
8
- var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
+ var PlatformTools_1 = require("../platform/PlatformTools");
9
9
  /**
10
10
  * Runs migration command.
11
11
  */
@@ -98,8 +98,7 @@ var MigrationRunCommand = /** @class */ (function () {
98
98
  _b.sent();
99
99
  _b.label = 8;
100
100
  case 8:
101
- console.log(chalk_1.default.black.bgRed("Error during migration run:"));
102
- console.error(err_1);
101
+ PlatformTools_1.PlatformTools.logCmdErr("Error during migration run:", err_1);
103
102
  process.exit(1);
104
103
  return [3 /*break*/, 9];
105
104
  case 9: return [2 /*return*/];