midway-model-gen 0.0.1

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 (65) hide show
  1. package/.idea/codeStyles/Project.xml +57 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/prettier.xml +6 -0
  6. package/.idea/test.iml +8 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/CHANGELOG.md +161 -0
  9. package/CONTRIBUTING.md +51 -0
  10. package/DEVELOPER.md +30 -0
  11. package/LICENSE +21 -0
  12. package/README.md +94 -0
  13. package/USECASES.md +53 -0
  14. package/bin/typeorm-model-generator +6 -0
  15. package/dist/package.json +106 -0
  16. package/dist/src/Engine.d.ts +7 -0
  17. package/dist/src/Engine.js +47 -0
  18. package/dist/src/IConnectionOptions.d.ts +14 -0
  19. package/dist/src/IConnectionOptions.js +22 -0
  20. package/dist/src/IGenerationOptions.d.ts +24 -0
  21. package/dist/src/IGenerationOptions.js +33 -0
  22. package/dist/src/ModelCustomization.d.ts +4 -0
  23. package/dist/src/ModelCustomization.js +256 -0
  24. package/dist/src/ModelGeneration.d.ts +4 -0
  25. package/dist/src/ModelGeneration.js +247 -0
  26. package/dist/src/NamingStrategy.d.ts +10 -0
  27. package/dist/src/NamingStrategy.js +61 -0
  28. package/dist/src/Utils.d.ts +6 -0
  29. package/dist/src/Utils.js +68 -0
  30. package/dist/src/drivers/AbstractDriver.d.ts +30 -0
  31. package/dist/src/drivers/AbstractDriver.js +258 -0
  32. package/dist/src/drivers/MariaDbDriver.d.ts +4 -0
  33. package/dist/src/drivers/MariaDbDriver.js +11 -0
  34. package/dist/src/drivers/MssqlDriver.d.ts +25 -0
  35. package/dist/src/drivers/MssqlDriver.js +408 -0
  36. package/dist/src/drivers/MysqlDriver.d.ts +27 -0
  37. package/dist/src/drivers/MysqlDriver.js +439 -0
  38. package/dist/src/drivers/OracleDriver.d.ts +25 -0
  39. package/dist/src/drivers/OracleDriver.js +316 -0
  40. package/dist/src/drivers/PostgresDriver.d.ts +31 -0
  41. package/dist/src/drivers/PostgresDriver.js +542 -0
  42. package/dist/src/drivers/SqliteDriver.d.ts +28 -0
  43. package/dist/src/drivers/SqliteDriver.js +308 -0
  44. package/dist/src/index.d.ts +1 -0
  45. package/dist/src/index.js +667 -0
  46. package/dist/src/library.d.ts +11 -0
  47. package/dist/src/library.js +14 -0
  48. package/dist/src/models/Column.d.ts +24 -0
  49. package/dist/src/models/Column.js +3 -0
  50. package/dist/src/models/Entity.d.ts +21 -0
  51. package/dist/src/models/Entity.js +3 -0
  52. package/dist/src/models/Index.d.ts +9 -0
  53. package/dist/src/models/Index.js +3 -0
  54. package/dist/src/models/Relation.d.ts +11 -0
  55. package/dist/src/models/Relation.js +3 -0
  56. package/dist/src/models/RelationId.d.ts +5 -0
  57. package/dist/src/models/RelationId.js +3 -0
  58. package/dist/src/models/RelationInternal.d.ts +11 -0
  59. package/dist/src/models/RelationInternal.js +3 -0
  60. package/dist/src/templates/entity.mst +47 -0
  61. package/dist/src/templates/index.mst +5 -0
  62. package/dist/src/templates/ormconfig.mst +17 -0
  63. package/dist/src/templates/tsconfig.mst +10 -0
  64. package/npminstall-debug.log +175 -0
  65. package/package.json +106 -0
