@mikro-orm/cli 7.2.0-dev.0 → 7.2.0-dev.10

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.
@@ -11,9 +11,11 @@ export interface BaseCommand<CommandArgs extends BaseArgs = BaseArgs> extends Co
11
11
  declare function createBasicConfig(): Argv<{
12
12
  config: string[] | undefined;
13
13
  contextName: string;
14
+ quiet: boolean;
14
15
  }>;
15
16
  export declare function configure(): Promise<Argv<{
16
17
  config: string[] | undefined;
17
18
  contextName: string;
19
+ quiet: boolean;
18
20
  }>>;
19
21
  export {};
@@ -30,6 +30,12 @@ function createBasicConfig() {
30
30
  type: 'string',
31
31
  desc: 'Set name of config to load out of the ORM configuration file. Used when config file exports an array or a function',
32
32
  default: process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default',
33
+ })
34
+ .option('quiet', {
35
+ alias: 'q',
36
+ type: 'boolean',
37
+ desc: 'Do not show any auxiliary output.',
38
+ default: false,
33
39
  })
34
40
  .alias('v', 'version')
35
41
  .alias('h', 'help')
package/CLIHelper.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Configuration, type EntityManager, type EntityManagerType, type IDataba
3
3
  * @internal
4
4
  */
5
5
  export declare class CLIHelper {
6
+ static quiet: boolean;
6
7
  /**
7
8
  * Gets a named configuration
8
9
  *
@@ -16,6 +17,7 @@ export declare class CLIHelper {
16
17
  static isDBConnected(config: Configuration, reason?: false): Promise<boolean>;
17
18
  static isDBConnected(config: Configuration, reason: true): Promise<true | string>;
18
19
  static getDriverDependencies(config: Configuration): string[];
20
+ static info(text: string): void;
19
21
  static dump(text: string, config?: Configuration): void;
20
22
  static getSettings(): Settings;
21
23
  static getConfigPaths(): Promise<string[]>;
package/CLIHelper.js CHANGED
@@ -9,6 +9,7 @@ import { searchConfiguration } from './searchConfiguration.js';
9
9
  * @internal
10
10
  */
11
11
  export class CLIHelper {
12
+ static quiet = false;
12
13
  /**
13
14
  * Gets a named configuration
14
15
  *
@@ -88,6 +89,13 @@ export class CLIHelper {
88
89
  return [];
89
90
  }
90
91
  }
92
+ static info(text) {
93
+ if (CLIHelper.quiet) {
94
+ return;
95
+ }
96
+ // eslint-disable-next-line no-console
97
+ console.log(text);
98
+ }
91
99
  static dump(text, config) {
92
100
  if (config?.get('highlighter')) {
93
101
  text = config.get('highlighter').highlight(text);
@@ -7,6 +7,7 @@ export class ClearCacheCommand {
7
7
  * @inheritDoc
8
8
  */
9
9
  async handler(args) {
10
+ CLIHelper.quiet = args.quiet;
10
11
  const config = await CLIHelper.getConfiguration(args.contextName, args.config);
11
12
  if (!config.get('metadataCache').enabled) {
12
13
  CLIHelper.dump(colors.red('Metadata cache is disabled in your configuration. Set cache.enabled to true to use this command.'));
@@ -14,6 +15,6 @@ export class ClearCacheCommand {
14
15
  }
15
16
  const cache = config.getMetadataCacheAdapter();
16
17
  await cache.clear();
17
- CLIHelper.dump(colors.green('Metadata cache was successfully cleared'));
18
+ CLIHelper.info(colors.green('Metadata cache was successfully cleared'));
18
19
  }
19
20
  }
@@ -17,6 +17,7 @@ export class CompileCommand {
17
17
  * @inheritDoc
18
18
  */
19
19
  async handler(args) {
20
+ CLIHelper.quiet = args.quiet;
20
21
  const config = await CLIHelper.getConfiguration(args.contextName, args.config);
21
22
  const settings = CLIHelper.getSettings();
22
23
  config.set('debug', !!settings.verbose);
@@ -51,12 +52,15 @@ export class CompileCommand {
51
52
  mkdirSync(dirname(outPath), { recursive: true });
52
53
  writeFileSync(outPath, output);
53
54
  writeFileSync(dtsPath, dts);
54
- CLIHelper.dump(colors.green(`Compiled functions generated to ${outPath} (${captured.length} functions)`));
55
- CLIHelper.dump(`\nExample usage in your ORM config:\n`);
55
+ if (args.quiet) {
56
+ return;
57
+ }
58
+ CLIHelper.info(colors.green(`Compiled functions generated to ${outPath} (${captured.length} functions)`));
59
+ CLIHelper.info(`\nExample usage in your ORM config:\n`);
56
60
  const importPath = esm ? './compiled-functions.js' : './compiled-functions';
57
- CLIHelper.dump(` ${esm ? 'import' : 'const'} compiledFunctions ${esm ? 'from ' : '= require('}${colors.cyan(`'${importPath}'`)}${esm ? '' : ')'};`);
58
- CLIHelper.dump('');
59
- CLIHelper.dump(` export default defineConfig({ compiledFunctions });\n`);
61
+ CLIHelper.info(` ${esm ? 'import' : 'const'} compiledFunctions ${esm ? 'from ' : '= require('}${colors.cyan(`'${importPath}'`)}${esm ? '' : ')'};`);
62
+ CLIHelper.info('');
63
+ CLIHelper.info(` export default defineConfig({ compiledFunctions });\n`);
60
64
  }
61
65
  static capture(metadata, config) {
62
66
  const captured = [];
@@ -6,6 +6,7 @@ export class CreateDatabaseCommand {
6
6
  * @inheritDoc
7
7
  */
8
8
  async handler(args) {
9
+ CLIHelper.quiet = args.quiet;
9
10
  const orm = await CLIHelper.getORM(args.contextName, args.config);
10
11
  await orm.schema.ensureDatabase();
11
12
  await orm.close(true);
@@ -14,10 +14,11 @@ export class CreateSeederCommand {
14
14
  * @inheritDoc
15
15
  */
16
16
  async handler(args) {
17
+ CLIHelper.quiet = args.quiet;
17
18
  const className = CreateSeederCommand.getSeederClassName(args.seeder);
18
19
  const orm = await CLIHelper.getORM(args.contextName, args.config);
19
20
  const path = await orm.seeder.create(className);
20
- CLIHelper.dump(colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
21
+ CLIHelper.info(colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
21
22
  await orm.close(true);
22
23
  }
23
24
  /**
@@ -15,10 +15,11 @@ export class DatabaseSeedCommand {
15
15
  * @inheritDoc
16
16
  */
17
17
  async handler(args) {
18
+ CLIHelper.quiet = args.quiet;
18
19
  const orm = await CLIHelper.getORM(args.contextName, args.config);
19
20
  const className = args.class ?? orm.config.get('seeder').defaultSeeder;
20
21
  await orm.seeder.seedString(className);
21
- CLIHelper.dump(colors.green(`Seeder ${className} successfully executed`));
22
+ CLIHelper.info(colors.green(`Seeder ${className} successfully executed`));
22
23
  await orm.close(true);
23
24
  }
24
25
  }
@@ -8,6 +8,7 @@ export class DebugCommand {
8
8
  * @inheritDoc
9
9
  */
10
10
  async handler(args) {
11
+ CLIHelper.quiet = args.quiet;
11
12
  CLIHelper.dump(`Current ${colors.cyan('MikroORM')} CLI configuration`);
12
13
  CLIHelper.dumpDependencies();
13
14
  const settings = CLIHelper.getSettings();
@@ -4,6 +4,7 @@ type DiscoveryExportArgs = BaseArgs & {
4
4
  path?: string[];
5
5
  out?: string;
6
6
  dump?: boolean;
7
+ quiet?: boolean;
7
8
  };
8
9
  export declare class DiscoveryExportCommand implements BaseCommand<DiscoveryExportArgs> {
9
10
  command: string;
@@ -41,6 +41,7 @@ export class DiscoveryExportCommand {
41
41
  * @inheritDoc
42
42
  */
43
43
  handler = async (args) => {
44
+ CLIHelper.quiet = args.quiet;
44
45
  const config = await CLIHelper.getConfiguration(args.contextName, args.config);
45
46
  const paths = this.resolvePaths(args, config);
46
47
  const baseDir = fs.absolutePath(config.get('baseDir') ?? process.cwd());
@@ -60,13 +61,16 @@ export class DiscoveryExportCommand {
60
61
  const output = this.generateFile(discovered, outPath, esm, driverPackage);
61
62
  mkdirSync(dirname(outPath), { recursive: true });
62
63
  writeFileSync(outPath, output);
63
- CLIHelper.dump(colors.green(`Entity exports generated to ${outPath} (${discovered.length} entities)`));
64
- CLIHelper.dump(`\nExample usage in your ORM config:\n`);
64
+ if (args.quiet) {
65
+ return;
66
+ }
67
+ CLIHelper.info(colors.green(`Entity exports generated to ${outPath} (${discovered.length} entities)`));
68
+ CLIHelper.info(`\nExample usage in your ORM config:\n`);
65
69
  const importExt = esm ? '.js' : '';
66
70
  const importPath = `./${basename(outPath).replace(/\.ts$/, importExt)}`;
67
- CLIHelper.dump(` import { entities } from ${colors.cyan(`'${importPath}'`)};`);
68
- CLIHelper.dump('');
69
- CLIHelper.dump(' export default defineConfig({ entities });\n');
71
+ CLIHelper.info(` import { entities } from ${colors.cyan(`'${importPath}'`)};`);
72
+ CLIHelper.info('');
73
+ CLIHelper.info(' export default defineConfig({ entities });\n');
70
74
  };
71
75
  resolvePaths(args, config) {
72
76
  if (args.path && args.path.length > 0) {
@@ -10,6 +10,7 @@ export class GenerateCacheCommand {
10
10
  desc: `Generate development cache for '.ts' files`,
11
11
  });
12
12
  args.option('combined', {
13
+ type: 'string',
13
14
  alias: 'c',
14
15
  desc: `Generate production cache into a single JSON file that can be used with the GeneratedCacheAdapter.`,
15
16
  });
@@ -19,7 +20,10 @@ export class GenerateCacheCommand {
19
20
  * @inheritDoc
20
21
  */
21
22
  async handler(args) {
22
- const options = args.combined ? { combined: './metadata.json' } : {};
23
+ CLIHelper.quiet = args.quiet;
24
+ const options = typeof args.combined !== 'undefined'
25
+ ? { combined: args.combined === '' ? './metadata.json' : args.combined }
26
+ : {};
23
27
  const config = await CLIHelper.getConfiguration(args.contextName, args.config, {
24
28
  metadataCache: { enabled: true, adapter: FileCacheAdapter, options },
25
29
  });
@@ -29,6 +33,6 @@ export class GenerateCacheCommand {
29
33
  const discovery = new MetadataDiscovery(new MetadataStorage(), config.getDriver().getPlatform(), config);
30
34
  await discovery.discover(args.ts ?? false);
31
35
  const combined = args.combined && config.get('metadataCache').combined;
32
- CLIHelper.dump(colors.green(`${combined ? 'Combined ' : ''}${args.ts ? 'TS' : 'JS'} metadata cache was successfully generated${combined ? ' to ' + combined : ''}`));
36
+ CLIHelper.info(colors.green(`${combined ? 'Combined ' : ''}${args.ts ? 'TS' : 'JS'} metadata cache was successfully generated${combined ? ' to ' + combined : ''}`));
33
37
  }
34
38
  }
@@ -1,4 +1,5 @@
1
1
  import { CLIHelper } from '../CLIHelper.js';
2
+ import { colors } from '@mikro-orm/core';
2
3
  export class GenerateEntitiesCommand {
3
4
  command = 'generate-entities';
4
5
  describe = 'Generate entities based on current database schema';
@@ -31,6 +32,7 @@ export class GenerateEntitiesCommand {
31
32
  * @inheritDoc
32
33
  */
33
34
  async handler(args) {
35
+ CLIHelper.quiet = args.quiet;
34
36
  if (!args.save && !args.dump) {
35
37
  return CLIHelper.showHelp();
36
38
  }
@@ -43,6 +45,9 @@ export class GenerateEntitiesCommand {
43
45
  if (args.dump) {
44
46
  CLIHelper.dump(dump.join('\n\n'));
45
47
  }
48
+ else {
49
+ CLIHelper.info(colors.green(`Entities generated successfully`));
50
+ }
46
51
  await orm.close(true);
47
52
  }
48
53
  }
@@ -8,10 +8,11 @@ export class ImportCommand {
8
8
  * @inheritDoc
9
9
  */
10
10
  async handler(args) {
11
+ CLIHelper.quiet = args.quiet;
11
12
  const orm = await CLIHelper.getORM(args.contextName, args.config, { multipleStatements: true });
12
13
  const buf = await readFile(args.file);
13
14
  await orm.em.getConnection().executeDump(buf.toString());
14
- CLIHelper.dump(colors.green(`File ${args.file} successfully imported`));
15
+ CLIHelper.info(colors.green(`File ${args.file} successfully imported`));
15
16
  await orm.close(true);
16
17
  }
17
18
  }
@@ -98,6 +98,7 @@ export class MigrationCommandFactory {
98
98
  return args;
99
99
  }
100
100
  static async handleMigrationCommand(args, method) {
101
+ CLIHelper.quiet = args.quiet;
101
102
  // to be able to run have a master transaction, but run marked migrations outside of it, we need a second connection
102
103
  const options = { pool: { min: 1, max: 2 } };
103
104
  const orm = await CLIHelper.getORM(args.contextName, args.config, options);
@@ -146,7 +147,7 @@ export class MigrationCommandFactory {
146
147
  const opts = MigrationCommandFactory.getUpDownOptions(args);
147
148
  await migrator[method](opts);
148
149
  const message = this.getUpDownSuccessMessage(method, opts);
149
- CLIHelper.dump(colors.green(message));
150
+ CLIHelper.info(colors.green(message));
150
151
  }
151
152
  static async handlePendingCommand(migrator) {
152
153
  const pending = await migrator.getPending();
@@ -171,10 +172,10 @@ export class MigrationCommandFactory {
171
172
  static async handleCreateCommand(migrator, args, config) {
172
173
  const ret = await migrator.create(args.path, args.blank, args.initial, args.name);
173
174
  if (ret.diff.up.length === 0) {
174
- return CLIHelper.dump(colors.green(`No changes required, schema is up-to-date`));
175
+ return CLIHelper.info(colors.green(`No changes required, schema is up-to-date`));
175
176
  }
176
177
  if (args.dump) {
177
- CLIHelper.dump(colors.green('Creating migration with following queries:'));
178
+ CLIHelper.info(colors.green('Creating migration with following queries:'));
178
179
  CLIHelper.dump(colors.green('up:'));
179
180
  CLIHelper.dump(ret.diff.up.map(sql => ' ' + sql).join('\n'), config);
180
181
  /* v8 ignore if */
@@ -187,11 +188,11 @@ export class MigrationCommandFactory {
187
188
  CLIHelper.dump(colors.yellow(`(${config.getDriver().constructor.name} does not support automatic down migrations)`));
188
189
  }
189
190
  }
190
- CLIHelper.dump(colors.green(`${ret.fileName} successfully created`));
191
+ CLIHelper.info(colors.green(`${ret.fileName} successfully created`));
191
192
  }
192
193
  static async handleCheckCommand(migrator, orm) {
193
194
  if (!(await migrator.checkSchema())) {
194
- return CLIHelper.dump(colors.green(`No changes required, schema is up-to-date`));
195
+ return CLIHelper.info(colors.green(`No changes required, schema is up-to-date`));
195
196
  }
196
197
  await orm.close(true);
197
198
  CLIHelper.dump(colors.yellow(`Changes detected. Please create migration to update schema.`));
@@ -199,25 +200,25 @@ export class MigrationCommandFactory {
199
200
  }
200
201
  static async handleFreshCommand(args, migrator, orm) {
201
202
  await orm.schema.drop({ dropMigrationsTable: true, dropDb: args.dropDb });
202
- CLIHelper.dump(colors.green('Dropped schema successfully'));
203
+ CLIHelper.info(colors.green('Dropped schema successfully'));
203
204
  const opts = MigrationCommandFactory.getUpDownOptions(args);
204
205
  await migrator.up(opts);
205
206
  const message = this.getUpDownSuccessMessage('up', opts);
206
- CLIHelper.dump(colors.green(message));
207
+ CLIHelper.info(colors.green(message));
207
208
  if (args.seed !== undefined) {
208
209
  const seederClass = args.seed || orm.config.get('seeder').defaultSeeder;
209
210
  await orm.seeder.seedString(seederClass);
210
- CLIHelper.dump(colors.green(`Database seeded successfully with seeder class ${seederClass}`));
211
+ CLIHelper.info(colors.green(`Database seeded successfully with seeder class ${seederClass}`));
211
212
  }
212
213
  }
213
214
  static async handleLogUnlogCommand(args, migrator, method) {
214
215
  await migrator[`${method}Migration`](args.name);
215
216
  const action = method === 'log' ? 'logged' : 'unlogged';
216
- CLIHelper.dump(colors.green(`Successfully ${action} migration '${args.name}'`));
217
+ CLIHelper.info(colors.green(`Successfully ${action} migration '${args.name}'`));
217
218
  }
218
219
  static async handleRollupCommand(migrator) {
219
220
  const ret = await migrator.rollup();
220
- CLIHelper.dump(colors.green(`${ret.fileName} successfully created (rollup)`));
221
+ CLIHelper.info(colors.green(`${ret.fileName} successfully created (rollup)`));
221
222
  }
222
223
  static getUpDownOptions(flags) {
223
224
  const ret = !flags.to && !flags.from && flags.only ? { migrations: flags.only.split(/[, ]+/) } : {};
@@ -76,6 +76,7 @@ export class SchemaCommandFactory {
76
76
  return args;
77
77
  }
78
78
  static async handleSchemaCommand(args, method, successMessage) {
79
+ CLIHelper.quiet = args.quiet;
79
80
  if (!args.run && !args.dump) {
80
81
  return CLIHelper.showHelp();
81
82
  }
@@ -102,7 +103,7 @@ export class SchemaCommandFactory {
102
103
  if (typeof args.seed !== 'undefined') {
103
104
  await orm.seeder.seedString(args.seed || orm.config.get('seeder').defaultSeeder);
104
105
  }
105
- CLIHelper.dump(colors.green(successMessage));
106
+ CLIHelper.info(colors.green(successMessage));
106
107
  await orm.close(true);
107
108
  }
108
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/cli",
3
- "version": "7.2.0-dev.0",
3
+ "version": "7.2.0-dev.10",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -50,8 +50,8 @@
50
50
  "copy": "node ../../scripts/copy.mjs"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/core": "7.2.0-dev.0",
54
- "mikro-orm": "7.2.0-dev.0",
53
+ "@mikro-orm/core": "7.2.0-dev.10",
54
+ "mikro-orm": "7.2.0-dev.10",
55
55
  "yargs": "17.7.2"
56
56
  },
57
57
  "engines": {