@@ -0,0 +1,667 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Yargs = require("yargs");
4
+ const Engine_1 = require("./Engine");
5
+ const TomgUtils = require("./Utils");
6
+ const IConnectionOptions_1 = require("./IConnectionOptions");
7
+ const IGenerationOptions_1 = require("./IGenerationOptions");
8
+ const fs = require("fs-extra");
9
+ const inquirer = require("inquirer");
10
+ const path = require("path");
11
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
12
+ CliLogic();
13
+ async function CliLogic() {
14
+ console.log(TomgUtils.packageVersion());
15
+ let options = makeDefaultConfigs();
16
+ const TOMLConfig = readTOMLConfig(options);
17
+ options = TOMLConfig.options;
18
+ if (process.argv.length > 2) {
19
+ options = checkYargsParameters(options);
20
+ }
21
+ else if (!TOMLConfig.fullConfigFile) {
22
+ options = await useInquirer(options);
23
+ }
24
+ options = validateConfig(options);
25
+ const driver = (0, Engine_1.createDriver)(options.connectionOptions.databaseType);
26
+ console.log(`[${new Date().toLocaleTimeString()}] Starting creation of model classes.`);
27
+ await (0, Engine_1.createModelFromDatabase)(driver, options.connectionOptions, options.generationOptions);
28
+ console.info(`[${new Date().toLocaleTimeString()}] Typeorm model classes created.`);
29
+ }
30
+ function validateConfig(options) {
31
+ if (options.generationOptions.lazy &&
32
+ options.generationOptions.relationIds) {
33
+ TomgUtils.LogError("Typeorm doesn't support RelationId fields for lazy relations.", false);
34
+ options.generationOptions.relationIds = false;
35
+ }
36
+ return options;
37
+ }
38
+ function makeDefaultConfigs() {
39
+ const generationOptions = (0, IGenerationOptions_1.getDefaultGenerationOptions)();
40
+ const connectionOptions = (0, IConnectionOptions_1.getDefaultConnectionOptions)();
41
+ return {
42
+ generationOptions,
43
+ connectionOptions,
44
+ };
45
+ }
46
+ function readTOMLConfig(options) {
47
+ if (!fs.existsSync(path.resolve(process.cwd(), ".tomg-config"))) {
48
+ return { options, fullConfigFile: false };
49
+ }
50
+ console.log(`[${new Date().toLocaleTimeString()}] Using configuration file. [${path.resolve(process.cwd(), ".tomg-config")}]`);
51
+ const retVal = fs.readJsonSync(path.resolve(process.cwd(), ".tomg-config"));
52
+ const [loadedGenerationOptions, loadedConnectionOptions] = retVal;
53
+ let hasUnknownProperties = false;
54
+ if (loadedConnectionOptions) {
55
+ Object.keys(loadedConnectionOptions).forEach((key) => {
56
+ if (Object.prototype.hasOwnProperty.call(options.connectionOptions, key)) {
57
+ options.connectionOptions[key] = loadedConnectionOptions[key];
58
+ }
59
+ else {
60
+ console.error(`Unknown connection option ${key}.`);
61
+ hasUnknownProperties = true;
62
+ }
63
+ });
64
+ }
65
+ if (loadedGenerationOptions) {
66
+ Object.keys(loadedGenerationOptions).forEach((key) => {
67
+ if (Object.prototype.hasOwnProperty.call(options.generationOptions, key)) {
68
+ options.generationOptions[key] = loadedGenerationOptions[key];
69
+ }
70
+ else {
71
+ console.error(`Unknown generation option ${key}.`);
72
+ hasUnknownProperties = true;
73
+ }
74
+ });
75
+ }
76
+ const fullConfigFile = !hasUnknownProperties &&
77
+ loadedConnectionOptions &&
78
+ loadedGenerationOptions &&
79
+ Object.keys(loadedConnectionOptions).length ===
80
+ Object.keys(options.connectionOptions).length &&
81
+ Object.keys(loadedGenerationOptions).length ===
82
+ Object.keys(options.generationOptions).length;
83
+ return {
84
+ options,
85
+ fullConfigFile,
86
+ };
87
+ }
88
+ function checkYargsParameters(options) {
89
+ const { argv } = Yargs.usage("Usage: typeorm-model-generator -h <host> -d <database> -p [port] -u <user> -x [password] -e [engine]\nYou can also run program without specifying any parameters.").options({
90
+ h: {
91
+ alias: "host",
92
+ string: true,
93
+ default: options.connectionOptions.host,
94
+ describe: "IP address/Hostname for database server",
95
+ },
96
+ d: {
97
+ alias: "database",
98
+ string: true,
99
+ demand: true,
100
+ default: options.connectionOptions.databaseNames.join(","),
101
+ describe: "Database name(or path for sqlite). You can pass multiple values separated by comma.",
102
+ },
103
+ u: {
104
+ alias: "user",
105
+ string: true,
106
+ default: options.connectionOptions.user,
107
+ describe: "Username for database server",
108
+ },
109
+ x: {
110
+ alias: "pass",
111
+ string: true,
112
+ default: options.connectionOptions.password,
113
+ describe: "Password for database server",
114
+ },
115
+ p: {
116
+ number: true,
117
+ alias: "port",
118
+ default: options.connectionOptions.port,
119
+ describe: "Port number for database server",
120
+ },
121
+ e: {
122
+ alias: "engine",
123
+ choices: [
124
+ "mssql",
125
+ "postgres",
126
+ "mysql",
127
+ "mariadb",
128
+ "oracle",
129
+ "sqlite",
130
+ ],
131
+ demand: true,
132
+ default: options.connectionOptions.databaseType,
133
+ describe: "Database engine",
134
+ },
135
+ o: {
136
+ alias: "output",
137
+ default: options.generationOptions.resultsPath,
138
+ describe: "Where to place generated models",
139
+ },
140
+ s: {
141
+ alias: "schema",
142
+ string: true,
143
+ default: options.connectionOptions.schemaNames.join(","),
144
+ describe: "Schema name to create model from. Only for mssql and postgres. You can pass multiple values separated by comma eg. -s scheme1,scheme2,scheme3",
145
+ },
146
+ i: {
147
+ alias: "instance",
148
+ string: true,
149
+ default: options.connectionOptions.instanceName,
150
+ describe: "Named instance to create model from. Only for mssql.",
151
+ },
152
+ ssl: {
153
+ boolean: true,
154
+ default: options.connectionOptions.ssl,
155
+ },
156
+ noConfig: {
157
+ boolean: true,
158
+ default: options.generationOptions.noConfigs,
159
+ describe: `Doesn't create tsconfig.json and ormconfig.json`,
160
+ },
161
+ cf: {
162
+ alias: "case-file",
163
+ choices: ["pascal", "param", "camel", "none"],
164
+ default: options.generationOptions.convertCaseFile,
165
+ describe: "Convert file names to specified case",
166
+ },
167
+ ce: {
168
+ alias: "case-entity",
169
+ choices: ["pascal", "camel", "none"],
170
+ default: options.generationOptions.convertCaseEntity,
171
+ describe: "Convert class names to specified case",
172
+ },
173
+ cp: {
174
+ alias: "case-property",
175
+ choices: ["pascal", "camel", "snake", "none"],
176
+ default: options.generationOptions.convertCaseProperty,
177
+ describe: "Convert property names to specified case",
178
+ },
179
+ eol: {
180
+ choices: ["LF", "CRLF"],
181
+ default: options.generationOptions.convertEol,
182
+ describe: "Force EOL to be LF or CRLF",
183
+ },
184
+ pv: {
185
+ alias: "property-visibility",
186
+ choices: ["public", "protected", "private", "none"],
187
+ default: options.generationOptions.propertyVisibility,
188
+ describe: "Defines which visibility should have the generated property",
189
+ },
190
+ lazy: {
191
+ boolean: true,
192
+ default: options.generationOptions.lazy,
193
+ describe: "Generate lazy relations",
194
+ },
195
+ a: {
196
+ alias: "active-record",
197
+ boolean: true,
198
+ default: options.generationOptions.activeRecord,
199
+ describe: "Use ActiveRecord syntax for generated models",
200
+ },
201
+ namingStrategy: {
202
+ describe: "Use custom naming strategy",
203
+ default: options.generationOptions.customNamingStrategyPath,
204
+ string: true,
205
+ },
206
+ relationIds: {
207
+ boolean: true,
208
+ default: options.generationOptions.relationIds,
209
+ describe: "Generate RelationId fields",
210
+ },
211
+ skipSchema: {
212
+ boolean: true,
213
+ default: options.generationOptions.skipSchema,
214
+ describe: "Omits schema identifier in generated entities",
215
+ },
216
+ generateConstructor: {
217
+ boolean: true,
218
+ default: options.generationOptions.generateConstructor,
219
+ describe: "Generate constructor allowing partial initialization",
220
+ },
221
+ disablePluralization: {
222
+ boolean: true,
223
+ default: !options.generationOptions.pluralizeNames,
224
+ describe: "Disable pluralization of OneToMany, ManyToMany relation names",
225
+ },
226
+ skipTables: {
227
+ string: true,
228
+ default: options.connectionOptions.skipTables.join(","),
229
+ describe: "Skip schema generation for specific tables. You can pass multiple values separated by comma",
230
+ },
231
+ tables: {
232
+ string: true,
233
+ default: options.connectionOptions.onlyTables.join(","),
234
+ describe: "Generate specific tables. You can pass multiple values separated by comma",
235
+ },
236
+ strictMode: {
237
+ choices: ["none", "?", "!"],
238
+ default: options.generationOptions.strictMode,
239
+ describe: "Mark fields as optional(?) or non-null(!)",
240
+ },
241
+ index: {
242
+ boolean: true,
243
+ default: options.generationOptions.indexFile,
244
+ describe: "Generate index file",
245
+ },
246
+ defaultExport: {
247
+ boolean: true,
248
+ default: options.generationOptions.exportType === "default",
249
+ describe: "Generate index file",
250
+ },
251
+ });
252
+ options.connectionOptions.databaseNames = argv.d.split(",");
253
+ options.connectionOptions.databaseType = argv.e;
254
+ const driver = (0, Engine_1.createDriver)(options.connectionOptions.databaseType);
255
+ const { standardPort, standardSchema, standardUser } = driver;
256
+ options.connectionOptions.host = argv.h;
257
+ options.connectionOptions.password = argv.x;
258
+ options.connectionOptions.port = argv.p || standardPort;
259
+ options.connectionOptions.schemaNames = argv.s
260
+ ? argv.s.split(",")
261
+ : [standardSchema];
262
+ options.connectionOptions.instanceName = argv.i || undefined;
263
+ options.connectionOptions.ssl = argv.ssl;
264
+ options.connectionOptions.user = argv.u || standardUser;
265
+ let skipTables = argv.skipTables.split(",");
266
+ if (skipTables.length === 1 && skipTables[0] === "") {
267
+ skipTables = []; // #252
268
+ }
269
+ let tables = argv.tables.split(",");
270
+ if (tables.length === 1 && tables[0] === "") {
271
+ tables = [];
272
+ }
273
+ options.connectionOptions.skipTables = skipTables;
274
+ options.connectionOptions.onlyTables = tables;
275
+ options.generationOptions.activeRecord = argv.a;
276
+ options.generationOptions.generateConstructor = argv.generateConstructor;
277
+ options.generationOptions.convertCaseEntity =
278
+ argv.ce;
279
+ options.generationOptions.convertCaseFile =
280
+ argv.cf;
281
+ options.generationOptions.convertCaseProperty =
282
+ argv.cp;
283
+ options.generationOptions.convertEol =
284
+ argv.eol;
285
+ options.generationOptions.lazy = argv.lazy;
286
+ options.generationOptions.customNamingStrategyPath = argv.namingStrategy;
287
+ options.generationOptions.noConfigs = argv.noConfig;
288
+ options.generationOptions.propertyVisibility =
289
+ argv.pv;
290
+ options.generationOptions.relationIds = argv.relationIds;
291
+ options.generationOptions.skipSchema = argv.skipSchema;
292
+ options.generationOptions.resultsPath = argv.o;
293
+ options.generationOptions.pluralizeNames = !argv.disablePluralization;
294
+ options.generationOptions.strictMode =
295
+ argv.strictMode;
296
+ options.generationOptions.indexFile = argv.index;
297
+ options.generationOptions.exportType = argv.defaultExport
298
+ ? "default"
299
+ : "named";
300
+ return options;
301
+ }
302
+ async function useInquirer(options) {
303
+ const oldDatabaseType = options.connectionOptions.databaseType;
304
+ options.connectionOptions.databaseType = (await inquirer.prompt([
305
+ {
306
+ choices: [
307
+ "mssql",
308
+ "postgres",
309
+ "mysql",
310
+ "mariadb",
311
+ "oracle",
312
+ "sqlite",
313
+ ],
314
+ default: options.connectionOptions.databaseType,
315
+ message: "Choose database engine",
316
+ name: "engine",
317
+ type: "list",
318
+ },
319
+ ])).engine;
320
+ const driver = (0, Engine_1.createDriver)(options.connectionOptions.databaseType);
321
+ if (options.connectionOptions.databaseType !== oldDatabaseType) {
322
+ options.connectionOptions.port = driver.standardPort;
323
+ options.connectionOptions.user = driver.standardUser;
324
+ options.connectionOptions.schemaNames = [driver.standardSchema];
325
+ }
326
+ if (options.connectionOptions.databaseType !== "sqlite") {
327
+ if (options.connectionOptions.databaseType === "mssql") {
328
+ options.connectionOptions.instanceName = (await inquirer.prompt([
329
+ {
330
+ default: options.connectionOptions.instanceName,
331
+ message: "Instance name(leave empty if using port number):",
332
+ name: "instanceName",
333
+ type: "input",
334
+ },
335
+ ])).instanceName;
336
+ }
337
+ const answ = await inquirer.prompt([
338
+ {
339
+ default: options.connectionOptions.host,
340
+ message: "Database address:",
341
+ name: "host",
342
+ type: "input",
343
+ },
344
+ {
345
+ message: "Database port:",
346
+ name: "port",
347
+ type: "input",
348
+ default: options.connectionOptions.port,
349
+ when: !options.connectionOptions.instanceName,
350
+ validate(value) {
351
+ const valid = !Number.isNaN(parseInt(value, 10));
352
+ return valid || "Please enter a valid port number";
353
+ },
354
+ },
355
+ {
356
+ default: options.connectionOptions.ssl,
357
+ message: "Use SSL:",
358
+ name: "ssl",
359
+ type: "confirm",
360
+ },
361
+ {
362
+ message: "Database user name:",
363
+ name: "login",
364
+ type: "input",
365
+ default: options.connectionOptions.user,
366
+ },
367
+ {
368
+ message: "Database user password:",
369
+ name: "password",
370
+ type: "password",
371
+ },
372
+ {
373
+ default: options.connectionOptions.databaseNames.join(","),
374
+ message: "Database name: (You can pass multiple values separated by comma)",
375
+ name: "dbName",
376
+ type: "input",
377
+ },
378
+ ]);
379
+ if (options.connectionOptions.databaseType === "mssql" ||
380
+ options.connectionOptions.databaseType === "postgres") {
381
+ options.connectionOptions.schemaNames = (await inquirer.prompt([
382
+ {
383
+ default: options.connectionOptions.schemaNames.join(","),
384
+ message: "Database schema: (You can pass multiple values separated by comma)",
385
+ name: "schema",
386
+ type: "input",
387
+ },
388
+ ])).schema.split(",");
389
+ }
390
+ options.connectionOptions.port = parseInt(answ.port, 10);
391
+ options.connectionOptions.host = answ.host;
392
+ options.connectionOptions.user = answ.login;
393
+ options.connectionOptions.password = answ.password;
394
+ options.connectionOptions.databaseNames = answ.dbName.split(",");
395
+ options.connectionOptions.ssl = answ.ssl;
396
+ }
397
+ else {
398
+ options.connectionOptions.databaseNames = (await inquirer.prompt([
399
+ {
400
+ default: options.connectionOptions.databaseNames,
401
+ message: "Path to database file:",
402
+ name: "dbName",
403
+ type: "input",
404
+ },
405
+ ])).dbName;
406
+ }
407
+ const ignoreSpecyficTables = (await inquirer.prompt([
408
+ {
409
+ default: options.connectionOptions.skipTables.length === 0
410
+ ? "All of them"
411
+ : "Ignore specific tables",
412
+ message: "Generate schema for tables:",
413
+ choices: [
414
+ "All of them",
415
+ "Ignore specific tables",
416
+ "Select specific tables",
417
+ ],
418
+ name: "specyficTables",
419
+ type: "list",
420
+ },
421
+ ])).specyficTables;
422
+ const optionsMapper = {
423
+ "All of them": () => {
424
+ options.connectionOptions.skipTables = [];
425
+ options.connectionOptions.onlyTables = [];
426
+ },
427
+ "Ignore specific tables": async () => {
428
+ const { tableNames } = await inquirer.prompt({
429
+ default: options.connectionOptions.skipTables.join(","),
430
+ message: "Table names(separated by comma)",
431
+ name: "tableNames",
432
+ type: "input",
433
+ });
434
+ options.connectionOptions.skipTables = tableNames.split(",");
435
+ },
436
+ "Select specific tables": async () => {
437
+ const { tableNames } = await inquirer.prompt({
438
+ default: options.connectionOptions.onlyTables.join(","),
439
+ message: "Table names(separated by comma)",
440
+ name: "tableNames",
441
+ type: "input",
442
+ });
443
+ options.connectionOptions.onlyTables = tableNames.split(",");
444
+ },
445
+ };
446
+ await optionsMapper[ignoreSpecyficTables]();
447
+ options.generationOptions.resultsPath = (await inquirer.prompt([
448
+ {
449
+ default: options.generationOptions.resultsPath,
450
+ message: "Path where generated models should be stored:",
451
+ name: "output",
452
+ type: "input",
453
+ },
454
+ ])).output;
455
+ const { customizeGeneration } = await inquirer.prompt([
456
+ {
457
+ default: false,
458
+ message: "Do you want to customize generated model?",
459
+ name: "customizeGeneration",
460
+ type: "confirm",
461
+ },
462
+ ]);
463
+ if (customizeGeneration) {
464
+ const defaultGenerationOptions = (0, IGenerationOptions_1.getDefaultGenerationOptions)();
465
+ const customizations = (await inquirer.prompt([
466
+ {
467
+ choices: [
468
+ {
469
+ checked: !options.generationOptions.noConfigs,
470
+ name: "Generate config files",
471
+ value: "config",
472
+ },
473
+ {
474
+ name: "Generate lazy relations",
475
+ value: "lazy",
476
+ checked: options.generationOptions.lazy,
477
+ },
478
+ {
479
+ name: "Use ActiveRecord syntax for generated models",
480
+ value: "activeRecord",
481
+ checked: options.generationOptions.activeRecord,
482
+ },
483
+ {
484
+ name: "Use custom naming strategy",
485
+ value: "namingStrategy",
486
+ checked: !!options.generationOptions
487
+ .customNamingStrategyPath,
488
+ },
489
+ {
490
+ name: "Generate RelationId fields",
491
+ value: "relationId",
492
+ checked: options.generationOptions.relationIds,
493
+ },
494
+ {
495
+ name: "Omits schema identifier in generated entities",
496
+ value: "skipSchema",
497
+ checked: options.generationOptions.skipSchema,
498
+ },
499
+ {
500
+ name: "Generate constructor allowing partial initialization",
501
+ value: "constructor",
502
+ checked: options.generationOptions.generateConstructor,
503
+ },
504
+ {
505
+ name: "Use specific naming convention",
506
+ value: "namingConvention",
507
+ checked: options.generationOptions.convertCaseEntity !==
508
+ defaultGenerationOptions.convertCaseEntity ||
509
+ options.generationOptions
510
+ .convertCaseProperty !==
511
+ defaultGenerationOptions.convertCaseProperty ||
512
+ options.generationOptions.convertCaseFile !==
513
+ defaultGenerationOptions.convertCaseFile,
514
+ },
515
+ {
516
+ name: "Use specific EOL character",
517
+ value: "converteol",
518
+ checked: false,
519
+ },
520
+ {
521
+ name: "Pluralize OneToMany, ManyToMany relation names",
522
+ value: "pluralize",
523
+ checked: options.generationOptions.pluralizeNames,
524
+ },
525
+ {
526
+ name: "Generate index file",
527
+ value: "index",
528
+ checked: options.generationOptions.indexFile,
529
+ },
530
+ {
531
+ name: "Prefer default exports",
532
+ value: "defaultExport",
533
+ checked: options.generationOptions.exportType ===
534
+ "default",
535
+ },
536
+ ],
537
+ message: "Available customizations",
538
+ name: "selected",
539
+ type: "checkbox",
540
+ },
541
+ ])).selected;
542
+ options.generationOptions.propertyVisibility = (await inquirer.prompt([
543
+ {
544
+ choices: ["public", "protected", "private", "none"],
545
+ message: "Defines which visibility should have the generated property",
546
+ name: "propertyVisibility",
547
+ default: options.generationOptions.propertyVisibility,
548
+ type: "list",
549
+ },
550
+ ])).propertyVisibility;
551
+ options.generationOptions.strictMode = (await inquirer.prompt([
552
+ {
553
+ choices: ["none", "?", "!"],
554
+ message: "Mark fields as optional(?) or non-null(!)",
555
+ name: "strictMode",
556
+ default: options.generationOptions.strictMode,
557
+ type: "list",
558
+ },
559
+ ])).strictMode;
560
+ options.generationOptions.noConfigs =
561
+ !customizations.includes("config");
562
+ options.generationOptions.pluralizeNames =
563
+ customizations.includes("pluralize");
564
+ options.generationOptions.lazy = customizations.includes("lazy");
565
+ options.generationOptions.activeRecord =
566
+ customizations.includes("activeRecord");
567
+ options.generationOptions.relationIds =
568
+ customizations.includes("relationId");
569
+ options.generationOptions.skipSchema =
570
+ customizations.includes("skipSchema");
571
+ options.generationOptions.generateConstructor =
572
+ customizations.includes("constructor");
573
+ options.generationOptions.indexFile = customizations.includes("index");
574
+ options.generationOptions.exportType = customizations.includes("defaultExport")
575
+ ? "default"
576
+ : "named";
577
+ if (customizations.includes("namingStrategy")) {
578
+ const namingStrategyPath = (await inquirer.prompt([
579
+ {
580
+ default: options.generationOptions.customNamingStrategyPath,
581
+ message: "Path to custom naming strategy file:",
582
+ name: "namingStrategy",
583
+ type: "input",
584
+ validate(value) {
585
+ const valid = value === "" || fs.existsSync(value);
586
+ return (valid ||
587
+ "Please enter a a valid path to custom naming strategy file");
588
+ },
589
+ },
590
+ ])).namingStrategy;
591
+ if (namingStrategyPath && namingStrategyPath !== "") {
592
+ options.generationOptions.customNamingStrategyPath =
593
+ namingStrategyPath;
594
+ }
595
+ else {
596
+ options.generationOptions.customNamingStrategyPath = "";
597
+ }
598
+ }
599
+ if (customizations.includes("namingConvention")) {
600
+ const namingConventions = await inquirer.prompt([
601
+ {
602
+ choices: ["pascal", "param", "camel", "none"],
603
+ default: options.generationOptions.convertCaseFile,
604
+ message: "Convert file names to specified case:",
605
+ name: "fileCase",
606
+ type: "list",
607
+ },
608
+ {
609
+ choices: ["pascal", "camel", "none"],
610
+ default: options.generationOptions.convertCaseEntity,
611
+ message: "Convert class names to specified case:",
612
+ name: "entityCase",
613
+ type: "list",
614
+ },
615
+ {
616
+ choices: ["pascal", "camel", "none"],
617
+ default: options.generationOptions.convertCaseProperty,
618
+ message: "Convert property names to specified case:",
619
+ name: "propertyCase",
620
+ type: "list",
621
+ },
622
+ ]);
623
+ options.generationOptions.convertCaseFile =
624
+ namingConventions.fileCase;
625
+ options.generationOptions.convertCaseProperty =
626
+ namingConventions.propertyCase;
627
+ options.generationOptions.convertCaseEntity =
628
+ namingConventions.entityCase;
629
+ }
630
+ if (customizations.includes("converteol")) {
631
+ const eolChoice = await inquirer.prompt([
632
+ {
633
+ choices: ["LF", "CRLF"],
634
+ default: options.generationOptions.convertEol,
635
+ message: "Force EOL to be:",
636
+ name: "eol",
637
+ type: "list",
638
+ },
639
+ ]);
640
+ options.generationOptions.convertEol = eolChoice.eol;
641
+ }
642
+ }
643
+ const { saveConfig } = await inquirer.prompt([
644
+ {
645
+ choices: [
646
+ "Yes, only model customization options",
647
+ "Yes, with connection details",
648
+ "No",
649
+ ],
650
+ default: "No",
651
+ message: "Save configuration to config file?",
652
+ name: "saveConfig",
653
+ type: "list",
654
+ },
655
+ ]);
656
+ if (saveConfig === "Yes, with connection details") {
657
+ await fs.writeJson(path.resolve(process.cwd(), ".tomg-config"), [options.generationOptions, options.connectionOptions], { spaces: 2 });
658
+ console.log(`[${new Date().toLocaleTimeString()}] Config file saved.`);
659
+ console.warn(`\x1b[33m[${new Date().toLocaleTimeString()}] WARNING: Password was saved as plain text.\x1b[0m`);
660
+ }
661
+ else if (saveConfig === "Yes, only model customization options") {
662
+ await fs.writeJson(path.resolve(process.cwd(), ".tomg-config"), [options.generationOptions], { spaces: 2 });
663
+ console.log(`[${new Date().toLocaleTimeString()}] Config file saved.`);
664
+ }
665
+ return options;
666
+ }
667
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import * as Engine from "./Engine";
2
+ import * as IConnectionOptions from "./IConnectionOptions";
3
+ import * as IGenerationOptions from "./IGenerationOptions";
4
+ import * as NamingStrategy from "./NamingStrategy";
5
+ import * as Utils from "./Utils";
6
+ export { Column } from "./models/Column";
7
+ export { Entity } from "./models/Entity";
8
+ export { Index } from "./models/Index";
9
+ export { Relation } from "./models/Relation";
10
+ export { RelationId } from "./models/RelationId";
11
+ export { Engine, IConnectionOptions, IGenerationOptions, NamingStrategy, Utils, };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Utils = exports.NamingStrategy = exports.IGenerationOptions = exports.IConnectionOptions = exports.Engine = void 0;
4
+ const Engine = require("./Engine");
5
+ exports.Engine = Engine;
6
+ const IConnectionOptions = require("./IConnectionOptions");
7
+ exports.IConnectionOptions = IConnectionOptions;
8
+ const IGenerationOptions = require("./IGenerationOptions");
9
+ exports.IGenerationOptions = IGenerationOptions;
10
+ const NamingStrategy = require("./NamingStrategy");
11
+ exports.NamingStrategy = NamingStrategy;
12
+ const Utils = require("./Utils");
13
+ exports.Utils = Utils;
14
+ //# sourceMappingURL=library.js.map